How To Forecast Time Series Data With Multiple Seasonal Periods

Forecasting a time series data signal ahead of time helps to make better decisions around planning capacity and estimating demand. Applications reach into all areas of business from predicting website traffic to actual traffic on the road.

This post will outline the modeling steps involved in forecasting a time series sequence with multiple seasonal periods, including:

  • Multiple seasonality using the fourier series with different periods

  • Seasonal behavior with external regressors in the form of fourier terms added to an ARIMA model

  • Best fit model discovered via Akaike Information Criteria (AIC)

For full details, be sure to check out the original post titled Forecasting Time Series Data with Multiple Seasonal Periods on the Pivotal blog.

To illustrate the steps, we will rely on sample time series data that tracks the number of people logging into a gaming website over the course of two months (Figure 1).

Fig. 1: Time series plot of number of gamer logins per hour

This time series demonstrates the concept of seasonal behavior over a short period, with the number of gamers logging in following both daily and weekly seasonality as shown by the considerably higher traffic on weekends versus weekdays. At the daily level, a cycle where logins increases towards mid-day and decreases thereafter is clearly visible to the naked eye.

Building The Model

Autoregressive integrated moving average (ARIMA) models are used to model time series data, however to deal with multiple seasonality, external regressors need to be added to the ARIMA model. To incorporate the multiple seasonality in our gamer login behavior, we have added Fourier terms as external regressors to the ARIMA model, where Nt is an ARIMA process.

This approach is flexible, allowing you to incorporate multiple periods in your model. In our example, we have added two seasonal periods, daily and weekly, with p1 and p2 including 24 hours and 168 hours respectively. AIC, derived from information theory, estimates the quality of model compared to other models, providing a means for model selection. The Ki value is chosen to minimize the AIC criteria.

To derive the right number of Fourier terms corresponding to each of the periods, we need to calculate the AIC values of the ARIMA model with varying Fourier terms. The scatter plot above shows the AIC values with varying number of Fourier terms for the two periods. Our example suggests we can best minimize the AIC criteria with one Fourier term corresponding to a period of 24 hours and two Fourier terms corresponding to a period of 168 hours.

To determine this, we wrote some R code to tune the number of Fourier terms and find the minimum AIC values is shown below.

Code 1: Finding the optimum number of fourier terms for a given time series

The result is we determined the best line of fit for the time series is an ARIMA (4, 0, 3) model. The plot of the fitted values is shown below.  The highlighted grey regions correspond to weekends, the red line corresponds to the fitted values, and the black line corresponds to the actual values.

The coefficients and the standard errors for the various terms are shown below.

Macintosh HD:Users:loaner:Desktop:Screen Shot 2015-03-03 at 3.31.54 PM.png

The resulting equation corresponding to the final model is

where y terms correspond to the autoregressive terms and z terms correspond to the moving average terms. The external regressors correspond to fourier terms with a period of 24 hours (single frequency) and period of 168 hours (two different frequencies).

Predicting Future Values

Now that we have determined the model, the next step is to use it to predict future values. To build in testing for the model, we will use data from 1 to 750 hours is used to train the model, while the data for the next 10 hours is used for testing.

Code 2 : Forecasting the time series values using the fitted model

Macintosh HD:Users:loaner:Desktop:Screen Shot 2015-03-03 at 3.35.56 PM.png

We recommend to only forecast less than 5 values in advance.

The massively parallel processing (MPP) capabilities of Pivotal Greenplum Database and Pivotal HAWQ are great tools to forecast multiple time series at different nodes in a scalable and parallel manner.

For further examples and sample code of forecasting data sets, see the original post.

Views: 12259


You need to be a member of Data Science Central to add comments!

Join Data Science Central

© 2021   TechTarget, Inc.   Powered by

Badges  |  Report an Issue  |  Privacy Policy  |  Terms of Service