I fitted an ARIMA model to a time series. Now I would like to use the model to forecast the next steps, for example 1 test, given a certain input series. Usually I find that fit.forecast() is used (as below), but this forecast works on the series it was used for fitting, while I want to get the forecast for a different part of the same series.
from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(series, order=(2,0,0))
fit = model.fit()
forecast = fit.forecast()[0] # this forecast the next value given the last 2 step in 'series'
There are a variety of ways to use the model and fitted parameters to produce forecasts from (a) different starting points within the original dataset, (b) after adding new observations, or (c) a completely different dataset.
from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(series, order=(2,0,0))
fit = model.fit()
# Forecast five steps from the end of `series`
fit.forecast(5)
# Forecast five steps starting after the tenth observation in `series`
# Note that the `dynamic=True` argument specifies that it only uses the
# actual data through the tenth observation to produce each of the
# five forecasts
fit.predict(10, 14, dynamic=True)
# Add new observations (`new_obs`) to the end of the dataset
# *without refitting the parameters* and then forecast
# five steps from the end of the new observations
fit_newobs = fit.append(new_obs, refit=False)
fit_newobs.forecast(5)
# Apply the model and the fitted parameters to an
# entirely different dataset (`series2`) and then forecast
# five steps from the end of that new dataset
fit_newdata = fit.apply(series2)
fit_newdata.forecast(5)
You may find the following notebook helpful: https://www.statsmodels.org/devel/examples/notebooks/generated/statespace_forecasting.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With