入门
快速开始
分层协调的最小示例
组织成不同聚合级别结构的大量时间序列通常要求其预测遵循聚合约束,这带来了创建能够实现一致预测的新算法的挑战。
HierarchicalForecast
包提供了广泛的 Python 实现的分层预测算法集合,这些算法遵循经典的分层协调。
在本笔记本中,我们将展示如何使用 StatsForecast
库生成基础预测,以及如何使用 HierarchicalForecast
包执行分层协调。
您可以使用 CPU 或 GPU 在 Google Colab 上运行这些实验。
1. 库
2. 加载数据
在本示例中,我们将使用 TourismSmall
数据集。以下单元格获取层次结构中不同级别的时间序列,用于从底层层次结构恢复完整数据集的求和矩阵 S
,以及用 tags
表示的每个层次结构的索引。
unique_id | nsw-hol-city | nsw-hol-noncity | vic-hol-city | vic-hol-noncity | qld-hol-city | |
---|---|---|---|---|---|---|
0 | 总计 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
1 | hol | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
2 | vfr | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
3 | bus | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
4 | oth | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
5 | nsw-hol | 1.0 | 1.0 | 0.0 | 0.0 | 0.0 |
我们将数据框分为训练/测试集。
3. 基础预测
以下单元格使用 auto_arima
和 naive
模型计算每个时间序列的基础预测。请注意,Y_hat_df
包含预测结果,但它们并不一致。
4. 分层协调
以下单元格使用 HierarchicalReconciliation
类使之前的预测结果一致。用于使预测一致的方法包括
自底向上 (BottomUp)
:该方法的协调是对上层进行简单相加。自顶向下 (TopDown)
:第二种方法将基础级别预测约束到最高聚合级别的序列,然后通过使用比例将其分配到分解序列。中间向下 (MiddleOut)
:将基础预测锚定在中间级别。
5. 评估
HierarchicalForecast
包包含 evaluate
函数用于评估不同的层次结构,我们可以使用 utilsforecast 计算相对于基线模型的平均绝对误差。
AutoARIMA | AutoARIMA/自底向上 | AutoARIMA/自顶向下_方法-预测比例 | AutoARIMA/自顶向下_方法-平均比例 | AutoARIMA/中间向下_中间级别-国家/目的/州_自顶向下方法-平均比例 | ||
---|---|---|---|---|---|---|
级别 | 指标 | |||||
国家 | mse-scaled | 0.317897 | 0.367078 | 0.317897 | 0.317897 | 0.305053 |
国家/目的 | mse-scaled | 0.318950 | 0.233606 | 0.262216 | 0.320225 | 0.196062 |
国家/目的/州 | mse-scaled | 0.268057 | 0.281189 | 0.320349 | 0.511356 | 0.268057 |
国家/目的/州/城市非城市 | mse-scaled | 0.292136 | 0.292136 | 0.323261 | 0.509784 | 0.280599 |
总体 | mse-scaled | 0.308942 | 0.295690 | 0.297072 | 0.364775 | 0.255038 |
参考文献
- Orcutt, G.H., Watts, H.W., & Edwards, J.B.(1968). Data aggregation and information loss. The American Economic Review, 58 , 773(787).
- Disaggregation methods to expedite product line forecasting. Journal of Forecasting, 9 , 233–254. doi:10.1002/for.3980090304.
- An investigation of aggregate variable time series forecast strategies with specific subaggregate time series statistical correlation. Computers and Operations Research, 26 , 1133–1149. doi:10.1016/S0305-0548(99)00017-9.
- Hyndman, R.J., & Athanasopoulos, G. (2021). “Forecasting: principles and practice, 3rd edition: Chapter 11: Forecasting hierarchical and grouped series.”. OTexts: Melbourne, Australia. OTexts.com/fpp3 Accessed on July 2022.