Joblib 机器学习—保存模型|加载模型_CodingPark编程公园
程序员文章站
2022-07-13 09:00:54
...
Joblib描述
Joblib可以用于机器学习 — 保存模型|加载模型
模型保存
joblib.dump( )
加载模型
joblib.load( )
举个例子
#加载模块
from sklearn.datasets import load_iris
import joblib
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
#分割数据集
data = load_iris()
X = data.data
y = data.target
train_X,test_X,train_y,test_y = train_test_split(X,y,test_size=0.3,random_state=2)
#训练模型
lr = LinearRegression()
lr.fit(train_X,train_y)
#将训练的模型保存到磁盘(value=模型名) 默认当前文件夹下
joblib.dump(filename='LR.model',value=lr)
# 下载本地模型
model1 = joblib.load(filename="LR.model")
#对本地模型进行预测
print(model1.predict(test_X))
print(model1.score(test_X,test_y))
# 重新设置模型参数并训练
model1.set_params(normalize=True).fit(train_X,train_y)
#新模型做预测
print(model1.predict(test_X))
print(model1.score(test_X,test_y))
这篇文章就用到了Joblib
????情感分析_CodingPark编程公园
https://blog.csdn.net/weixin_38411989/article/details/107838752?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161789235716780265445227%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=161789235716780265445227&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_v2~rank_v29-5-107838752.nonecase&utm_term=svm
上一篇: zookeeper单节点部署
下一篇: 机器学习入门(一)