What does it mean for a timeseries to have multiple seasonalities?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

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

0

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

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

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.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

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.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

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.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.