本文介绍了导出机器学习模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一种机器学习算法,并希望将其导出.假设我正在使用scikit学习库和随机森林算法.
I am creating a machine learning algorithm and want to export it.Suppose i am using scikit learn library and Random Forest algorithm.
modelC=RandomForestClassifier(n_estimators=30)
m=modelC.fit(trainvec,yvec)
我如何导出它或有任何功能?
How can i export it or is there a any function for it ?
推荐答案
如果您遵循scikit 关于模型持久性的文档
If you follow scikit documentation on model persistence
In [1]: from sklearn.ensemble import RandomForestClassifier
In [2]: from sklearn import datasets
In [3]: from sklearn.externals import joblib
In [4]: iris = datasets.load_iris()
In [5]: X, y = iris.data, iris.target
In [6]: m = RandomForestClassifier(2).fit(X, y)
In [7]: m
Out[7]:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=2, n_jobs=1,
oob_score=False, random_state=None, verbose=0,
warm_start=False)
In [8]: joblib.dump(m, "filename.cls")
实际上,您可以使用pickle.dump
代替joblib
,但是joblib
在压缩分类器中的numpy
数组方面做得很好.
In fact, you can use pickle.dump
instead of joblib
, but joblib
does a very good job at compressing the numpy
arrays inside classifiers.
这篇关于导出机器学习模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!