Beyhan Gul
Beyhan Gul

Reputation: 1259

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 ?

Upvotes: 1

Views: 3907

Answers (1)

Eli Korvigo
Eli Korvigo

Reputation: 10503

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.

Upvotes: 7

Related Questions