Skip to main content
Large collections of time series organized into structures at different aggregation levels often require their forecasts to follow their aggregation constraints and to be nonnegative, 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 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. Open In Colab

1. Load Data

In this example we will use the Wiki2 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.
We split the dataframe in train/test splits.

2. Base Forecasts

The following cell computes the base forecast for each time series using the AutoETS model. Observe that Y_hat_df contains the forecasts but they are not coherent.
Observe that the AutoETS model computes negative forecasts for some series.

3. Non-Negative Reconciliation

The following cell makes the previous forecasts coherent and nonnegative using the HierarchicalReconciliation class.
Observe that the nonnegative reconciliation method obtains nonnegative forecasts.
The free reconciliation method gets negative forecasts.

4. Evaluation

The HierarchicalForecast 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