Skip to content

Commit 05b8ed8

Browse files
jlwalke2smlindauer
andauthored
pzmm updates (#87)
* Merge 4075/4083 commits from OMMR * Adjust pzmm zipping method to output iofile. * Remove now-redundant pzmm model upload process. * Edit notebook example to leverage sasctl framework. * Adjust dmcas writers doc_strings to state acceptance of dataframe, array, or list * First attempt to change dmcas_fitstat writer to accept more data types. * added Session.as_swat() * updated docs * test as_swat() * Combine Lift/ROC chart generation into one call. * Spell transpose correctly and remove unused functions. * Remove uploadData from init statement. * Include empty ROC and Lift dmcas JSON files in installation. * Lowercase all references to pzmm. * Add empty dmcas lift/roc JSON files. * Add missing null roc json file. * Final dev updates to Lift/ROC chart fixes. * custom get_repository() method to ignore 403 errors. Improved efficiency for default_repository() * Adjust score code for invalid column names/values. * Fix missing numpy package in writeScoreCode * Fix isidentifer error with improper type. * Add error for no data provided in calculateFitStat * Fix dataframe input for generateROCLiftStat() * Update example notebook to include new features * Adjust protocol for Session object. * Fix error in generating ROC/LIFT charts. * Update example notebook and outputs. * Fix overwritten model object on repeat runs. * Adjust text to documentation standards. * Remove sas server names from example before GitHub release. * include docs and examples * additional example * Merge from Github * Fix missing argument in pickle and zipping calls. * refreshed cassettes * refreshed cassettes * refreshed cassettes * temporary disable regression test * temporary disable regression test * correctly mock default repo * fix tests * fixed cli command for get_repository * Update changelog.md * prep for release * Adjust score code for invalid column names/values. * Fix missing numpy package in writeScoreCode * Fix isidentifer error with improper type. * Merge 4075/4083 commits from OMMR * Adjust dmcas writers doc_strings to state acceptance of dataframe, array, or list * First attempt to change dmcas_fitstat writer to accept more data types. * custom get_repository() method to ignore 403 errors. Improved efficiency for default_repository() * Adjust protocol for Session object. * Update example notebook and outputs. * Fix overwritten model object on repeat runs. * Adjust text to documentation standards. * Adjust score code for invalid column names/values. * Fix missing numpy package in writeScoreCode * Fix isidentifer error with improper type. * Adjust score code for invalid column names/values. * Fix missing numpy package in writeScoreCode * Fix isidentifer error with improper type. * Change writeScoreCode intercept default behavior * writeScoreCode should handle non-binary targets * Add software version checking API call and task. * Added MM version check to writeScoreCode(). * Add DS2 wrapper function to writeScoreCode.py * Include future API builds for Viya 4.0 * Add API call to move Python score resources. * Fix doc_string errors. * Add f(x) to upload/copy pzmm Python/DS2 score code * Include upload/copy score code in writeScore() * Fix indentation error * First run of testing new copy/upload task. * Fix incorrect role assignment of pickle file. * Add headers to PUT scoreResources API call. * Adjust version to differentiate between main/dev versions. * Handle case of Viya 3.5 & no model provided. * General fixes to DS2 converter. * Fix dtype vs string error. * Call ds2 wrapper endpoint and adjust writeScoreCode. * Add mojo model file handling to PickelModel. * Add H2O option to writeFileMetaData. * Add mojo file to zippable files * Fix astore vs Python typo * Add new import file to handle model imports and adjust init file * Adjust examples and create new simple/h2o notebooks * Include single row csv for testing * Major update to writeScoreCode * Final modification to writeScoreCode & new notebooks * Edit notebook to remove unused cells * Fix pathing and .zip errors in H2O example * Fix trailing .zip * Include default method for scoring/validating in CAS for Viya 3.5 users. * Required *.sas files for scoring in CAS/MAS * Remove reference to uncommitted feature * Bug fixes for CAS wrapper and documentation * Delete FleetManagementSimple.ipynb * Update FleetManagementSimpleH2O.ipynb * Update H2OModelFleetMaintenance.ipynb * Adjust to new handling of model importing * Delete fleet_maintenance.csv * Update change to CSV files * Update H2OModelFleetMaintenance.ipynb * Update README.md * moved get_software_version() to platform_version() * removed f strings for compatibility * bugfix * remove f strings * removed duplicate method Co-authored-by: Scott Lindauer <[email protected]> Co-authored-by: Scott Lindauer <[email protected]>
1 parent 280e455 commit 05b8ed8

33 files changed

+4623
-8420
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Unreleased
22
----------
33
**Improvements**
44
- `PagedList` handles situations where the server over-estimates the number of items available for paging.
5+
- The version of SAS Viya on the server can now be determined using `sasctl.platform_version()`.
6+
7+
**Bugfixes**
8+
- Reworked the `model_repository.get_repository()` to prevent HTTP 403 errors that could occur with some Viya environments.
59

610
v1.5.5 (2021-03-26)
711
-------------------

examples/FleetManagement.ipynb

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"\n",
2121
"This notebook provides an example of how to build and train a Python model and then import the model into SAS Model Manager using the fleet maintenance data set. Lines of code that must be modified by the user, such as directory paths are noted with the comment \"_Changes required by user._\".\n",
2222
"\n",
23-
"_**Note:** If you download only this notebook and not the rest of the repository, you must also download the fleet_maintenance.csv from the data folder in the examples directory. These files are used when executing this notebook example._\n",
23+
"_**Note:** If you download only this notebook and not the rest of the repository, you must also download the fleet maintenance CSV file from the data folder in the examples directory. These files are used when executing this notebook example._\n",
2424
"\n",
2525
"Here are the steps shown in this notebook:\n",
2626
"\n",
@@ -989,20 +989,16 @@
989989
},
990990
{
991991
"cell_type": "code",
992-
"execution_count": 19,
992+
"execution_count": 15,
993993
"metadata": {
994994
"Collapsed": "false"
995995
},
996996
"outputs": [],
997997
"source": [
998-
"S = pzmm.ScoreCode()\n",
998+
"I = pzmm.ImportModel()\n",
999999
"for (prefix, path) in zip(modelPrefix, zipFolder):\n",
1000-
" S.writeScoreCode(x, y, prefix,\n",
1001-
" '{}.predict({})', prefix + '.pickle',\n",
1002-
" pyPath=path)\n",
1003-
" zipIOFile = pzmm.ZipModel.zipFiles(_, path, prefix)\n",
10041000
" with sess:\n",
1005-
" modelReponse = modelRepo.import_model_from_zip(prefix, 'Fleet Management Report', zipIOFile)"
1001+
" I.pzmmImportModel(path, prefix, 'Fleet Management Report', x, y, '{}.predict({})')\n"
10061002
]
10071003
},
10081004
{
@@ -1030,6 +1026,53 @@
10301026
"nbconvert_exporter": "python",
10311027
"pygments_lexer": "ipython3",
10321028
"version": "3.8.3"
1029+
},
1030+
"latex_envs": {
1031+
"LaTeX_envs_menu_present": true,
1032+
"autoclose": true,
1033+
"autocomplete": true,
1034+
"bibliofile": "biblio.bib",
1035+
"cite_by": "apalike",
1036+
"current_citInitial": 1,
1037+
"eqLabelWithNumbers": true,
1038+
"eqNumInitial": 1,
1039+
"hotkeys": {
1040+
"equation": "Ctrl-E",
1041+
"itemize": "Ctrl-I"
1042+
},
1043+
"labels_anchors": false,
1044+
"latex_user_defs": false,
1045+
"report_style_numbering": false,
1046+
"user_envs_cfg": false
1047+
},
1048+
"varInspector": {
1049+
"cols": {
1050+
"lenName": 16,
1051+
"lenType": 16,
1052+
"lenVar": 40
1053+
},
1054+
"kernels_config": {
1055+
"python": {
1056+
"delete_cmd_postfix": "",
1057+
"delete_cmd_prefix": "del ",
1058+
"library": "var_list.py",
1059+
"varRefreshCmd": "print(var_dic_list())"
1060+
},
1061+
"r": {
1062+
"delete_cmd_postfix": ") ",
1063+
"delete_cmd_prefix": "rm(",
1064+
"library": "var_list.r",
1065+
"varRefreshCmd": "cat(var_dic_list()) "
1066+
}
1067+
},
1068+
"types_to_exclude": [
1069+
"module",
1070+
"function",
1071+
"builtin_function_or_method",
1072+
"instance",
1073+
"_Feature"
1074+
],
1075+
"window_display": false
10331076
}
10341077
},
10351078
"nbformat": 4,

examples/H2OModelFleetMaintenance.ipynb

Lines changed: 2855 additions & 0 deletions
Large diffs are not rendered by default.
13.1 KB
Binary file not shown.
21.3 KB
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
import math
4+
import pickle
5+
import pandas as pd
6+
import numpy as np
7+
8+
9+
global _thisModelFit
10+
11+
with open('/models/resources/viya/fc809ba9-11ec-45ad-bc49-ce2cd2a02fd4/DecisionTreeClassifier.pickle', 'rb') as _pFile:
12+
_thisModelFit = pickle.load(_pFile)
13+
14+
def scoreDecisionTreeClassifier(Speed_sensor, Vibration, Engine_Load, Coolant_Temp, Intake_Pressure, Engine_RPM, Speed_OBD, Intake_Air, Flow_Rate, Throttle_Pos, Voltage, Ambient, Accel, Engine_Oil_Temp, Speed_GPS, GPS_Longitude, GPS_Latitude, GPS_Bearing, GPS_Altitude, Turbo_Boost, Trip_Distance, Litres_Per_km, Accel_Ssor_Total, CO2, Trip_Time, CO_emission, HC_emission, PM_emission, NOx_emission, CO2_emission, Fuel_level, Oil_life, Vibration_alert, VibrationAlert_Total, Vibration_Recent, Turbo_alert, Emission_alert, Fog_control, Engine_control):
15+
"Output: EM_EVENTPROBABILITY, EM_CLASSIFICATION"
16+
17+
try:
18+
_thisModelFit
19+
except NameError:
20+
21+
with open('/models/resources/viya/fc809ba9-11ec-45ad-bc49-ce2cd2a02fd4/DecisionTreeClassifier.pickle', 'rb') as _pFile:
22+
_thisModelFit = pickle.load(_pFile)
23+
24+
try:
25+
inputArray = pd.DataFrame([[Speed_sensor, Vibration, Engine_Load, Coolant_Temp, Intake_Pressure, Engine_RPM, Speed_OBD, Intake_Air, Flow_Rate, Throttle_Pos, Voltage, Ambient, Accel, Engine_Oil_Temp, Speed_GPS, GPS_Longitude, GPS_Latitude, GPS_Bearing, GPS_Altitude, Turbo_Boost, Trip_Distance, Litres_Per_km, Accel_Ssor_Total, CO2, Trip_Time, CO_emission, HC_emission, PM_emission, NOx_emission, CO2_emission, Fuel_level, Oil_life, Vibration_alert, VibrationAlert_Total, Vibration_Recent, Turbo_alert, Emission_alert, Fog_control, Engine_control]],
26+
columns=['Speed_sensor', 'Vibration', 'Engine_Load', 'Coolant_Temp', 'Intake_Pressure', 'Engine_RPM', 'Speed_OBD', 'Intake_Air', 'Flow_Rate', 'Throttle_Pos', 'Voltage', 'Ambient', 'Accel', 'Engine_Oil_Temp', 'Speed_GPS', 'GPS_Longitude', 'GPS_Latitude', 'GPS_Bearing', 'GPS_Altitude', 'Turbo_Boost', 'Trip_Distance', 'Litres_Per_km', 'Accel_Ssor_Total', 'CO2', 'Trip_Time', 'CO_emission', 'HC_emission', 'PM_emission', 'NOx_emission', 'CO2_emission', 'Fuel_level', 'Oil_life', 'Vibration_alert', 'VibrationAlert_Total', 'Vibration_Recent', 'Turbo_alert', 'Emission_alert', 'Fog_control', 'Engine_control'],
27+
dtype=float)
28+
prediction = _thisModelFit.predict(inputArray)
29+
except ValueError:
30+
# For models requiring or including an intercept value, a 'const' column is required
31+
# For example, many statsmodels models include an intercept value that must be included for the model prediction
32+
inputArray = pd.DataFrame([[1.0, Speed_sensor, Vibration, Engine_Load, Coolant_Temp, Intake_Pressure, Engine_RPM, Speed_OBD, Intake_Air, Flow_Rate, Throttle_Pos, Voltage, Ambient, Accel, Engine_Oil_Temp, Speed_GPS, GPS_Longitude, GPS_Latitude, GPS_Bearing, GPS_Altitude, Turbo_Boost, Trip_Distance, Litres_Per_km, Accel_Ssor_Total, CO2, Trip_Time, CO_emission, HC_emission, PM_emission, NOx_emission, CO2_emission, Fuel_level, Oil_life, Vibration_alert, VibrationAlert_Total, Vibration_Recent, Turbo_alert, Emission_alert, Fog_control, Engine_control]],
33+
columns=['const', 'Speed_sensor', 'Vibration', 'Engine_Load', 'Coolant_Temp', 'Intake_Pressure', 'Engine_RPM', 'Speed_OBD', 'Intake_Air', 'Flow_Rate', 'Throttle_Pos', 'Voltage', 'Ambient', 'Accel', 'Engine_Oil_Temp', 'Speed_GPS', 'GPS_Longitude', 'GPS_Latitude', 'GPS_Bearing', 'GPS_Altitude', 'Turbo_Boost', 'Trip_Distance', 'Litres_Per_km', 'Accel_Ssor_Total', 'CO2', 'Trip_Time', 'CO_emission', 'HC_emission', 'PM_emission', 'NOx_emission', 'CO2_emission', 'Fuel_level', 'Oil_life', 'Vibration_alert', 'VibrationAlert_Total', 'Vibration_Recent', 'Turbo_alert', 'Emission_alert', 'Fog_control', 'Engine_control'],
34+
dtype=float)
35+
prediction = _thisModelFit.predict(inputArray)
36+
37+
try:
38+
EM_EVENTPROBABILITY = float(prediction)
39+
except TypeError:
40+
# If the model expects non-binary responses, a TypeError will be raised.
41+
# The except block shifts the prediction to accept a non-binary response.
42+
EM_EVENTPROBABILITY = float(prediction[:,1])
43+
44+
if (EM_EVENTPROBABILITY >= 0.2269170579029734):
45+
EM_CLASSIFICATION = '1'
46+
else:
47+
EM_CLASSIFICATION = '0'
48+
49+
return(EM_EVENTPROBABILITY, EM_CLASSIFICATION)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "DecisionTreeClassifier",
3+
"description": " : Maintenance_flag = Speed_sensor + Vibration + Engine_Load + Coolant_Temp + Intake_Pressure + Engine_RPM + Speed_OBD + Intake_Air + Flow_Rate + Throttle_Pos + Voltage + Ambient + Accel + Engine_Oil_Temp + Speed_GPS + GPS_Longitude + GPS_Latitude + GPS_Bearing + GPS_Altitude + Turbo_Boost + Trip_Distance + Litres_Per_km + Accel_Ssor_Total + CO2 + Trip_Time + CO_emission + HC_emission + PM_emission + NOx_emission + CO2_emission + Fuel_level + Oil_life + Vibration_alert + VibrationAlert_Total + Vibration_Recent + Turbo_alert + Emission_alert + Fog_control + Engine_control",
4+
"function": "classification",
5+
"scoreCodeType": "python",
6+
"trainTable": " ",
7+
"trainCodeType": "Python",
8+
"algorithm": "",
9+
"targetVariable": "Maintenance_flag",
10+
"targetEvent": 1,
11+
"targetLevel": "BINARY",
12+
"eventProbVar": "EM_EVENTPROBABILITY",
13+
"modeler": "sasdemo",
14+
"tool": "Python 3",
15+
"toolVersion": "3.8.3"
16+
}

0 commit comments

Comments
 (0)