Debasish Kanhar
Debasish Kanhar

Reputation: 1173

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

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.

Upvotes: 10

Views: 17237

Answers (2)

Justin Shenk
Justin Shenk

Reputation: 568

"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.

Upvotes: 3

Ian Zhang
Ian Zhang

Reputation: 432

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

Upvotes: 12

Related Questions