如何在scikit-learn中保存随机森林?

mrb*_*ean 4 python random-forest scikit-learn

实际上有很多关于持久性的问题,但我已经尝试了很多使用picklejoblib.dumps.但当我用它来保存我的随机森林时我得到了这个:

ValueError: ("Buffer dtype mismatch, expected 'SIZE_t' but got 'long'", <type 'sklearn.tree._tree.ClassificationCriterion'>, (1, array([10])))
Run Code Online (Sandbox Code Playgroud)

谁能告诉我为什么?

一些代码供审查

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)
Run Code Online (Sandbox Code Playgroud)

要么

from sklearn.externals import joblib
joblib.dump(forest,'rf.pkl') 

from sklearn.externals import joblib
forest = joblib.load('rf.pkl')
Run Code Online (Sandbox Code Playgroud)

xgd*_*gsc 5

它是由使用不同的32/64位版本的python来保存/加载引起的,因为在64位python上训练的Scikits-Learn RandomForrest不会在32位python上打开.