statsmodels.tsa._stl.STL“无法确定 endog 的周期”

yun*_*fei 8 python statistics statsmodels

我想通过statsmodels STL方法进行分解

我的时间序列数据如下所示:

         success.rate
Date
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
Run Code Online (Sandbox Code Playgroud)

当我把它放入STL中时

STL(sdf, seasonal=20, robust=True)
Run Code Online (Sandbox Code Playgroud)

我总是收到这样的错误:

--------------------------------------------------------------------------
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
Run Code Online (Sandbox Code Playgroud)

Kev*_*n S 9

如果您的时间序列在索引上没有已知频率(例如,sdf.index.freqis None,那么您需要使用 来设置季节性周期periodseasonal告诉 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()
res.plot()
plt.show()
Run Code Online (Sandbox Code Playgroud)

这段代码产生

STL演示