Solved – Seasonal Decomposition

seasonalitytime series

I am having a time series which shows some kind of periodic behavior looking at the plot. In order to get this seasonal component I am using the rolling mean and use seasonal_decompose of the statsmodels Python library.

sig = df_sensors['S1'].rolling(window=100).mean()[2000:4000].values
decomposed = sm.tsa.seasonal_decompose(sig, freq=4)

As you can see, I am assuming a frequency (freq) of the series of 4 Hz. I am doing this because the FFT of the original data of df_sensors['S1'] shows the following:

enter image description here

So it appears that there are 2 major components. One which is at ~4 Hz and another which is at ~ 175 Hz.

Plotting the result of the decomposition:

decomposed.plot()

shows the following:

enter image description here

As you can see, it is not able to find the actual seasonal part of the signal. You can also see rather long seasons of 4 Hz and the rather fast seasons of 175 Hz in the original signal.

I would like to understand why there was not seasonal component extracted. To the naked eye the behavior looks very seasonal – although there are irregularities.

In the end I would like to try and predict the seasonal behavior but I am a bit stuck here.

Any help would be appreciated and please let me know if you need more information.

Best Answer

As far as I understand, seasonality is detected but since you had freq set to such a low value (4), the plot fluctuates and covers the whole graph.

I would recommend changing the freq parameter - which should be set as follows: if you assume that some periodic activity is happening every e.g. 24 hours and your measurements are every 10 mins, decomposition_frequency = (60 / 10) * 24, where 60 / 10 = 6 - meaning you have 6 10mins intervals in an hour, and then you multiply it by 24 to make an hour a day.

In your case, if you would like to capture those fluctuations that happen every 500 steps, you could set freq to 500 and see what you get.