|
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 |
|
|
0 commit comments