Reconciliation Quick Start
Minimal Example of Hierarchical Reconciliation
Large collections of time series organized into structures at different aggregation levels often require their forecasts to follow their aggregation constraints, which poses the challenge of creating novel algorithms capable of coherent forecasts.
The HierarchicalForecast
package provides a wide collection of Python
implementations of hierarchical forecasting algorithms that follow
classic hierarchical reconciliation.
In this notebook we will show how to use the StatsForecast
library to
produce base forecasts, and use HierarchicalForecast
package to
perform hierarchical reconciliation.
You can run these experiments using CPU or GPU with Google Colab.
1. Libraries
2. Load Data
In this example we will use the TourismSmall
dataset. The following
cell gets the time series for the different levels in the hierarchy, the
summing matrix S
which recovers the full dataset from the bottom level
hierarchy and the indices of each hierarchy denoted by tags
.
unique_id | ds | y | |
---|---|---|---|
0 | total | 1998-03-31 | 84503 |
1 | total | 1998-06-30 | 65312 |
2 | total | 1998-09-30 | 72753 |
3 | total | 1998-12-31 | 70880 |
4 | total | 1999-03-31 | 86893 |
nsw-hol-city | nsw-hol-noncity | vic-hol-city | vic-hol-noncity | qld-hol-city | |
---|---|---|---|---|---|
total | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
hol | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
vfr | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
bus | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
oth | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
We split the dataframe in train/test splits.
3. Base forecasts
The following cell computes the base forecast for each time series
using the auto_arima
and naive
models. Observe that Y_hat_df
contains the forecasts but they are not coherent.
4. Hierarchical reconciliation
The following cell makes the previous forecasts coherent using the
HierarchicalReconciliation
class. The used methods to make the forecasts coherent are:
BottomUp
: The reconciliation of the method is a simple addition to the upper levels.TopDown
: The second method constrains the base-level predictions to the top-most aggregate-level serie and then distributes it to the disaggregate series through the use of proportions.MiddleOut
: Anchors the base predictions in a middle level.
5. Evaluation
The HierarchicalForecast
package includes the
HierarchicalEvaluation
class to evaluate the different hierarchies and also is capable of
compute scaled metrics compared to a benchmark model.
level | Overall | Country | Country/Purpose | Country/Purpose/State | Country/Purpose/State/CityNonCity |
---|---|---|---|---|---|
metric | mse-scaled | mse-scaled | mse-scaled | mse-scaled | mse-scaled |
AutoARIMA | 0.168957 | 0.132836 | 0.193802 | 0.182351 | 0.199594 |
AutoARIMA/BottomUp | 0.100188 | 0.08518 | 0.077097 | 0.155771 | 0.199594 |
AutoARIMA/TopDown_method-forecast_proportions | 0.144239 | 0.132836 | 0.11976 | 0.204426 | 0.227395 |
AutoARIMA/MiddleOut_middle_level-Country/Purpose/State_top_down_method-forecast_proportions | 0.134219 | 0.145776 | 0.091276 | 0.182351 | 0.215141 |
References
- 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.