Skip to main content
Geographical Hierarchical Forecasting on Australian Tourism Data using multiple models for each level in the hierarchy.
This notebook extends the classic Australian Domestic Tourism (Tourism) geographical aggregation example to showcase how HierarchicalForecast can be used to produce coherent forecasts when different forecasting models are applied at each level of the hierarchy. We will use the Tourism dataset, which contains monthly time series of the number of visitors to each state of Australia. Specifically, we will demonstrate fitting a diverse set of models across the hierarchical levels. This includes statistical models like AutoETS from StatsForecast, machine learning models such as HistGradientBoostingRegressor using MLForecast, and neural network models like NBEATS from NeuralForecast. After generating these base forecasts, we will reconcile them using BottomUp, MinTrace(mint_shrink), TopDown(forecast_proportions) reconciliators from HierarchicalForecast. You can run these experiments using CPU or GPU with Google Colab. Open In Colab

1. Load and Process Data

In this example we will use the Tourism dataset from the Forecasting: Principles and Practice book. The dataset only contains the time series at the lowest level, so we need to create the time series for all hierarchies.
The dataset can be grouped in the following hierarchical structure.
Using the aggregate function from HierarchicalForecast we can get the full set of time series.

Split Train/Test sets

We use the final two years (8 quarters) as test set.

2. Computing different models for different hierarchies

In this section, we illustrate how to fit a different type of model for each level of the hierarchy. In particular, for each level, we will fit the following models:
  • Country: AutoETS model from StatsForecast.
  • Country/State: HistGradientBoostingRegressor model from scikit-learn through the MLForecast API.
  • Country/State/Region: NBEATS model from NeuralForecast.
This fit_predict_any_models function is a helper function for training and forecasting with models from StatsForecast, MLForecast, and NeuralForecast.
We now define the models that we want to use.
We have defined a hierarchy consisting of three levels. We will use the different model types for each of the levels in the hierarchy.
To fit each model and create forecasts with it, we loop over the timeseries that are present in each level of the hierarchy, using the tags we created earlier using the aggregate function.
We have now created forecasts for different levels of the hierarchy, using different model types. Let’s look at the forecasts.
As you can see, AutoETS only has entries for the unique_id=Australia, which is because we only created forecasts for the level Country using AutoETS. Secondly, we also only have forecasts using HistGradientBoostingRegressor for timeseries in the level Country/State, again as we only created forecasts for the level Country/State using HistGradientBoostingRegressor. Finally, NBEATS shows no forecasts at all in this view, but when we look at the tail of the predictions we see that NBEATS only has forecasts for the level Country/State/Region, which was also what we intended to create.

3. Reconcile forecasts

First, we need to make sure we have one forecast column containing all the forecasts across all the levels, as we want to reconcile the forecasts across the levels. We do so by taking the mean across the forecast columns. In this case, because there’s only a single entry for each unique_id, it would be equivalent to just combine or sum the forecast columns. However, you might want to use more than one model per level in the hierarchy. In that case, you’d need to think about how to ensemble the multiple forecasts - a simple mean ensemble generally works well in those cases, so you can directly use the below code also for the more complex case where you have multiple models for each level.
As we can see, we now have a single column all_forecasts that includes the forecasts across all the levels:
We are now ready to make the forecasts coherent using the HierarchicalReconciliation class. In this example we use BottomUp, MinTrace(mint_shrink), TopDown(forecast_proportions) reconcilers.
The dataframe Y_rec_df contains the reconciled forecasts.

4. Evaluation

The HierarchicalForecast package includes an evaluate function to evaluate the different hierarchies. To evaluate models we use mase metric and compare it to base predictions.
We find that:
  • No Single Best Method: The results indicate that there is no universally superior reconciliation method. The optimal choice depends on which level of the hierarchy is most important.
  • MinTrace for Country and Country/State: The MinTrace(mint_shrink) reconciler shows best performance for the upper levels of the hierarchy, reducing the MASE from 1.59 (base forecast) to just 0.44.
  • BottomUp for Country/State/Region and Overall: The BottomUp method preserves only the NBEATS forecast of the most granular Country/State/Regions level, and aggregates those forecasts for the upper levels. It yields the best Overall MASE score.

6. Recap

This notebook demonstrated the power and flexibility of HierarchicalForecast in a multi-model forecasting scenario. In this example we fitted:
  • StatsForecast with AutoETS model for the Country level.
  • MLForecast with HistGradientBoostingRegressor model for the Country/State level.
  • NeuralForecast with NBEATS model for the Country/State/Region level.
We then combined the results into a single prediction. For the reconciliation of the forecasts, we used HierarchicalReconciliation with three different methods:
  • BottomUp
  • MinTrace(method='mint_shrink')
  • TopDown(method='forecast_proportions')
Finally, we evaluated the performance of these reconciliation methods.