如何解决coremltools.converters.sklearn.convert导致错误:NameError:未定义名称“ _tree”
TLDR:我无法将线性回归模型转换为可以保存的模型,如下所示:
model = coremltools.converters.sklearn.convert(regr,input_features,output_feature)
model.save("Advertising.mlmodel")
我正在研究Raywenderlich教程Beginning Machine Learning with SciKit Learn,当我将线性回归转换为可以保存的模型时,在Jupyter Notebook末尾偶然发现一个错误,这给了我以下错误。
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-82-da16b7baefa4> in <module>
12 # tree.export_graphviz(model)
13
---> 14 coreml_model = coremltools.converters.sklearn.convert(model,inputs,output)
15 coreml_model.save('Advertising.mlmodel')
/usr/local/lib/python3.8/site-packages/coremltools/converters/sklearn/_converter.py in convert(sk_obj,output_feature_names)
146 # several issues with the ordering of the classes are worked out. For now,147 # to use custom class labels,directly import the internal function below.
--> 148 from ._converter_internal import _convert_sklearn_model
149
150 spec = _convert_sklearn_model(
/usr/local/lib/python3.8/site-packages/coremltools/converters/sklearn/_converter_internal.py in <module>
34 from . import _LinearSVR
35 from . import _linear_regression
---> 36 from . import _decision_tree_classifier
37 from . import _decision_tree_regressor
38 from . import _gradient_boosting_classifier
/usr/local/lib/python3.8/site-packages/coremltools/converters/sklearn/_decision_tree_classifier.py in <module>
14
15 model_type = "classifier"
---> 16 sklearn_class = _tree.DecisionTreeClassifier
17
18
NameError: name '_tree' is not defined
这很奇怪,因为根据github.io/coremltools上的Apple官方文档,它们的实现与Raywenderlich相同,但仍然对我不起作用。
这是指向我的notebook
的链接解决方法
CoreMlTools适用于19.2及以下版本的scikit-learn版本。 也许您有更大的版本。
尝试通过以下方式将scikit-learn降级到19.2:
!pip install --force-reinstall 'scikit-learn==0.19.2'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。