1. SARIMA models
Now you know how to find seasonality in data, in this lesson you'll learn how to use that seasonality to make more accurate predictions.
2. The SARIMA model
A SARIMA or seasonal ARIMA model is the tool of choice for seasonal time series. Previously we saw that we could split up our time series into a seasonal and some non-seasonal components.
Fitting a SARIMA model is like fitting two different ARIMA models at once, one to the seasonal part and another to the non-seasonal part.
Since we have these two models we will have two sets of orders. We have non-seasonal orders for the autoregressive, difference and moving average parts. We also have this set of orders for the seasonal part. We use capital P, D and Q for these seasonal orders.
There is also a new order, S, which is the length of the seasonal cycle.
3. The SARIMA model
Lets compare the SARIMA and ARIMA model further.
This is the equation for a simple ARIMA model. We regress the time series against itself at lags-1 and 2 and against the shock at lag-1.
This is the equation for a simple SARIMA model with season length of 7 days. This SARIMA model only has a seasonal part; we have set the non-seasonal orders to zero. We regress the time series against itself at lags of one season and two seasons and against the shock at lag of one season.
This particular SARIMA model will be able to capture seasonal, weekly patterns, but won't be able to capture local, day-to-day patterns.
If we construct a SARIMA model and include non-seasonal orders as well, then we can capture both of these patterns.
4. Fitting a SARIMA model
Fitting a SARIMA model is almost the same as fitting an ARIMA model. We import the SARIMAX class from statsmodels. This functions a lot like the ARIMA class we used before.
The only difference is that we can specify the seasonal order as well as the regular order when we instantiate the model.
This means that there are a lot of model orders we need to find.
In the last lesson you learned how to find the seasonal period, S, using the ACF. The next task is to find the order of differencing.
5. Seasonal differencing
To make a time series stationary we may need to apply seasonal differencing.
In seasonal differencing, instead of subtracting the most recent time series value, we subtract the time series value from one cycle ago.
We can take the seasonal difference by using the DataFrame-dot-diff method. This time we pass in an integer S, the length of the seasonal cycle.
6. Differencing for SARIMA models
If the time series shows a trend then we take the normal difference.
7. Differencing for SARIMA models
If there is a strong seasonal cycle, then we will also take the seasonal difference.
8. Differencing for SARIMA models
Once we have found the two orders of differencing, and made the time series stationary, we need to find the other model orders.
9. Finding p and q
To find the non-seasonal orders, we plot the ACF and the PACF of the differenced time series.
10. Finding P and Q
To find the seasonal orders we plot the ACF and PACF of the differenced time series at multiple seasonal steps. Then we can use the same table of ACF and PACF rules to work out the seasonal order.
11. Plotting seasonal ACF and PACF
We make these seasonal ACF and PACF plots using the plot-acf and plot-pacf functions, but this time we set the lags parameter to a list of lags instead of a maximum. This plots the ACF and PACF at these specific lags only.
12. Let's practice!
Thats it for this lesson cycle. Let's practice!