ARMA out-of-sample prediction with statsmodels

两盒软妹~` 提交于 2019-11-28 06:02:24

I thought there was an issue for this. If you file one on github, I'll be more likely to remember to add something like this. The prediction machinery is not (yet) available as user-facing functions, so you'd have to do something like this.

If you've fit a model already, then you can do this.

# this is the nsteps ahead predictor function
from statsmodels.tsa.arima_model import _arma_predict_out_of_sample
res = sm.tsa.ARMA(y, (3, 2)).fit(trend="nc")

# get what you need for predicting one-step ahead
params = res.params
residuals = res.resid
p = res.k_ar
q = res.k_ma
k_exog = res.k_exog
k_trend = res.k_trend
steps = 1

_arma_predict_out_of_sample(params, steps, residuals, p, q, k_trend, k_exog, endog=y, exog=None, start=len(y))

This is a new prediction 1 step ahead. You can tack this on to y, and you'll need to update your residuals.

For univariate out-of sample prediction (test) We can use:

ARMAResults.forecast(steps=1, exog=None, alpha=0.05)

It would be res.forcast(steps=1)

Same is available for ARIMA as well.

ARIMAResults.forecast(steps=1, exog=None, alpha=0.05)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!