7

I am wondering if Python has any implementations of Multi-Seasonal Time Series like msts method in forecast library under R.

So far, I have found only following packages for Time Series in Python:

However, none of them contains approach that I am looking for. Please advice.

SpanishBoy
  • 233
  • 2
  • 8
  • If you have two (or n) specific seasonalities you want to adjust for, you could get each of them separately from statsmodels by calling sm.decompose() twice with the two different frequency= parameters. Then you could subtract both those seasonal components from your raw signal. Does that get you what you want? If not, could you elaborate on specifically what you're trying to do? – Max Power Apr 12 '17 at 17:58

1 Answers1

4

If you have two (or n) specific seasonalities you want to adjust for, you could get each of them separately from statsmodels by calling sm.decompose() twice with the different frequency= parameters. Then you could subtract both those seasonal components from your raw signal.

For an example where you have hourly data and want to seasonally adjust for daily and weekly effects...

import statsmodels.api as sm

daily_components = sm.tsa.seasonal_decompose(raw_series, period=24)
weekly_components= sm.tsa.seasonal_decompose(raw_series, period=24*7)

adjusted = raw_series - daily_components.seasonal - weekly_components.seasonal
Simon
  • 307
  • 2
  • 10
Max Power
  • 283
  • 1
  • 10
  • 1
    An editor suggests the code should be amended to: `no_daily = raw_series - daily_components['seasonal']`, & `weekly_components= sm.decompose(no_daily, freq=24*7)`, because, "weekly_components decomposition will infer daily_components values. So their seasonal components will interfere with each other." – gung - Reinstate Monica Jun 22 '18 at 16:52
  • @gung I got this idea too. I wonder if there is a consensus on which approach is more "appropriate". – Kota Mori Jan 23 '19 at 20:58
  • @KotaMori, my comment documents an instance where someone tried to edit the answer to say what they thought it should be, rather than what the OP wrote. If you have your own question, click the `[Ask Question]` link at the top & ask it there. – gung - Reinstate Monica Jan 23 '19 at 21:03
  • 1
    not sure why is this question closed. anyway, 2 comments: note that the current statsmodels implementation is naive, and the STL implementation is yet to come (during 2020!). Also, note that the API changed a bit and now it's: `daily_components = seasonal_decompose(raw_series, freq=24)` & `no_daily = raw_series - daily_components.seasonal` – ihadanny Dec 25 '19 at 20:32