Seasonal Decompose

315 views
Skip to first unread message

Surya

unread,
Aug 2, 2017, 8:03:59 AM8/2/17
to pystatsmodels
Hi, 

I'm applying statsmodels.tsa.seasonal.seasonal_decompose on my time series. As I understand from the source, this method does the following:
  1. Calculate convolution to get trends
  2. Remove trends from series
  3. Calculate seasonal mean to get seasons
  4. Remove seasons to get residual.

1) Is there any way to use a different convolution function here?
2) How do I interpret the frequency?

Let's say I have a time series X(T), with sample frequency 1 per minute. 
I can notice seasons at 1 day periodicity. It sort of looks like | Sine | but quite lot of randomness included. 

How do I select the frequency to decompose? Is it 1 * 60 * 24 (24 hours)?  How would the decomposition behave if I use for instance 1 * 60 * 40 (40 hours)? 

When I use 40 hours, I am able to see approx. seasons in residual series as well.

Thank you for reading.


Surya

josef...@gmail.com

unread,
Aug 2, 2017, 10:44:41 AM8/2/17
to pystatsmodels
On Wed, Aug 2, 2017 at 7:48 AM, Surya <kastur...@gmail.com> wrote:
Hi, 

I'm applying statsmodels.tsa.seasonal.seasonal_decompose on my time series. As I understand from the source, this method does the following:
  1. Calculate convolution to get trends
  2. Remove trends from series
  3. Calculate seasonal mean to get seasons
  4. Remove seasons to get residual.


I'm not an expert on seasonal decomposition, and only know enough to "maintain" it.

 
1) Is there any way to use a different convolution function here?

seasonal_decompose has a filt option that can be used to replace the default kernel/window for the moving average/convolution filter for the trend..

 
2) How do I interpret the frequency?

"freq is an int that gives the number of periods per cycle" from the docstring of seasonal_mean
There is some extra code for pandas frequency which refers to kalender time periods and assumes some default frequency/length of seasonal cycle, e.g. annual with monthly or quarterly data, IIRC.


Let's say I have a time series X(T), with sample frequency 1 per minute. 
I can notice seasons at 1 day periodicity. It sort of looks like | Sine | but quite lot of randomness included. 

How do I select the frequency to decompose? Is it 1 * 60 * 24 (24 hours)?  How would the decomposition behave if I use for instance 1 * 60 * 40 (40 hours)? 

When I use 40 hours, I am able to see approx. seasons in residual series as well.

The seasonal component is an averagetaken over cycles of time points within a cycle. Also freq is used to determine the default length of the trend convolution filter. If the inferred or given season length (freq) does not correspond to the actual cycle length, then trend and seasonal cycle get messed up. (E.g. if there is a 7-day week with daily data and freq is 5, then Monday and Saturday would be considered to be at the same point in the cycle.


Do you have suggestion for adding options to make the filtering more flexible?

Josef 
Reply all
Reply to author
Forward
0 new messages