【问题标题】:Updating ARIMA forecasting in Python在 Python 中更新 ARIMA 预测
【发布时间】:2017-07-28 22:43:21
【问题描述】:

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

【问题讨论】:

  • 试试PyFlux
  • 所以你从网上复制了一段代码,但令人惊讶的是它并没有达到你想要的效果?它到底应该做什么,而它又做了什么?

标签: python time-series


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    在使用 Statsmodels API 时,我也有同样的问题,我发现金字塔 API 非常有用。 auto_arima() 函数可让您添加新的观察结果。这是一个例子http://www.alkaline-ml.com/pmdarima/0.9.0/auto_examples/arima/example_add_new_samples.html

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 2023-03-30
      • 1970-01-01
      • 2021-03-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      相关资源
      最近更新 更多