【sklearn】from sklearn.extermals import joblib(保存模型和加载模型)

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

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')
posted @ 2018-03-18 11:30  wanglei5205  阅读(6321)  评论(0编辑  收藏  举报
levels of contents