Professional Documents
Culture Documents
What Is Time Series Decomposition and How Does It Work?
What Is Time Series Decomposition and How Does It Work?
Sachin Date
A seasonal component
A trend component
A cyclical component, and
A noise component.
In case of the hourly weather data, one knows what are the
underlying physical phenomena that are causing the two
seasonal patterns. But in most cases, it’s not possible to
know what are all the factors that are introducing
seasonality into your data. And so, it is seldom easy to
unearth all the seasonal periods that may be hiding in a time
series.
Additive combination
If the seasonal and noise components change the trend by
an amount that is independent of the value of trend, the
trend, seasonal and noise components are said to behave in
an additive way. One can represent this situation as
follows:
Multiplicative combination
If the seasonal and noise components change the trend by
an amount that depends on the value of trend, the three
components are said to behave in a multiplicative way as
follows:
Let’s load the data into a pandas DataFrame and plot the
time series:
import pandas as pd
import numpy as np
import math
from matplotlib import pyplot as pltmydateparser = lambda x:
pd.datetime.strptime(x, '%d-%m-%y')df =
pd.read_csv('retail_sales_used_car_dealers_us_1992_2020.csv',
header=0, index_col=0, parse_dates=['DATE'],
date_parser=mydateparser)fig =
plt.figure()fig.suptitle('Retail sales of used car dealers in
the US in millions of
dollars')df['Retail_Sales'].plot()plt.show()
Now let’s begin the step by step decomposition of
this time series.
(Image by Author)
Thus the retail used car sales time series is assumed to have
the following multiplicative decomposition model:
Therefore:
We’ll add a new column into our data frame and fill it with
the product of the seasonal and noise components using the
above formula.
df['SEASONALITY AND NOISE'] = df['Retail_Sales']/df['2 x 12
CMA (TREND)']
Let’s plot the new column. This time, we will see the
seasonality and noise showing through:
fig = plt.figure()fig.suptitle('SEASONALITY and NOISE
components')plt.ylim(0, 1.3)df['SEASONALITY AND
NOISE'].plot()plt.show()
(Image by Author)