nok / sklearn-porter

Transpile trained scikit-learn estimators to C, Java, JavaScript and others.
BSD 3-Clause "New" or "Revised" License
1.28k stars 170 forks source link

scikit-learn-0.24.1: ModuleNotFoundError: No module named 'sklearn.tree.tree' #82

Open inielse opened 3 years ago

inielse commented 3 years ago

I'm using porter 0.7.4. I updated to scikit-learn 0.24.1 (using conda) and got the error:

ModuleNotFoundError: No module named 'sklearn.tree.tree'

It seems like the imports have changed??

I got it running by changing imports: in init.py from sklearn.tree import DecisionTreeClassifier in Porter.py: from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import AdaBoostClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.ensemble import ExtraTreesClassifier from sklearn.svm import LinearSVC from sklearn.svm import SVC from sklearn.svm import NuSVC from sklearn.neighbors import KNeighborsClassifier

and later changing (in the code in a if-version) a couple places sklearn.neural_network.multilayer_perceptron \ -> from sklearn.neural_network \

dujtep-airtech commented 3 years ago

This one need to freeze version of scikit-learn. run cmd with "pip3 install scikit-learn==0.22" and freeze with "python3 -m pip freeze - scikit-learn==0.22"

smsti commented 3 years ago

I'm using porter 0.7.4. I updated to scikit-learn 0.24.1 (using conda) and got the error:

ModuleNotFoundError: No module named 'sklearn.tree.tree'

It seems like the imports have changed??

I got it running by changing imports: in init.py from sklearn.tree import DecisionTreeClassifier in Porter.py: from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import AdaBoostClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.ensemble import ExtraTreesClassifier from sklearn.svm import LinearSVC from sklearn.svm import SVC from sklearn.svm import NuSVC from sklearn.neighbors import KNeighborsClassifier

and later changing (in the code in a if-version) a couple places sklearn.neural_network.multilayer_perceptron \ -> from sklearn.neural_network \

thanks, that was extremely helpful.. i was unable to proceed via 0.22; i am on WinPython

mayowaosibodu commented 2 years ago

I'm using porter 0.7.4. I updated to scikit-learn 0.24.1 (using conda) and got the error:

ModuleNotFoundError: No module named 'sklearn.tree.tree'

It seems like the imports have changed??

I got it running by changing imports: in init.py from sklearn.tree import DecisionTreeClassifier in Porter.py: from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import AdaBoostClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.ensemble import ExtraTreesClassifier from sklearn.svm import LinearSVC from sklearn.svm import SVC from sklearn.svm import NuSVC from sklearn.neighbors import KNeighborsClassifier

and later changing (in the code in a if-version) a couple places sklearn.neural_network.multilayer_perceptron \ -> from sklearn.neural_network \

Is there a way to incorporate these changes into the repo? I've made the changes locally, but I'm wondering how these updates could be made into the source code on here. What's the procedure for that?

outcastdreamer commented 2 years ago

@nok please make changes of the import in the porter.py, or just state your module as deprecated if you are no longer updating it.

jkfurtney commented 1 year ago

Here is a monkey patch that works for me with Python 3.10.4 and sklearn==1.2.1

Just put this at the top of your source file and you will not need to patch the sklearn_porter source

import sklearn
import sklearn.tree
import sklearn.ensemble
import sklearn.svm
import sklearn.neighbors
import sklearn.neural_network
import json
import sys
sys.modules["sklearn.tree.tree"] = sklearn.tree
sys.modules["sklearn.ensemble.weight_boosting"] = sklearn.ensemble
sys.modules["sklearn.ensemble.forest"] = sklearn.ensemble
sys.modules["sklearn.svm.classes"] = sklearn.svm
sys.modules["sklearn.neighbors.classification"] = sklearn.neighbors
sys.modules["sklearn.neural_network.multilayer_perceptron"] = sklearn.neural_network

json.origional_load = json.load
json.load = lambda f, **kwargs: json.origional_load(f)
from sklearn_porter import Porter