微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python:在 statsmodel 的 holtwinters 函数中执行 forcast() 时出现 KeyError

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?