统计模型ARIMA-使用Forecast()和Forecast()的不同结果 [英] Statsmodels ARIMA - Different results using predict() and forecast()

查看:0
本文介绍了统计模型ARIMA-使用Forecast()和Forecast()的不同结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会使用(StatsModels)ARIMA来预测序列中的值:

plt.plot(ind, final_results.predict(start=0 ,end=26))
plt.plot(ind, forecast.values)
plt.show()
我以为我会从这两个图中得到相同的结果,但结果却是这样的:

我想知道问题是关于预测还是预测

推荐答案

从图表上看,您似乎正在使用forecast()进行样本外预测,使用Forecast进行比特样本内预测。根据ARIMA方程的性质,对于较长的预测期,超出样本的预测往往会收敛到样本平均值。

为了了解forecast()predict()在不同场景下是如何工作的,我系统地比较了ARIMA_results类中的各种模型。请随意复制与statsmodels_arima_comparison.pyin this repository的比较。我研究了order=(p,d,q)的每一种组合,只将p, d, q限制为0或1。例如,order=(1,0,0)可以得到一个简单的自回归模型。 简而言之,我研究了三个选项,使用以下(stationary) time series

A.迭代样本内预测形成历史。历史由时间序列的前80%形成,最后20%形成测试集。然后预测测试集的第一个点,将真实值添加到历史中,预测第二个点,等等。这将给出模型预测质量的评估。

for t in range(len(test)):
    model = ARIMA(history, order=order)
    model_fit = model.fit(disp=-1)
    yhat_f = model_fit.forecast()[0][0]
    yhat_p = model_fit.predict(start=len(history), end=len(history))[0]
    predictions_f.append(yhat_f)
    predictions_p.append(yhat_p)
    history.append(test[t])

B.接下来,我通过迭代预测测试系列的下一个点,并将此预测附加到历史中,来研究样本外预测。

for t in range(len(test)):
    model_f = ARIMA(history_f, order=order)
    model_p = ARIMA(history_p, order=order)
    model_fit_f = model_f.fit(disp=-1)
    model_fit_p = model_p.fit(disp=-1)
    yhat_f = model_fit_f.forecast()[0][0]
    yhat_p = model_fit_p.predict(start=len(history_p), end=len(history_p))[0]
    predictions_f.append(yhat_f)
    predictions_p.append(yhat_p)
    history_f.append(yhat_f)
    history_f.append(yhat_p)

C.我使用了forecast(step=n)参数和predict(start, end)参数,以便使用这些方法进行内部多步预测。

model = ARIMA(history, order=order)
    model_fit = model.fit(disp=-1)
    predictions_f_ms = model_fit.forecast(steps=len(test))[0]
    predictions_p_ms = model_fit.predict(start=len(history), end=len(history)+len(test)-1)

原来:

A.预测和预测AR的结果相同,但ARMA的结果不同:test time series chart

B.预测和预测对AR和ARMA产生不同的结果:test time series chart

C.预测和预测AR的结果相同,但ARMA的结果不同:test time series chart

此外,比较B.和C.中看似相同的方法,我在结果中发现了细微但明显的差异。

我认为,差异主要是因为forecast()predict()中的"预测是在原始内生变量的水平上进行的"产生了对水平差异的预测(compare the API reference)。

此外,考虑到我更信任统计模型函数的内部功能,而不是我的简单迭代预测循环(这是主观的),我建议使用forecast(step)predict(start, end)

这篇关于统计模型ARIMA-使用Forecast()和Forecast()的不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆