Scikit-learn: ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ๊ฐ€์ ธ์˜จ ์ ˆ์ธ ๋ชจ๋ธ์„ ๋กœ๋“œํ•  ๋•Œ ๊ฐ€์ ธ์˜ค๊ธฐ ์˜ค๋ฅ˜

์— ๋งŒ๋“  2020๋…„ 02์›” 27์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: scikit-learn/scikit-learn

๋ฒ„๊ทธ ์„ค๋ช…

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

ํŽธ์ง‘: ์„ค๋ช… ์ˆ˜์ •

Question

๋ชจ๋“  3 ๋Œ“๊ธ€

sklearn.ensemble._forest ์—์„œ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์˜๋„๋œ ๊ฒƒ์ž…๋‹ˆ๊นŒ?

ํŒŒ์ดํ”„๋ผ์ธ์„ ํ”ผํดํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•œ scikit-learn ๋ฒ„์ „๊ณผ ํ”ผํด ํ•ด์ œํ•˜๋ ค๋Š” ๋ฒ„์ „์„ ์•Œ๋ ค์ฃผ์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ? 0.22.1์—์„œ ํ”ผํด๋งํ•˜๋Š” ๋™์•ˆ 0.21.3์—์„œ ํ”ผํด๋ง์„ ํ•ด์ œํ•˜๋ ค๊ณ  ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿฐ ๋‹ค์Œ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค๋ฅธ scikit-learn ๋ฒ„์ „์—์„œ pickling/unpickling์„ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„๊ทธ๋กœ ๊ฐ„์ฃผํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ทธ๊ฒƒ์ด ๋ฐ”๋กœ ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ปค๋„์—์„œ ์ƒˆ ๋…ธํŠธ๋ถ์„ ์‹œ์ž‘ํ–ˆ๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ชฐ๋ž์Šต๋‹ˆ๋‹ค. ์‹ ์†ํ•œ ๋‹ต๋ณ€์— ์ง„์‹ฌ์œผ๋กœ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰