如何解决Python:在 statsmodel 的 holtwinters 函数中执行 forcast() 时出现 KeyError
我正在尝试使用以下代码进行时间序列预测。
from statsmodels.tsa.holtwinters import ExponentialSmoothing as HWES
#read the data file. the date column is expected to be in the mm-dd-yyyy format.
df_train_y = pd.DataFrame(data = tsne_train_output)
df_train_y.index.freq = 'd'
df_test_y = pd.DataFrame(data = tsne_test_output)
df_test_y.index.freq = 'd'
#plot the data
df_train_y.plot()
plt.show()
#build and train the model on the training data
model = HWES(df_train_y,seasonal_periods=144,trend='add',seasonal='add')
fitted = model.fit(optimized=True,use_brute=True)
#print out the training summary
print(fitted.summary())
#create an out of sample forcast for the next 12 steps beyond the final data point in the training data set
trend_forecast = fitted.forecast(steps= 157200)
我的数据如下所示:
df_train_y >>
y_train
0 0
1 0
2 0
3 0
4 0
... ...
366755 65
366756 66
366757 63
366758 65
366759 68
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-137-66fe58a542ec> in <module>()
23
24 #create an out of sample forcast for the next 12 steps beyond the final data point in the training data set
---> 25 trend_forecast = fitted.forecast(steps= '157200')
1 frames
/usr/local/lib/python3.7/dist-packages/statsmodels/tsa/holtwinters.py in forecast(self,steps)
344 try:
345 freq = getattr(self.model._index,'freq',1)
--> 346 start = self.model._index[-1] + freq
347 end = self.model._index[-1] + steps * freq
348 return self.model.predict(self.params,start=start,end=end)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
所以我尝试检查第 346 行中操作数的类型,
运行 type(fitted.model._index[-1])
后,我得到 int
;我还通过使用 holtwinters.py
将所有操作数类型转换为 int
来编辑 int()
中的代码,但错误仍然存在。
我已在 statsmodels here 的 github 存储库中报告了此问题。 并在 datascience stackexchange 中问了同样的问题,但一无所获。 DS Stackexchange question link
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。