ValueError: freq T not understood. Please report if you think this in error. (seasonal_decompose)
Asked Answered
M

2

10

I was trying out seasonal_decompose to decompose my time series. The data is perfect time series with frequency of '2T' i.e. 2 Minutes. From file tsatools.py (site-pkgs\statsmodels\tsa\tsatools.py), in line 655, I added the following. _ elif freq == 'T': return 6024752_ I added this from the following inference: Freq A means 1 year hence it returns 1. Q means quaterly and hence returns 4 M means monthly and hence returns 12 and so on. Therefore, T means per minute, hence 60247*365

When I do the above, I get following error: ValueError: Inferred frequency of index and frequency don't match. This function does not re-sample From line 70 in seasonal.py (statsmodel\tsa\seasonal.py) Because : variable freq is : <2 * Minutes> And variable pfreq is 2T 524160.

I mean seasonal decompose should be able to decompose timeseries of 1min frequency, and something seems to have changed. Please have a look at it, and let me know if I'm missing anything.

Mendive answered 18/3, 2016 at 12:1 Comment(1)
This has been fixed in statsmodels master and will be changed in the upcoming release so it will be possible to override the default period length freq.Sholokhov
C
12

I got the same problem, I think it's an internal problem since I test all the index data type. At the end, I tried this and it works.

import statsmodels.api as sm
decompfreq = 6*12
decomposition = sm.tsa.seasonal_decompose(ts3_log.values,freq=decompfreq)
trend = decomposition.trend

decompfreq is calculated based on the time window, which is 10 mins, so the freqency actually is half a day.

Hope this would help you

Cure answered 20/6, 2016 at 13:18 Comment(4)
If I understand correctly, does freq need to be the # of samples in a season? So if I had daily seasonality and my samples are every 5 minutes, then freq = ((24*60)//5)?Outright
yup, I think soCure
What is that supposed to mean? Number of samples in a season? Am I supposed to know the season/seasons beforehand?Selvage
I don't understand. Then it's simply the len of my series?Chevalier
C
3

"You need to explicitly set the period when using data that does not have an obvious seasonality." - User bashtage.

If your data is in seconds, then try:

sm.tsa.seasonal_decompose(series, period = 60*60*24) to represent a daily period.

Reference: the statsmodels.tsa.tsatools documentation for freq_to_period.

Crotchety answered 28/2, 2022 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.