我有一个包含3068个观测值的数据序列。 我希望为前3037个观测值生成一个ARIMA(0,1,1)模型,并使用该模型通过第3037个实际观测值对第3038个观测值进行预测。 然后,我希望使用第3038个实际观测值更新此ARIMA(0,1,1)模型,并使用该模型通过第3038个实际观测值对第3039个观测值进行预测。 以此类推... 如果能提供一些草稿代码示例将不胜感激。
我有一个包含3068个观测值的数据序列。 我希望为前3037个观测值生成一个ARIMA(0,1,1)模型,并使用该模型通过第3037个实际观测值对第3038个观测值进行预测。 然后,我希望使用第3038个实际观测值更新此ARIMA(0,1,1)模型,并使用该模型通过第3038个实际观测值对第3039个观测值进行预测。 以此类推... 如果能提供一些草稿代码示例将不胜感激。
在使用Statsmodels API时,我也有同样的问题,但是我发现pyramid API非常有帮助。 auto_arima() 函数可以让你添加新的观测值。这里有一个例子 http://www.alkaline-ml.com/pmdarima/0.9.0/auto_examples/arima/example_add_new_samples.html
在我看来,更新整个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