What does it mean for a timeseries to have multiple seasonalities?

What does it mean for a timeseries to have multiple seasonalities?

What does it mean for a timeseries to have multiple seasonalities?

This recipe explains what does it mean for a timeseries to have multiple seasonalities


Recipe Objective

Consider sales data contains daily observations. It exhibits weekly and yearly seasonal patterns. It means we are dealing with time series containing multiple seasonal effects. Now this time series has multiple seasonities effects. It can best be cared by TBATS or BATS.

So this recipe is a short example on does a time series have multiple seasonalities? What does it mean?. Let's get started.

Step 1 - Import the library

import numpy as np import pandas as pd from tbats import BATS,TBATS

Let's pause and look at these imports. Numpy and pandas are general ones. bats will help us in building the model; make sure you have preinstalled it in your system.

Step 2 - Setup the Data

df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date']).set_index('date')

Here, we have used one time series data from github. Also, we have set our index to date.

Now our dataset is ready.

Step 3 - Splitting dataset

train_data = df[1:len(df)-12] test_data = df[len(df)-12:]

We have split our dataset into train and test samples.

Step 4 - Creating TBAT, BATS & predicting

estimator_tbats = TBATS(seasonal_periods=(7, 365.25)) model_tbats = estimator.fit(train_data) estimator_bats = BATS(seasonal_periods=(7, 365.25)) model_bats = estimator.fit(train_data) y_forecast_tbats = model_tbats.forecast(steps=365) y_forecast_bats = model_bats.forecast(steps=365) print(y_forecast_tbats) print(y_forecast_bats)

Simply, using TBATS/BATS library, we have created an object of TBATS/BATS class and thereby fit our datset on the train. Finally we are predicting the datset for the next 1 year (365 days).

Step 5 - Lets look at our dataset now

Once we run the above code snippet, we will see:

Srcoll down the ipython file to visualize the results.

Relevant Projects

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.