How to handle seasonality for forecasting
This article is a follow-up to a previous post. There, we identified 3 types of seasonal patterns.
Here, we’ll:
- Learn how to describe the seasonality of a time series.
- Go over 8 approaches you can use to model seasonality.
Seasonality refers to repeatable patterns that recur over some period. It is an important source of variation that is important to model.
There are several ways of handling seasonality. Some approaches remove the seasonal component before modeling. Seasonally-adjusted data (a time series minus the seasonal component) highlights long-term effects such as trends or business cycles. Other approaches add extra variables that capture the cyclical nature of seasonality.
Before going over different methods, let’s create a time series and describe its seasonal patterns.
Analysis example
We’ll use the same process we did in the previous article (see also reference [1]):
period = 12 # monthly series
size = 120beta1 = np.linspace(-.6, .3, num=size)
beta2 = np.linspace(.6, -.3, num=size)
sin1 = np.asarray([np.sin(2 * np.pi * i / 12) for i in np.arange(1, size + 1)])
cos1 = np.asarray([np.cos(2 * np.pi * i / 12) for i in np.arange(1, size + 1)])
xt = np.cumsum(np.random.normal(scale=0.1, size=size))
yt = xt + beta1 * sin1 + beta2 * cos1 + np.random.normal(scale=0.1, size=size)
yt = pd.Series(yt)
Here’s what this series look like:
We can start by describing the seasonal pattern by its strength:
# https://github.com/vcerqueira/blog/tree/main/src
from src.seasonality import seasonal_strengthseasonal_strength(yt, period=12)
# 0.90