ARMA out-of-sample prediction with statsmodels
Asked Answered
C

2

15

I'm using statsmodels to fit a ARMA model.

import statsmodels.api as sm
arma    = sm.tsa.ARMA(data, order =(4,4));
results = arma.fit( full_output=False, disp=0);

Where data is a one-dimensional array. I know to get in-sample predictions:

pred = results.predict();

Now, given a second data set data2, how can I use the previously calibrated model to generate a series with forecasts (predictions) based in this observations?

Costa answered 4/9, 2013 at 14:29 Comment(0)
F
17

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.

Fransen answered 4/9, 2013 at 17:29 Comment(3)
Do you know if this is still an issue with statsmodels? Is this better supported within the package now?Accession
Is this equivalent to doing res.forecast() statsmodels.org/dev/generated/…Bushy
sm.tsa.ARMA seems to be deprecated, is there any modern solution to this?Tusk
E
0

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)

Euphonic answered 23/4, 2018 at 19:2 Comment(1)
Ohh didn't see the comment from Miss PalmerEuphonic

© 2022 - 2024 — McMap. All rights reserved.