原创博文,转载请注明出处!

sklearn中保存和加载模型的方法

1.载入模块

  1 from sklearn.externals import joblib

2.保存模型

  1 joblib.dump(model,'filename.pkl')

3.加载模型

  1 model = joblib.load('filename.pkl')

4.例子

  1 # -*- coding: utf-8 -*-
  2 """
  3 # 作者:wanglei5205
  4 # 邮箱:wanglei5205@126.com
  5 # 博客:http://cnblogs.com/wanglei5205
  6 # github:http://github.com/wanglei5205
  7 """
  8 ### 导入模块
  9 from sklearn.datasets import load_iris
 10 from sklearn import svm
 11 from sklearn.externals import joblib
 12 
 13 iris = load_iris()
 14 x,y = iris.data,iris.target
 15 
 16 model = svm.SVC()
 17 model.fit(x,y)
 18 
 19 joblib.dump(model,'dump_model.pkl')
 20 
 21 model_new = joblib.load('dump_model.pkl')

相关文章:

  • 2021-10-28
  • 2021-08-25
  • 2021-10-25
  • 2021-10-04
  • 2022-01-16
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-03
  • 2022-12-23
  • 2021-09-09
  • 2021-11-30
  • 2021-05-31
  • 2022-12-23
  • 2022-02-05
相关资源
相似解决方案