You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pickling a RandomForestClassifier pulled from an sklearn Pipeline appears to result in a ModuleNotFoundError when loading into another notebook. The errant module does exist, but cannot be found: sklearn.ensemble._forest.
Steps/Code to Reproduce
fromsklearn.ensembleimportRandomForestClassifierfromsklearn.pipelineimportmake_pipelineimportpickleimportnumpyasnppipeline=make_pipeline(
# Other steps in pipeline as wellRandomForestClassifier(),
)
# Create some fake dataX_train=np.array([[2,8,5],[4,7,2],[1,9,4]])
y_train=np.array([26, 29, 18])
# Train the modelpipeline.fit(X_train, y_train)
# Pickle the modelmodel=pipeline.named_steps['randomforestclassifier']
outfile=open("model.pkl", "wb")
pickle.dump(model, outfile)
outfile.close()
In another notebook:
fromsklearn.ensembleimportRandomForestClassifierimportpickle# Attempt to load the pickled model in another file / notebook:infile=open("model.pkl", "rb")
model=pickle.load(infile)
infile.close()
# It's lonely over heremodel
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-20-c8d1783e8b58> in <module>
5 # Attempt to load the pickled model in another file / notebook:
6 infile = open("model.pkl", "rb")
----> 7 model = pickle.load(infile)
8 infile.close()
ModuleNotFoundError: No module named 'sklearn.ensemble._forest'
Could you tell use which version of scikit-learn did you use to pickle the pipeline and which version are you trying to unpickle. I assume that you are trying to unpickle in 0.21.3 while pickling in 0.22.1
You can then just update. However, be aware that we don't consider it as a bug because we don't support pickling/unpickling across different scikit-learn version
Describe the bug
Pickling a RandomForestClassifier pulled from an sklearn Pipeline appears to result in a
ModuleNotFoundError
when loading into another notebook. The errant module does exist, but cannot be found:sklearn.ensemble._forest
.Steps/Code to Reproduce
In another notebook:
Expected Results
Actual Results
Versions
EDIT: Fix description
The text was updated successfully, but these errors were encountered: