season_decompose:操作数不能与序列中的形状一起广播 [英] 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.
一个简单的系列:
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()
我不断得到:ValueError: operands could not be broadcast together with shapes (12,) (14,)
我已经尝试了几乎所有内容,仅传递了logdf.values,传递了非日志系列.它不起作用. numpy和statsmodel版本:
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
推荐答案
正如@yoonforh所指出的,在我的案例中,这是通过将freq
参数设置为小于时间序列长度来解决的.例如.如果您的时间序列ts
看起来像这样:
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
形状是
(12,)
因此这将导致上述错误:
so this will give the error as per above:
seasonal_decompose(ts, freq=12, model='additive')
但是如果我尝试freq=11
或其他任何小于12的int
,例如
but if I try freq=11
or any other int
less than 12, e.g.
seasonal_decompose(ts, freq=11, model='additive')
这有效
这篇关于season_decompose:操作数不能与序列中的形状一起广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!