Get startedGet started for free

Intro to ARIMA models

1. Introduction to ARIMA models

In the last lesson you learned how to forecast. Now let's tie together forecasting and non-stationarity and show how we can overcome some problems that happen when these things meet.

2. Non-stationary time series recap

Lets look again at a non-stationary time series. This is the growth rate of world population. You learned in chapter one that you cannot apply an ARMA model to non-stationary time series such as this. We need to take the difference of the time series to make it stationary. Only then can we model it.

3. Non-stationary time series recap

Here we have taken the first difference of the time series. This is now stationary and we can model it with an ARMA model.

4. Forecast of differenced time series

However, when we do this, we will have a model which is trained to predict the value of the difference of the time series. What we really want to predict is the not the difference, but the actual value of the time series. We can achieve this by carefully transforming our predictions of the differences.

5. Reconstructing original time series after differencing

We start with predictions of the difference values The opposite of taking the difference is taking the cumulative sum or integral. We will need to use this transform to go from predictions of the difference values to predictions of the absolute values. We can do this using the numpy-dot-cumsum function. If we apply this function we now have a prediction of how much the time series changed from its initial value over the forecast period.

6. Reconstructing original time series after differencing

To get an absolute value we need to add the last value of the original time series to this.

7. Reconstructing original time series after differencing

We now have a forecast of the non-stationary time series. If we would like to plot our uncertainties as before we will need to carefully transform them as well.

8. The ARIMA model

These steps of starting with non-stationary data; differencing to make it stationary; and then integrating the forecast are very common in time series modeling. This is a lot of work! But thankfully, there is a extension of the ARMA model which does it for us! This is the ARIMA, or autoregressive integrated moving average model.

9. Using the ARIMA model

We can implement an ARIMA model using the ARIMA model class from statsmodels. The ARIMA model has three model orders. These are p the autoregressive order; d the order of differencing; and q the moving average order. In the previous lesson we were setting the middle order parameter d to zero. If d is zero we simply have an ARMA model.

10. Using the ARIMA model

When we use this model, we pass it in a non-differenced time series and the model order. Here we want to difference the time series data just once and then apply an ARMA(2,1) model. This is achieved by using an ARIMA(2,1,1) model. After we have stated the difference parameter we don't need to worry about differencing any more. We fit the model as before and make forecasts. The differencing and integration steps are all taken care of by the model object.

11. Using the ARIMA model

This is a much easier way to get a forecast for non-stationary time series!

12. Picking the difference order

We must still be careful about selecting the right amount of differencing. Remember, we difference our data only until it is stationary and no more. We will work this out before we apply our model, using the augmented Dicky-Fuller test to decide the difference order.

13. Picking the difference order

By the time we come to apply a model we already know the degree of differencing we should apply.

14. Let's practice!

Now, let's get practicing!