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.
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.
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.
train_data = df[1:len(df)-12] test_data = df[len(df)-12:]
We have split our dataset into train and test samples.
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).
Once we run the above code snippet, we will see:
Srcoll down the ipython file to visualize the results.