问题描述
我正在尝试使用以下代码进行时间序列预测。
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 (将#修改为@)