莫烦python教程学习笔记——保存模型、加载模型的两种方法
2024-10-19 19:44:06
# View more python tutorials on my Youtube and Youku channel!!! # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial """
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
"""
from __future__ import print_function
from sklearn import svm
from sklearn import datasets clf = svm.SVC()
iris = datasets.load_iris()
X, y = iris.data, iris.target
clf.fit(X, y) # method 1: pickle
import pickle
# save
with open('save/clf.pickle', 'wb') as f:
pickle.dump(clf, f)
# restore
with open('save/clf.pickle', 'rb') as f:
clf2 = pickle.load(f)
print(clf2.predict(X[0:1])) # method 2: joblib
from sklearn.externals import joblib
# Save
joblib.dump(clf, 'save/clf.pkl')
# restore
clf3 = joblib.load('save/clf.pkl')
print(clf3.predict(X[0:1]))
最新文章
- Webservice简介
- Multiplexing SDIO Devices Using MAX II or CoolRunner-II CPLD
- 读书笔记2014第3本:Visual Studio程序员箴言
- 关于css float 属性以及position:absolute 的区别。
- SunTlsRsaPremasterSecret KeyGenerator not available问题解决
- Thinkphp编辑器扩展类kindeditor用法
- ThreadLocal笔记
- Pick apples(大范围贪心,小范围完全背包)
- Linux 打开句柄限制的调整
- 从PRISM开始学WPF(六)MVVM(二)Command-更新至Prism7.1
- GUI学习之三——QObject学习总结
- SMBus与I2C的差别
- error::尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
- Java导出Excel表,POI 实现合并单元格以及列自适应宽度(转载)
- couldn't connect to host
- 草莓糖CMT依旧强势,数字货币量化分析[2018-05-29]
- HDFS集中式的缓存管理原理与代码剖析
- U盘拷贝大文件提示文件过大无法拷贝解决方案
- 重新认识synchronized(下)
- C/C++中qsort()以及sort()的用法