每小时时间序列预测

Hourly time series forecast

我正在学习 Udemy 的课程来学习一些时间序列预测,我正在尝试 运行 这段代码,其中包含一年的每小时数据:

from statsmodels.tsa.holtwinters import ExponentialSmoothing

model = ExponentialSmoothing(train['count'],trend='add',seasonal='add',seasonal_periods=12).fit()

但是一旦我运行这个:

predictions = model.forecast(24) 

我收到这个错误:

ValueWarning: No supported index is available. Prediction results will be given with an integer index beginning at start. ValueWarning)

这让我很难绘制数据进行比较,因为测试数据和预测之间的索引类型不匹配。

这是我创建索引的方式:

idx = pd.date_range(ts_data.index.min(), ts_data.index.max(), freq='H')
ts_data = ts_data.reindex(idx, fill_value=0)
ts_data.sort_index(inplace=True)
ts_data.head(10)

    count
date    
2018-11-19 02:00:00 70.0
2018-11-19 03:00:00 84.0
2018-11-19 04:00:00 98.0
2018-11-19 05:00:00 89.0
2018-11-19 06:00:00 87.0
2018-11-19 07:00:00 76.0
2018-11-19 08:00:00 58.0
2018-11-19 09:00:00 36.0
2018-11-19 10:00:00 38.0
2018-11-19 11:00:00 17.0

我想知道为什么预测方法没有 return 正确的索引。

您正在一个名为 ts_data 的数据帧上创建正确的索引,但您正在将您的模型拟合到另一个名为 train[= 的数据帧上17=].

尝试查看 train 数据帧的索引,看看它的格式是否正确。