在Python中更新ARIMA预测

3

我有一个包含3068个观测值的数据序列。 我希望为前3037个观测值生成一个ARIMA(0,1,1)模型,并使用该模型通过第3037个实际观测值对第3038个观测值进行预测。 然后,我希望使用第3038个实际观测值更新此ARIMA(0,1,1)模型,并使用该模型通过第3038个实际观测值对第3039个观测值进行预测。 以此类推... 如果能提供一些草稿代码示例将不胜感激。


尝试使用PyFlux - zipa
所以你从互联网上复制了一段代码,但出乎意料地它并不能实现你想要的功能?它具体应该做什么,而它却做了什么? - MB-F
2个回答

0

0

在我看来,更新整个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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接