How to output RandomForest Classifier from python?

ε祈祈猫儿з 提交于 2019-11-29 18:38:24

问题


I have trained a RandomForestClassifier from Python Sckit Learn Module with very big dataset, but question is how can I possibly save this model and let other people apply it on their end. Thank you!


回答1:


The recommended method is to use joblib, this will result in a much smaller file than a pickle:

from sklearn.externals import joblib
joblib.dump(clf, 'filename.pkl') 

#then your colleagues can load it

clf = joblib.load('filename.pkl')

See the online docs




回答2:


Have you tried pickling the RandomForestClassifier using the Pickle module and then saving it to the disk?

Here’s an example based on the pickle docs:

import pickle

classifier = RandomForestClassifier(etc)
output = open('classifier.pkl', 'wb')
pickle.dump(classifier, output)
output.close()

The “other people” could then reload the pickled object as follows:

import pickle

f = open('classifier.pkl', 'rb')
classifier = pickle.load(f)
f.close()


来源:https://stackoverflow.com/questions/23000693/how-to-output-randomforest-classifier-from-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!