我已经使用pmdarima模块的管道方法创建了一个模型
fit2 = Pipeline([
('boxcox', BoxCoxEndogTransformer(lmbda2=1e-6)),
('arima', pmd.AutoARIMA(trace=True,
suppress_warnings=True,
m=12,
stepwise=True))])
并使用列车数据集拟合模型
fitted = fit2.fit(train)
并且能够进行预测。之后,尝试将模型持久化为pickle文件
pickle_tgt = "arima.pkl"
joblib.dump(fitted, pickle_tgt, compress=3)
然后我将pickle文件读回另一个python实例
def get_model(product_id):
file_path = "collector/resources/" + product_id
try:
model = joblib.load(file_path)
return model
except Exception:
print(traceback.format_exc())
然而,当我尝试使用我导入的模型进行预测时
fc, confint = model.predict(n_periods=24, return_conf_int=True)
它失败并返回下面的堆栈跟踪
fc, confint = model.predict(n_periods=n_periods, return_conf_int=True)
File "C:Userscollectorvenvlibsite-packagespmdarimapipeline.py", line 436, in predict
alpha=alpha, **predict_kwargs)
File "C:Userscollectorvenvlibsite-packagespmdarimautilsmetaestimators.py", line 53, in <lambda>
out = (lambda *args, **kwargs: self.fn(obj, *args, **kwargs))
File "C:Userscollectorvenvlibsite-packagespmdarimaarimaauto.py", line 184, in predict
return_conf_int=return_conf_int, alpha=alpha)
File "C:Userscollectorvenvlibsite-packagespmdarimaarimaarima.py", line 651, in predict
alpha=alpha)
File "C:Userscollectorvenvlibsite-packagespmdarimaarimaarima.py", line 86, in _seasonal_prediction_with_confidence
**kwargs)
File "C:Userscollectorvenvlibsite-packagesstatsmodelstsastatespacemlemodel.py", line 3234, in get_prediction
transformed=True, includes_fixed=True, **kwargs)
File "C:Userscollectorvenvlibsite-packagesstatsmodelstsastatespacesarimax.py", line 1732, in _get_extension_time_varying_matrices
if not self.simple_differencing and self._k_trend > 0:
AttributeError: 'SARIMAX' object has no attribute '_k_trend'
pmdarima版本是1.6.0,我尝试在sarimax.py文件中设置_k_trend=0变量,但似乎没有任何效果。有人能解决这个问题吗?
显然,在colab和本地env中安装pmdarima时存在版本兼容性问题,请在此处查找更多信息