【问题标题】:Export machine learning model导出机器学习模型
【发布时间】:2016-10-27 13:51:27
【问题描述】:

我正在创建机器学习算法并希望将其导出。 假设我正在使用 scikit 学习库和随机森林算法。

 modelC=RandomForestClassifier(n_estimators=30)
 m=modelC.fit(trainvec,yvec)

modelC.model

我怎样才能导出它或者它有什么功能?

【问题讨论】:

    标签: python python-2.7 machine-learning scikit-learn


    【解决方案1】:

    如果你关注 scikit documentation 的模型持久性

    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 数组方面做得非常好。

    【讨论】:

    • 感谢您的回复。它正在工作,但我怎样才能将它再次导入到我的预测 python 文件中?
    • @BeyhanGül joblib.load
    猜你喜欢
    • 2020-03-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2021-02-20
    相关资源
    最近更新 更多