【问题标题】:Prediction of Holt-Winters Forecasting Algorithm failsHolt-Winters 预测算法的预测失败
【发布时间】:2019-04-30 15:31:33
【问题描述】:

我尝试使用 Holt-Winters 算法预测时间序列。问题是,输出完全错误(此设置中的直线)。

我使用 statsmodels 实现,但不确定“seasonal_periods”参数。起初我尝试了 60*24,因为数据的频率为一分钟,季节性为一天。但是几分钟后我停止了算法,因为我认为运行时间不应该那么长。将参数设置为 365(每年的天数),我得到下图所示的结果。即使使用这个较慢的值,运行时间也是 5-10 分钟。这对于 Holt-Winters 算法来说是常见的吗?

这是我的代码:

model = ExponentialSmoothing(train_forecast_data_df, seasonal='mul', seasonal_periods=365).fit()
pred = model.predict(start=test_forecast_data_df.index.min(), end=test_forecast_data_df.index.max())

fig, ax = plt.subplots(1, 1, figsize=(16, 4))
ax.plot(train_forecast_data_df.index, train_forecast_data_df, label='Train')
ax.plot(pred.index, pred, label='Holt-Winters', alpha=0.7, c='r', linestyle='-')
ax.plot(test_forecast_data_df.index, test_forecast_data_df, label='Test', alpha=0.7)

ax.legend(loc='best')

这里是结果。蓝色是训练数据,橙色是测试数据,红色是预测。

我希望有人可以帮助我。

【问题讨论】:

    标签: python time-series statsmodels forecasting holtwinters


    【解决方案1】:

    根据我在您的情节中看到的情况,您只有五天的数据。如果您正在寻找每日季节性,您可以使用seasonal_periods= # of samples you have per day。这将是您对 1440 的第一个猜测。

    我的数据包含 34951 个样本,我的代码如下(不幸的是,是的,运行大约需要一个小时)。
    m_h = 8760 fit_yvth = ExponentialSmoothing((yv_trainh),seasonal_periods=m_h,trend='add',seasonal='mul',damped=True).fit() yv_hath = fit_yvth.forecast(len(yv_th))

    您可以做的另一件事是重新采样数据以减少处理速度。我使用了 4 年的分钟数据。每小时的数据需要一个小时左右才能完成,每天的数据需要不到一分钟的时间来运行。 (将我的数据的seasonal_periods 减少到m_d = 365 和1457 个样本)

    使用:train_h = train.resample('H').mean().bfill()

    如果您不想直接进入小时,您可以重新采样较小的块,例如 5 分钟将被重新采样,如下所示。

    train_5m = train.resample('5M').mean().bfill()

    Below is the output after letting the code do it's thing.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2011-08-17
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      相关资源
      最近更新 更多