简体   繁体   中英

Export machine learning model

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)

modelC.model

How can i export it or is there a any function for it ?

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")

In fact, you can use pickle.dump instead of joblib , but joblib does a very good job at compressing the numpy arrays inside classifiers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM