Seasonality Detection

Different from data points detection, seasonality detection is to find seasonality pattern in the time series. In time series decomposition, the disclosed seasonality pattern is one of the solutions. In this section, you will see more methods in displaying seasonality patterns.

Kats Seasonality Detection

Kats has 2 main seasonality detection methods. ACF (Auto Correlation Function) Detector and FFT (Fast Fourier Transform) Detector.

ACF Seasonality Detector

The data input is sales data. Kats' ACF seasonality detection is straightforward, as illustrated by the ACF plot below. Additionally, it identifies whether seasonality exists and determines the seasonality length (7 days in this example).

ACF is commonly used in ARIMA modeling to help determine parameter values. In an ACF plot, each vertical bar represents the degree of linear dependency between the ith time point and the (i+g)th time point, referred to as 'autocorrelation.' Given a confidence level (such as 95%), any autocorrelation value outside the confidence interval (indicated by the threshold lines) is considered significant.

A positive autocorrelation suggests that the values tend to move in the same direction, a negative autocorrelation implies they move in opposite directions, and a value close to 0 indicates minimal or no temporal dependency. In the plot above, we observe alternating patterns of significant positive and significant negative autocorrelation, which reveal the seasonality in the time series.

The Kats ACF detector determines the seasonality length by examining the ACF output's confidence interval list and identifying repeated cycles where the autocorrelation exceeds the confidence threshold. You can dive deeper here.

๐ŸŒป Check detailed code in Kats Seasonality Detection

FFT Seasonality Detector

FFT (Fast Fourier Transform) takes a time-based data, measures every repetitive pattern and returns the amplitude, offset and rotation speed in each repetitive sequence.

If we use sales data as an example, FFT detected seasonality pattern is shown with the purple curve below. Kats uses frequency and amplitude as the detection output. You can consider the output is like a signal wave, where the y-axis, labeled 'PSD (dB),' indicates the signal power per unit bandwidth. The x-axis represents frequency: for daily time series data, it is measured in "1/Day", and for hourly data, in "1/Hour". The detected seasonality has length as 6.98 days, quite close to the 7 days detected by ACF seasonality detector.

At the same time, you might noticed the detected outliers in the plot too, which are marked with purple dots. Outlier detection also based on FFT. It calculates an amplitude threshold using amplitude median + amplitude mean absolute deviation * mad_threshold, "mad_threshold" is a positve user assigned mean absolute deviation threshold (larger value, less sensitive to outliers). The outliers are non-harmonics data points with their amplitude passed threshold. Explore detailed logic here!

Similarly, we can plot FFT detected humiditity seasoanlity:

And FFT detected temperature seasaonlity:

๐ŸŒป Check detailed code in Kats Seasonality Detection

But do you find Kats FFT detector's plots insightful? Discuss your ideas here!

Greykite Seasonality Detection

Greykite seasonality detection provides lots of informative visualization and insights (maybe too much...). It supports different seasonality cycles, such as yearly, monthly, quarterly, weekly, daily. Within each seasonality cycle, there are different time features to explore, for example, in yearly seasonality, there is day of year seasonality, day of month seasonality, etc.

Let's take a look at sales data's yearly seasonality by day of month. There are 2 patterns shown in the following plot:

  • The peak and trough sales in 2013 and 2014 appear to be opposite to each other

  • The sales peak and trough in 2015 tends to happen earlier than same periods of 2013, 2014

Besides seeing the seasonality pattern in each year, we can also plot average sales throughout the time, as we can see below, the grey mean value changes over the time, which poses challenges to find seasaonlity changepoints.

Therefore, Greykite provides "relative offset" plot which removes the effect caused by changing mean. Look at the relative offset plot below, the 2 patterns found above became more clear, besides, we can see in 2013, 2014, between August and October, the sales fluctuations are smaller, so August and October can be considered as seasonality changepoints.

We can also explore monthly sales patterns by day of week. It seems that every month is showing similar patterns that Monday tends to have a bit higher sales while Sunday has 0 sales because all the stores are closed.

Similarly, we can plot day of week sales patterns by month, which can disclose weekly seasonality in all years. The sales patterns on Monday and Sunday are still quite different from other days of week.

But are you going to wonder whether every week in a month, we will see the same pretty patterns above? Let's look at day of week patterns by day of month. Ah! It seems that Monday doesn't lead sales every week, especailly around 10th or 20th in a month, Monday sales can be lower than other days of week.

Greykite also allows you to check seasonality patterns in customized periods. For example, Lady H. was wondering whether the new year week (between Dec. 23 and Dec. 31) has quite different sales pattern than other period. So she divided the time as new year week and other period:

Then looking at weekly seasonality in both periods, the week of new year is indeed showing quite different sales pattern that the sales during the new year tend to be much lower than other period, and when it's getting closer to Christmas, the sales is higher than other period. This do align with our common sense:

You can also randomly choose multiple periods and plot their sales patterns to get some general ideas. For example, here Lady H. chose 20 weeks sales patterns randomly, most of the weeks are showing similar patterns but the week of 2015-05-31 is a special one, its Friday sales was much lower than average while its other weekdays' sales were much higher than the average. Why this happened? In practice, this will be a good opportunity to dive deeper into the data.

๐ŸŒป Play with Greykite Seasonality Detection code to to explore more!

Have to admit, Greykite provides a flexible and powerful seasonality detection that can disclose many patterns hidden in the time series. And now, we have done all the comparisons between Kats and Greykite! ๐ŸŽ‰

Last updated