import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
# Create linear regression object
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(X_train, y_train)
# how save ?????
# save here
保存经过训练的模型并在其他地方使用的最佳实践是什么?
最佳答案
sklearn
有一个 joblib
模块,用于保存模型和/或保存到文件:
from sklearn.externals import joblib
joblib.dump(regr, 'file_name.pkl')
# load pickled model later
regr = joblib.load('file_name.pkl')
您还可以使用 Python 的内置 pickle
但 docs建议使用joblib
来有效地pickle具有大型numpy
数组的对象
关于python - sklearn "transport"训练模型的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38224639/