HierarchicalForecast package provides a wide collection of Python
implementations of hierarchical forecasting algorithms that follow
nonnegative hierarchical reconciliation.
In this notebook, we will show how to use the HierarchicalForecast
package to perform nonnegative reconciliation of forecasts on Wiki2
dataset.
You can run these experiments using CPU or GPU with Google Colab.
1. Load Data
In this example we will use theWiki2 dataset. The following cell gets
the time series for the different levels in the hierarchy, the summing
dataframe S_df which recovers the full dataset from the bottom level
hierarchy and the indices of each hierarchy denoted by tags.
2. Base Forecasts
The following cell computes the base forecast for each time series using theAutoETS model. Observe that Y_hat_df contains the
forecasts but they are not coherent.
AutoETS model computes negative forecasts for some
series.
3. Non-Negative Reconciliation
The following cell makes the previous forecasts coherent and nonnegative using theHierarchicalReconciliation class.
The free reconciliation method gets negative forecasts.
4. Evaluation
TheHierarchicalForecast package includes the evaluate function to
evaluate the different hierarchies. We use utilsforecast to compute
the mean absolute error.
Observe that the nonnegative reconciliation method performs better
(lower error) than its unconstrained counterpart.
References
- 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.
- Wickramasuriya, S. L., Athanasopoulos, G., & Hyndman, R. J. (2019). “Optimal forecast reconciliation for hierarchical and grouped time series through trace minimization”. Journal of the American Statistical Association, 114 , 804–819. doi:10.1080/01621459.2018.1448825..
- Wickramasuriya, S.L., Turlach, B.A. & Hyndman, R.J. (2020). “Optimal non-negative forecast reconciliation”. Stat Comput 30, 1167–1182, https://doi.org/10.1007/s11222-020-09930-0.

