实际上,关于持久性存在很多问题,但是我使用pickle
或尝试了很多joblib.dumps
。但是当我用它保存我的随机森林时,我得到了:
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上打开。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句