相关文章推荐
个性的啄木鸟  ·  将Shiny ...·  1 年前    · 
冲动的火车  ·  jQuery trim() method ...·  1 年前    · 

statsmodels.tsa._stl.STL "无法从endog确定周期"

3 人关注

我想通过statsmodels STL方法得到分解。

我的时间序列数据看起来像下面这样。

         success.rate
2020-09-11  24.735701
2020-09-14  24.616301
2020-09-15  24.695900
2020-09-16  24.467051
2020-09-17  24.118799

when I put it into STL like

STL(sdf, seasonal=20, robust=True)

我总是得到这样的错误。

--------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/mnt/d/mywork/test
 STL(sdf,seasonal=20, robust=True)
----> 1 STL(sdf, seasonal=20, robust=True)
statsmodels/tsa/_stl.pyx in statsmodels.tsa._stl.STL.__init__()
ValueError: Unable to determine period from endog
    
python
statistics
statsmodels
yunfei
yunfei
发布于 2021-06-23
1 个回答
Kevin S
Kevin S
发布于 2021-06-29
已采纳
0 人赞同

如果你的时间序列在指数上没有一个已知的频率(例如, sdf.index.freq None ,那么你需要用 period 来设置季节性的周期。 seasonal 告诉STL在季节性LOWESS中使用多少个完整的季节,但并没有告诉STL一个完整的时期需要多少个观测值。

from statsmodels.datasets import co2
from statsmodels.tsa.seasonal import STL
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
data = co2.load(True).data
data = data.resample('M').mean().ffill()
# Remove freq info
data.index = [i for i in range(data.shape[0])]
res = STL(data, period=12).fit()