来自 GitHub 问题的this 回答,很明显您应该使用新的ETSModel 类,而不是旧的(但仍然存在以保持兼容性)ExponentialSmoothing。
ETSModel 比ExponentialSmoothing 包含更多参数和更多功能。
要计算置信区间,我建议你使用ETSResults的simulate方法:
from statsmodels.tsa.exponential_smoothing.ets import ETSModel
import pandas as pd
# Build model.
ets_model = ETSModel(
endog=y, # y should be a pd.Series
seasonal='mul',
seasonal_periods=12,
)
ets_result = ets_model.fit()
# Simulate predictions.
n_steps_prediction = y.shape[0]
n_repetitions = 500
df_simul = ets_result.simulate(
nsimulations=n_steps_prediction,
repetitions=n_repetitions,
anchor='start',
)
# Calculate confidence intervals.
upper_ci = df_simul.quantile(q=0.9, axis='columns')
lower_ci = df_simul.quantile(q=0.1, axis='columns')
基本上,调用simulate 方法你会得到一个带有n_repetitions 列和n_steps_prediction 步骤的DataFrame(在这种情况下,你的训练数据集中的相同数量的项目y)。
然后,您使用 DataFrame quantile 方法计算置信区间(请记住 axis='columns' 选项)。
您还可以从df_simul 计算其他统计信息。
我还查看了源代码:simulate 在内部被forecast 方法调用,以预测未来的步骤。因此,您还可以使用相同的方法预测未来的步骤及其置信区间:只需使用anchor='end',这样模拟将从y 的最后一步开始。
公平地说,还有一种更直接的方法来计算置信区间:get_prediction 方法(内部使用simulate)。但我不太喜欢它的界面,它对我来说不够灵活,我没有找到指定所需置信区间的方法。在我看来,simulate 方法的方法很容易理解,而且非常灵活。
如果您想了解有关如何执行此类模拟的更多详细信息,请阅读优秀的预测:原则与实践在线书籍中的this 章节。