.

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.

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

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.

Posted 9 November 2021

© 2021 TechTarget, Inc. Powered by

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

**Most Popular Content on DSC**

To not miss this type of content in the future, subscribe to our newsletter.

- Book: Applied Stochastic Processes
- Long-range Correlations in Time Series: Modeling, Testing, Case Study
- How to Automatically Determine the Number of Clusters in your Data
- New Machine Learning Cheat Sheet | Old one
- Confidence Intervals Without Pain - With Resampling
- Advanced Machine Learning with Basic Excel
- New Perspectives on Statistical Distributions and Deep Learning
- Fascinating New Results in the Theory of Randomness
- Fast Combinatorial Feature Selection

**Other popular resources**

- Comprehensive Repository of Data Science and ML Resources
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- 100 Data Science Interview Questions and Answers
- Cheat Sheets | Curated Articles | Search | Jobs | Courses
- Post a Blog | Forum Questions | Books | Salaries | News

**Archives:** 2008-2014 |
2015-2016 |
2017-2019 |
Book 1 |
Book 2 |
More

**Most popular articles**

- Free Book and Resources for DSC Members
- New Perspectives on Statistical Distributions and Deep Learning
- Time series, Growth Modeling and Data Science Wizardy
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- Comprehensive Repository of Data Science and ML Resources
- Advanced Machine Learning with Basic Excel
- Difference between ML, Data Science, AI, Deep Learning, and Statistics
- Selected Business Analytics, Data Science and ML articles
- How to Automatically Determine the Number of Clusters in your Data
- Fascinating New Results in the Theory of Randomness
- Hire a Data Scientist | Search DSC | Find a Job
- Post a Blog | Forum Questions

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

Join Data Science Central