当前位置:网站首页>Model saving and loading of sklearn
Model saving and loading of sklearn
2022-07-24 17:56:00 【samll-guo】
'''
After training the model, save it locally , And reload the model for two methods of prediction
'''
# Method 1:pickle
from sklearn import svm
from sklearn import datasets
import pickle
clf = svm.SVC()
iris = datasets.load_iris()
X,y = iris.data, iris.target
clf.fit(X,y)
# Save model
with open('clf.pickle','wb') as f:
pickle.dump(clf,f) # Will train the good model clf Stored in variables f in , And save to local
# Reloading and using the model
with open('clf.pickle','rb') as f:
clf_load = pickle.load(f) # Store the model in variables clf_load in
print(clf_load.predict(X[0:1000])) # Call the model and predict the results # Method 2:joblib Method
from sklearn import svm
from sklearn import datasets
import joblib
# sklearn.externals.joblib Function is used in 0.21 And previous versions of , In the latest version , This function should be deprecated and imported directly joblib
# from sklearn.externals import joblib
clf = svm.SVC()
iris = datasets.load_iris()
X,y = iris.data, iris.target
clf.fit(X,y)
# Save the trained ones clf Model
joblib.dump(clf,'clf.pkl',compress=3)
# Reload the trained clf Model
clf3 = joblib.load('clf.pkl')
print(clf3.predict(X[0:1000])) # Print forecast
# Comparatively speaking ,joblib More efficient , but 32 position python and 64 position python It cannot be used seamlessly , You can check the situation of this machine through the following code
import platform
print(platform.architecture())边栏推荐
- Blackmagic Fusion Studio 18
- 分家后印象笔记过日子依然不好过,骚操作却不少
- Openlayers: point aggregation effect
- 去不图床容量兑换
- OpenCV 图片旋转
- Tensorflow introductory tutorial (40) -- acunet
- 0615 ~ realize RBAC permission management with user-defined annotations
- 还在从零开始搭建项目?这款升级版快速开发脚手架值得一试!
- C language custom type explanation - structure
- [leetcode] 30. Concatenate substrings of all words
猜你喜欢

The use and Simulation of character and string library functions in C language

SV强制类型转换和常数

二维卷积——torch.nn.conv2d的使用

Gan Development Series II (pggan, Singan)

SSM framework learning
Link editing tips of solo blog posts illegal links

700. 二叉搜索树中的搜索-dfs法

获取同程(艺龙)酒店数据
How to remove the top picture of the bubble skin article details of solo blog

0630~职业素养课
随机推荐
仅需一个依赖给Swagger换上新皮肤,既简单又炫酷!
深入解析著名的阿里云Log4j 漏洞
简单测试JS代码
Blackmagic Fusion Studio 18
Preliminary understanding of redis
Use prometheus+grafana to monitor MySQL performance indicators
mac数据库管理软件Navicat Premium Essentials Mac
Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!
0701~放假总结
干货|值得收藏的三款子域名收集工具
213. 打家劫舍 II-动态规划
C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
0612~quartz timer frame
awk从入门到入土(17)awk多行写法
分家后印象笔记过日子依然不好过,骚操作却不少
单细胞代码解析-妇科癌症单细胞转录组及染色质可及性分析1
com.mysql.cj.jdbc.exceptions. MySQLTransactionRollbackException: Deadlock found when trying to get lo
Openlayers: point aggregation effect
0621~ES&Lucene
Simple test JS code