sklearn ํ์ดํ๋ผ์ธ์์ ๊ฐ์ ธ์จ RandomForestClassifier๋ฅผ ํผํด๋งํ๋ฉด ๋ค๋ฅธ ๋
ธํธ๋ถ์ ๋ก๋ํ ๋ ModuleNotFoundError
๋ฐ์ํฉ๋๋ค. ์๋ชป๋ ๋ชจ๋์ด ์กด์ฌํ์ง๋ง ์ฐพ์ ์ ์์ต๋๋ค: sklearn.ensemble._forest
.
from sklearn.ensemble import RandomForestClassifier
from sklearn.pipeline import make_pipeline
import pickle
import numpy as np
pipeline = make_pipeline(
# Other steps in pipeline as well
RandomForestClassifier(),
)
# Create some fake data
X_train = np.array([[2,8,5],[4,7,2],[1,9,4]])
y_train = np.array([26, 29, 18])
# Train the model
pipeline.fit(X_train, y_train)
# Pickle the model
model = pipeline.named_steps['randomforestclassifier']
outfile = open("model.pkl", "wb")
pickle.dump(model, outfile)
outfile.close()
๋ค๋ฅธ ๋ ธํธ๋ถ์์:
from sklearn.ensemble import RandomForestClassifier
import pickle
# 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 here
model
RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,
criterion='gini', max_depth=None, max_features='auto',
max_leaf_nodes=None, max_samples=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=100,
n_jobs=None, oob_score=False, random_state=None,
verbose=0, warm_start=False)
---------------------------------------------------------------------------
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'
System:
python: 3.7.4 (default, Oct 9 2019, 16:55:50) [GCC 7.4.0]
executable: /usr/local/bin/python3.7
machine: Linux-4.15.0-88-generic-x86_64-with-debian-buster-sid
Python deps:
pip: 19.3
setuptools: 40.8.0
sklearn: 0.21.3
numpy: 1.17.2
scipy: 1.3.1
Cython: None
pandas: 0.25.1
ํธ์ง: ์ค๋ช ์์
sklearn.ensemble._forest
์์ ๊ฐ์ ธ์ฌ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๊ฒ์ ์๋๋ ๊ฒ์
๋๊น?
ํ์ดํ๋ผ์ธ์ ํผํดํ๋ ๋ฐ ์ฌ์ฉํ scikit-learn ๋ฒ์ ๊ณผ ํผํด ํด์ ํ๋ ค๋ ๋ฒ์ ์ ์๋ ค์ฃผ์ค ์ ์์ต๋๊น? 0.22.1์์ ํผํด๋งํ๋ ๋์ 0.21.3์์ ํผํด๋ง์ ํด์ ํ๋ ค๊ณ ํ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
๊ทธ๋ฐ ๋ค์ ์
๋ฐ์ดํธํ๋ฉด ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ค๋ฅธ scikit-learn ๋ฒ์ ์์ pickling/unpickling์ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ ๋ฒ๊ทธ๋ก ๊ฐ์ฃผํ์ง ์์ต๋๋ค.
๊ทธ๊ฒ์ด ๋ฐ๋ก ๋ฌธ์ ์์ต๋๋ค. ๋ค๋ฅธ ์ปค๋์์ ์ ๋ ธํธ๋ถ์ ์์ํ๋ค๋ ์ฌ์ค์ ๋ชฐ๋์ต๋๋ค. ์ ์ํ ๋ต๋ณ์ ์ง์ฌ์ผ๋ก ๊ฐ์ฌ๋๋ฆฝ๋๋ค.