如何在 scikit-learn 中保存随机森林? [英] How to save a randomforest in scikit-learn?
本文介绍了如何在 scikit-learn 中保存随机森林?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上有很多关于持久性的问题,但我已经尝试了很多使用 pickle
或 joblib.dumps
.但是当我用它来保存我的随机森林时,我得到了这个:
Actually there is a lot of question about persistence,but i have tried a lot using pickle
or joblib.dumps
. but when i use it to save my random forest i got this:
ValueError: ("Buffer dtype mismatch, expected 'SIZE_t' but got 'long'", <type 'sklearn.tree._tree.ClassificationCriterion'>, (1, array([10])))
谁能告诉我为什么?
一些代码供审查
forest = RandomForestClassifier()
forest.fit(data[:n_samples], target[:n_samples ])
import cPickle
with open('rf.pkl', 'wb') as f:
cPickle.dump(forest, f)
with open('rf.pkl', 'rb') as f:
forest = cPickle.load(f)
或
from sklearn.externals import joblib
joblib.dump(forest,'rf.pkl')
from sklearn.externals import joblib
forest = joblib.load('rf.pkl')
推荐答案
使用不同的 32/64 位版本的 python 来保存/加载导致,如 在 64 位 python 上训练的 Scikits-Learn RandomForrest 不会在 32 位 python 上打开 建议.
It is caused by using different 32/64 bit version of python to save/load, as Scikits-Learn RandomForrest trained on 64bit python wont open on 32bit python suggests.
这篇关于如何在 scikit-learn 中保存随机森林?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文