Get startedGet started for free

Forecasting

1. Forecasting

Now that we know how to fit models, let's use them to predict the future.

2. Predicting the next value

Take a simple AR(1) model. At any point in the time series we can estimate the next series value. We make this prediction by multiplying the previous value by the lag-one AR coefficient. If the previous value was 10 and coefficient a-one is 0.6, we would estimate the next value as 6. If the shock term had a standard deviation of 1, we would predict our lower and upper uncertainty limits to be 5 and 7.

3. One-step-ahead predictions

In the time period we have data for, we can make lots of these predictions in-sample; using the previous series value to estimate the next ones. This is called a one-step-ahead prediction. This allows us to evaluate how good our model is at predicting just one value ahead. Here, the mean prediction is marked with a red line while the uncertainty range is shaded. The uncertainty is due to the random shock terms that we can't predict.

4. Making one-step-ahead predictions

We can use a fitted ARIMA model to make these predictions. Starting from a ARIMA fitted results object, we can use its get-underscore-prediction method to generate in sample predictions. We set the start parameter as a negative integer stating how many steps back to begin the forecast. Setting start to -25 means we make predictions for the last 25 entries of the training data.

5. Making one-step-ahead predictions

This returns a forecast object. The central value of the forecast is stored in the predicted-underscore-mean attribute of the forecast object. This predicted mean is a pandas series.

6. Confidence intervals

To get the lower and upper limits on the values of our predictions we use the conf-underscore-int method of the forecast object. This generates a pandas DataFrame of the lower and upper uncertainty range of our prediction.

7. Plotting predictions

We can use pyplot's dot-plot method to plot the mean value. We can use pyplot-dot-fill-underscore-between to shade the area between our lower and upper limits.

8. Plotting predictions

9. Dynamic predictions

We can make predictions further than just one step ahead. To make these dynamic predictions we predict one step ahead, and use this predicted value to forecast the next value after that, and so on. Since we don't know the shock terms at each step, our uncertainty can grow very quickly.

10. Making dynamic predictions

Making dynamic predictions is very similar to making one-step-ahead predictions. The only difference is that in the get-predictions method, we set the parameter dynamic equals true. Everything else is exactly as before.

11. Forecasting out of sample

Finally, after testing our predictions in-sample, we can use our model to predict the future. To make future forecasts we use the get-underscore-forecast method of the results object. We choose the number of steps after the end of the training data to forecast up to. Everything else neatly follows as before.

12. Forecasting out of sample

This is also a dynamic forecast.

13. Let's practice!

I'm sure that by now you can forecast some exercises coming up. Let's practice!