8 Techniques to Model Seasonality | by Vitor Cerqueira | Jul, 2023

How to handle seasonality for forecasting

Vitor Cerqueira
Towards Data Science
Photo by Clark Young on Unsplash

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.

A time series and its seasonally-adjusted version. The data source is in the next section. Image by author.

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 = 120

beta1 = 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:

Artificial time series with a stochastic stationary seasonality. Image by author.

We can start by describing the seasonal pattern by its strength:

# https://github.com/vcerqueira/blog/tree/main/src
from src.seasonality import seasonal_strength

seasonal_strength(yt, period=12)
# 0.90

Source link

This post originally appeared on TechToday.

Leave a Reply

Your email address will not be published. Required fields are marked *