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.

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

A/B Testing Approach for Comparing Performance of ML Models
The objective of this project is to compare the performance of BERT and DistilBERT models for building an efficient Question and Answering system. Using A/B testing approach, we explore the effectiveness and efficiency of both models and determine which one is better suited for Q&A tasks.

Learn to Build an End-to-End Machine Learning Pipeline - Part 2
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, incorporating Hopsworks' feature store and Weights and Biases for model experimentation.