gpt4 book ai didi

python - 拯救随机森林

转载 作者:太空狗 更新时间:2023-10-29 20:56:06 26 4
gpt4 key购买 nike

我想保存并加载一个合适的随机森林分类器,但出现错误。

forest = RandomForestClassifier(n_estimators = 100, max_features = mf_val)
forest = forest.fit(L1[0:100], L2[0:100])
joblib.dump(forest, 'screening_forest/screening_forest.pkl')
forest2 = joblib.load('screening_forest/screening_forest.pkl')

错误是:

  File "C:\Users\mkolarek\Documents\other\TrackerResultAnalysis\ScreeningClassif
ier\ScreeningClassifier.py", line 67, in <module>
forest2 = joblib.load('screening_forest/screening_forest.pkl')
File "C:\Python27\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py",
line 425, in load
obj = unpickler.load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py",
line 285, in load_build
Unpickler.load_build(self)
File "C:\Python27\lib\pickle.py", line 1217, in load_build
setstate(state)
File "_tree.pyx", line 2280, in sklearn.tree._tree.Tree.__setstate__ (sklearn\
tree\_tree.c:18350)
ValueError: Did not recognise loaded array layout
Press any key to continue . . .

我必须初始化 forest2 还是什么?

最佳答案

我用 cPickle 解决了这个问题:

with open('screening_forest/screening_forest.pickle', 'wb') as f:
cPickle.dump(forest, f)

with open('screening_forest/screening_forest.pickle', 'rb') as f:
forest2 = cPickle.load(f)

但 joblib 解决方案也可能有用。

关于python - 拯救随机森林,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27524939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com