AttributeError:“ SARIMAXResults”对象没有属性“ append”

时间:2019-07-17 16:23:40

标签: python statsmodels arima

我已经训练了ARMA模型,现在我想在不重新训练模型的情况下对验证数据做出预测。每次进行预测时,我都希望将先前的目标附加到模型中以进行下一预测。我正在尝试使用方法append,但是尽管documentation中列出了该方法,但是却得到了AttributeError

import numpy
import pandas
from statsmodels.tsa.statespace.sarimax import SARIMAX

N_TRAIN = 100

train_data = pandas.Series(0.05 + numpy.random.randn(N_TRAIN)*0.01)
valid_data = pandas.Series(0.05 + numpy.random.randn(N_TRAIN)*0.01)

model = SARIMAX(
    endog=train_data,
    order=(1, 0, 1),              # (p, d, q)
    seasonal_order=(0, 0, 0, 0),  # (P, D, Q, S)
    trend='ct',                   # 'n', 'c', 't', 'ct'
    enforce_stationarity=False,
    enforce_invertibility=False
)

fitted_model = model.fit(disp=False, maxiter=100, method='powell')

predictions = []
for target in valid_data:
    prediction = fitted_model.forecast()
    predictions.append(prediction)
    fitted_model.append(endog=target, refit=False)
Out:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-79-9c27f92bfa88> in <module>()
     23     prediction = fitted_model.forecast()
     24     predictions.append(prediction)
---> 25     fitted_model.append(endog=target, refit=False)

C:\projects\utilities\anaconda35\lib\site-packages\statsmodels\base\wrapper.py in __getattribute__(self, attr)
     33             pass
     34 
---> 35         obj = getattr(results, attr)
     36         data = results.model.data
     37         how = self._wrap_attrs.get(attr)

AttributeError: 'SARIMAXResults' object has no attribute 'append'

1 个答案:

答案 0 :(得分:1)

链接的文档适用于Statsmodels的开发版本。最新版本v0.10不包含此功能。要使用它,您可以从Github安装开发版本。否则,此功能将在v0.11版本中发布(尚未安排日期)。