How to save random forest in scikit-learn?

Actually there are many questions about conservation, but I tried a lot to use pickleor joblib.dumps. but when I use it to save my random forest, I got the following:

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

Can someone tell me why?

some code for review

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)

or

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

from sklearn.externals import joblib
forest = joblib.load('rf.pkl')
+4
source share
1 answer

This is caused by using the 32/64-bit version of python to save / load, since Scikits-Learn RandomForrest trained on a 64-bit python cannot open on a 32-bit python .

+5
source

Source: https://habr.com/ru/post/1568568/


All Articles