怎么把statsmodels训练的模型本地保存?
1个回答
就是正常的存储读取,用pickle就可以了
import statsmodels.api as sm
import pickle
# 训练模型
model = sm.OLS(y,X).fit()
# 保存本地
filepath = 'my_model.pkl'
with open(filepath, 'wb') as f:
pickle.dump(model, f)
# 从本地导入使用
with open(filepath, 'rb') as f:
new_model = pickle.load(f)