coremltools
coremltools copied to clipboard
Error converting sklearn linear regression model
❓Question
System Information
- If applicable
Conversion fails with - Exception has occurred: NameError name '_tree' is not defined.
Model is a linear regression but converter appears to be looking for a decision tree one. There's also a warning about scikit-learn version 0.22.1 is not supported. Minimum required version: 0.17. Maximum required version: 0.19.2. Disabling scikit-learn conversion API.
anyone seen this?
Iain
@IAINATTWATER thanks for reporting. We are looking into this.
Is there a resolution for this ?
Not that I’m aware of.
Iain.
On Oct 26, 2020, at 6:51 PM, Harsha Sammeta [email protected] wrote:
Is there a resolution for this ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
+Also running into this issue when converting a RandomForestClassifier created in sklearn 0.23.2 (python 3.7). Coremltools conversion is being disabled due to the versioning mismatch.
Downgraded sklearn to 0.19.2 at the moment as a workaround, but this issue needs to be addressed as soon possible.
Were you able to downgrade sklearn via pip? Whenever I try to downgrade to 0.19.2 or lower it fails.
I use a PyCharm managed venv, but I just spun up another one through the terminal and ran:
pip install 'scikit-learn==0.19.2'
and it worked fine. You could also try using the --force-reinstall flag if that would help.

Thanks. Will give it a try.
Sent from my iPhone
On Nov 10, 2020, at 6:46 PM, steven-dicristofaro [email protected] wrote:
I use a PyCharm managed venv, but I just spun up another one through the terminal and ran:
pip install 'scikit-learn==0.19.2' and it worked fine. You could also try using the --force-reinstall flag if that would help.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
also for those who have some flexibility in their model deployment form factor - just discovered this library for python that looks mighty interesting https://github.com/BayesWitnesses/m2cgen#supported-models . Haven't tried it out yet, but IN THEORY it seems we could just transpile to C and bring that into a swift app with a bridging header or via .podspec.
+Java transpiling for any Android guys out there that need this to be X-platform
At least for for linear regression, it seems to work fine with the most recent version of Scikit Learn (0.24.1) if you just update the max supported version.
Hi and sorry for the post but I have the same problem for SVC model from sklearn models. I load my model with pickle because it's also pre-trained, the model works on conda. But when I want to convert this to ml, I have : name '_tree' is not defined Anyone has the same problem with SVC ? Sorry again for the post :)
@Eddy872 This was my exact problem. I wish I had a better solution for you but I ended up just switching to a model that was actually supported. It's been so long I can't quite remember which one I used. Sorry to be the bearer of bad news :(
@imcauley Thank you, maybe you can help me, which models are supported ? models from sklearn ?
I resolved! The problem is the Python version. You need creating a PyCharm Project with python version 3.7 and install scikit-learn 0.19.2
We now support the latest version of Scikit-Learn (1.1.2
). So I believe this is fixed.
Can anyone confirm this is fixed? Or give us step to reproduce the issue, if it is still an issue.
Since I have not heard anything here, I'm going to close this issue. If this has not been fixed by supporting a new version of scikit-learn, please let us know.
scikit-learn version 1.3.0 is not supported. Minimum required version: 0.17. Maximum required version: 1.1.2. Disabling scikit-learn conversion API.
Same thing again, and probably will keep being a thing since it's a hardcoded semver
coremltools/_deps/__init__.py
line 58 if anyone needs to get around the pin
Getting error when using flag --quantize-nbits 6. ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). I tried downgrading python, torch and scikit-learn but nothing changes. Anyone has a tip on how to solve this?
I got
File "/Users/user2/Documents/anchorz/data_research/lib/action_detection/batch_convert/training.py", line 67, in use_sklearn
coreml_model = ct.converters.sklearn.convert(gb_clf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/coremltools/converters/sklearn/_converter.py", line 148, in convert
from ._converter_internal import _convert_sklearn_model
File "/opt/homebrew/lib/python3.11/site-packages/coremltools/converters/sklearn/_converter_internal.py", line 24, in <module>
from . import (_SVC, _SVR, _decision_tree_classifier, _decision_tree_regressor,
File "/opt/homebrew/lib/python3.11/site-packages/coremltools/converters/sklearn/_decision_tree_regressor.py", line 16, in <module>
sklearn_class = _tree.DecisionTreeRegressor
^^^^^
NameError: name '_tree' is not defined
using: scikit-learn==1.3.0 python==3.11.5
resolved it by downgrade to scikit-learn==1.1.2 and python==3.9.6.