Group Group Group Group Group Group Group Group Group

Tutorial Beginning Machine Learning with scikit-learn

#1

Hi,

I have done the tutorial, now I am trying to build a Lasso model:

from sklearn import linear_model
reg = linear_model.Lasso(alpha = 0.1)
reg.fit(X_train, y_train)
reg.score(X_test, y_test)

All this I have done OK, but when I try to generate the file with coremltools:

import coremltools

input_features = [“tv”, “radio”, “newspaper”]
output_feature = “sales”

model = coremltools.converters.sklearn.convert(reg, input_features, output_feature)
model.save(“AdvertisingLasso.mlmodel”)

I have in the line that generates the model the following error:


ValueError Traceback (most recent call last)
in ()
2 output_feature = “sales”
3
----> 4 model = coremltools.converters.sklearn.convert(reg, input_features, output_feature)
5 model.save(“AdvertisingLasso.mlmodel”)

/anaconda2/lib/python2.7/site-packages/coremltools/converters/sklearn/_converter.pyc in convert(sk_obj, input_features, output_feature_names)
144 from ._converter_internal import _convert_sklearn_model
145 spec = _convert_sklearn_model(
–> 146 sk_obj, input_features, output_feature_names, class_labels = None)
147
148 return MLModel(spec)

/anaconda2/lib/python2.7/site-packages/coremltools/converters/sklearn/_converter_internal.pyc in _convert_sklearn_model(input_sk_obj, input_features, output_feature_names, class_labels)
146 # that step in the list.
147 obj_list = [ Input(sk_obj_name, sk_obj, _get_converter_module(sk_obj))
–> 148 for sk_obj_name, sk_obj in sk_obj_list]
149
150

/anaconda2/lib/python2.7/site-packages/coremltools/converters/sklearn/_converter_internal.pyc in _get_converter_module(sk_obj)
96 “Transformer ‘%s’ not supported; supported transformers are %s.”
97 % (repr(sk_obj),
—> 98 “,”.join(k.name for k in _converter_module_list)))
99
100 return _converter_module_list[cv_idx]

ValueError: Transformer ‘Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000,
normalize=False, positive=False, precompute=False, random_state=None,
selection=‘cyclic’, tol=0.0001, warm_start=False)’ not supported; supported transformers are coremltools.converters.sklearn._dict_vectorizer,coremltools.converters.sklearn._one_hot_encoder,coremltools.converters.sklearn._normalizer,coremltools.converters.sklearn._standard_scaler,coremltools.converters.sklearn._imputer,coremltools.converters.sklearn._NuSVC,coremltools.converters.sklearn._NuSVR,coremltools.converters.sklearn._SVC,coremltools.converters.sklearn._SVR,coremltools.converters.sklearn._linear_regression,coremltools.converters.sklearn._LinearSVC,coremltools.converters.sklearn._LinearSVR,coremltools.converters.sklearn._logistic_regression,coremltools.converters.sklearn._random_forest_classifier,coremltools.converters.sklearn._random_forest_regressor,coremltools.converters.sklearn._decision_tree_classifier,coremltools.converters.sklearn._decision_tree_regressor,coremltools.converters.sklearn._gradient_boosting_classifier,coremltools.converters.sklearn._gradient_boosting_regressor.

Thanks in advance,

Felix.

#2

Hey Felix,

The CoreML converters don’t support every class yet. Lasso is currently unsupported.

-Chris

#3

Ok, thank you very much.