2017-08-09 313 views
1

我会用(Statsmodels)ARIMA,以便从一系列的预测值不同的结果:Statsmodels ARIMA - 使用预测()和预测()

plt.plot(ind, final_results.predict(start=0 ,end=26)) 
plt.plot(ind, forecast.values) 
plt.show() 

我认为我会得到相同的结果从这两幅图,而是我得到这个: enter image description here

我想知道,如果问题是否有关预测预测

回答

0

从图表中看起来好像您正在执行带有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)。另外,由于我比stat简单的迭代预测循环(这是主观的)更信任statsmodels函数的内部功能,所以我推荐使用forecast(step)predict(start, end)