python - 在 Python 中更新 ARIMA 预测

标签 python time-series

我有一个包含 3068 个观察值的系列。 我想为第一个 3037 次观察生成一个 ARIMA(0,1,1) 模型,并用这个模型预测第 3038 个实际观察到第 3037 个。 然后我想用 3038 个实际观察更新这个 ARIMA(0,1,1) 模型,并用这个模型预测第 3039 个实际观察到第 3038 个实际观察。 继续... 一些草稿代码示例将不胜感激。

最佳答案

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

关于python - 在 Python 中更新 ARIMA 预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42670077/

相关文章:

python - 在 python pandas 数据帧中添加时间序列强度的廉价方法

python - 带有 Redis 的 Django websockets

用于树结构的类似 Python numpy 的接口(interface)

python - 如何获取任何 python 方法的参数?

python - Sqlalchemy:当字符串位于左侧且列位于右侧时,使用 PSQL 的 `~` 运算符

mysql - 在具有计数条件的日期之间选择

python - 从 3D 创建 4D 上对角线数组

python - 如何在 Python 中识别 ARIMA 模型的 p(滞后阶数)

python - 如何绘制从 EEG 信号中提取的 ICA 分量?

python - 使用 TimeGrouper 进行 Pandas 时间序列分组