简体   繁体   中英

In-sample prediction interval for ARIMA in Python

I am using the statsmodels ARIMA to build models and give estimates. predict() can be used to give the in-sample model estimates/results. forecast() can be used to give out-of-sample estimates and prediction intervals. I need the prediction intervals for the in-sample model results. Is there any operation that can be used? Can forecast() be called for in-sample?

If possible, you should switch to using the SARIMAX model, which has more features and will be better supported going forwards (the ARIMA model will be deprecated in the next release). The results object will then have methods called get_prediction and get_forecast that will allow you to create a new results object that is extended with your new values.

The syntax for getting prediction intervals is a little different, but it supports intervals both in-sample and out-of-sample.

from statsmodels.tsa.api import SARIMAX
model = SARIMAX(timeseries, order=(1, 0, 6))
results = model.fit()

pred = results.get_prediction(start=..., end=...)
print(pred.predicted_mean)        # prediction
print(pred.conf_int(alpha=0.05))  # confidence interval

fcast = results.get_forecast(steps=...)
print(fcast.predicted_mean)        # forecast
print(fcast.conf_int(alpha=0.05))  # confidence interval

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM