Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seasonal_decompose: operands could not be broadcast together with shapes on a series

I know there are many questions on this topic, but none of them helped me to solve this problem. I'm really stuck on this.

With a simple series:

0
2016-01-31  266
2016-02-29  235
2016-03-31  347
2016-04-30  514
2016-05-31  374
2016-06-30  250
2016-07-31  441
2016-08-31  422
2016-09-30  323
2016-10-31  168
2016-11-30  496
2016-12-31  303

import statsmodels.api as sm
logdf = np.log(df[0])
decompose = sm.tsa.seasonal_decompose(logdf,freq=12, model='additive')
decomplot = decompose.plot()

i keep getting: ValueError: operands could not be broadcast together with shapes (12,) (14,)

I've tried pretty much everything, passing only logdf.values, passing a non-log series. It doesn't work. Numpy and statsmodel versions:

print(statsmodels.__version__)
print(pd.__version__)
print(np.__version__)
0.6.1
0.18.1
1.11.3
like image 609
Marco Goldin Avatar asked Feb 21 '17 10:02

Marco Goldin


1 Answers

As @yoonforh pointed, in my case this was fixed by setting the freq parameter to less than the time series length. E.g. if your time series ts looks like this:

2014-01-01    0.0
2014-02-01    0.0
2014-03-01    1.0
2014-04-01    1.0
2014-05-01    0.0
2014-06-01    1.0
2014-07-01    1.0
2014-08-01    0.0
2014-09-01    0.0
2014-10-01    1.0
2014-11-01    0.0
2014-12-01    0.0

the shape is

(12,)

so this will give the error as per above:

seasonal_decompose(ts, freq=12, model='additive')

but if I try freq=11 or any other int less than 12, e.g.

seasonal_decompose(ts, freq=11, model='additive')

this works

like image 120
tsando Avatar answered Sep 25 '22 15:09

tsando