在我看来,更新整个 ARIMA 模型很快,但我还没有找到仅将下一个观察值附加到模型的方法。我的完整模型重新拟合代码:
for t in range(len(test)):
model = ARIMA(history, order=(ar, i, ma))
model_fit = model.fit(disp=0, solver=solver, max_iter=max_iter)
output = model_fit.forecast()
yhat = output[0]
predictions.append(yhat)
obs = test[t] # the real observation (the expected value)
history.append(obs)
您还可以通过在一个步骤中预测多个值来规避针对每个新观察的完整模型重新拟合。
我的代码一次性预测所有值(使用安全网,模型可能无法预测所有需要的点):
iter = 0
while iter < len(test):
model = ARIMA(history, order=(ar, i, ma))
model_fit = model.fit(disp=0, solver=solver)
remaining_steps = len(test)-iter
yhats, _, _ = model_fit.forecast(steps=remaining_steps)
len_new = len(yhats) # length of new predictions
predictions = numpy.concatenate([predictions, yhats])
history = numpy.concatenate([history, test[iter:iter+len_new]])
iter += len_new
这是关于如何在 R 中完成的相关答案:https://stats.stackexchange.com/a/34191/149565