25
25
26
26
27
27
def _sklearn_to_dict (model ):
28
+ # As of Viya 3.4 model registration fails if character fields are longer
29
+ # than 1024 characters
30
+ DESC_MAXLEN = 1024
31
+
32
+ # As of Viya 3.4 model registration fails if user-defined properties are
33
+ # longer than 512 characters.
34
+ PROP_MAXLEN = 512
35
+
28
36
# Convert Scikit-learn values to built-in Model Manager values
29
37
mappings = {'LogisticRegression' : 'Logistic regression' ,
30
38
'LinearRegression' : 'Linear regression' ,
31
39
'SVC' : 'Support vector machine' ,
32
40
'GradientBoostingClassifier' : 'Gradient boosting' ,
41
+ 'XGBClassifier' : 'Gradient boosting' ,
42
+ 'XGBRegressor' : 'Gradient boosting' ,
33
43
'RandomForestClassifier' : 'Forest' ,
34
44
'DecisionTreeClassifier' : 'Decision tree' ,
35
45
'DecisionTreeRegressor' : 'Decision tree' ,
36
46
'classifier' : 'Classification' ,
37
47
'regressor' : 'Prediction' }
38
48
49
+ if hasattr (model , '_final_estimator' ):
50
+ estimator = type (model ._final_estimator )
51
+ else :
52
+ estimator = type (model )
53
+
39
54
# Can tell if multi-class .multi_class
40
55
result = dict (
41
- description = str (model ),
42
- algorithm = mappings .get (type ( model ) .__name__ , type ( model ) .__name__ ),
56
+ description = str (model )[: DESC_MAXLEN ] ,
57
+ algorithm = mappings .get (estimator .__name__ , estimator .__name__ ),
43
58
scoreCodeType = 'ds2MultiType' ,
44
59
trainCodeType = 'Python' ,
45
60
function = mappings .get (model ._estimator_type , model ._estimator_type ),
46
61
tool = 'Python %s.%s'
47
62
% (sys .version_info .major , sys .version_info .minor ),
48
- properties = [{'name' : k , 'value' : v }
63
+ properties = [{'name' : str (k )[:PROP_MAXLEN ],
64
+ 'value' : str (v )[:PROP_MAXLEN ]}
49
65
for k , v in model .get_params ().items ()]
50
66
)
51
67
@@ -156,9 +172,6 @@ def register_model(model, name, project, repository=None, input=None,
156
172
files .append ({'name' : 'dmcas_packagescorecode.sas' ,
157
173
'file' : mas_module .score_code (),
158
174
'role' : 'Score Code' })
159
- files .append ({'name' : 'dmcas_espscorecode.sas' ,
160
- 'file' : mas_module .score_code (dest = 'ESP' ),
161
- 'role' : 'Score Code' })
162
175
files .append ({'name' : 'dmcas_epscorecode.sas' ,
163
176
'file' : mas_module .score_code (dest = 'CAS' ),
164
177
'role' : 'score' })
@@ -251,7 +264,8 @@ def publish_model(model, destination, code=None, max_retries=60,
251
264
def submit_request ():
252
265
# Submit a publishing request
253
266
if code is None :
254
- publish_req = mm .publish_model (model , destination , force = replace , ** kwargs )
267
+ publish_req = mm .publish_model (model , destination ,
268
+ force = replace , ** kwargs )
255
269
else :
256
270
publish_req = mp .publish_model (model , destination ,
257
271
code = code , ** kwargs )
@@ -265,7 +279,9 @@ def submit_request():
265
279
# Submit and wait for status
266
280
job = submit_request ()
267
281
268
- if job .state .lower () == 'completed' and job .destination .destinationType != 'microAnalyticService' :
282
+ # If model was successfully published and it isn't a MAS module, we're done
283
+ if job .state .lower () == 'completed' \
284
+ and job .destination .destinationType != 'microAnalyticService' :
269
285
return request_link (job ,'self' )
270
286
271
287
# If MAS publish failed and replace=True, attempt to delete the module
0 commit comments