Skip to main content

What is Hierarchical Forecasting?

Hierarchical forecasting involves generating forecasts for multiple time series that share a hierarchical structure (e.g., product demand by category, department, or region). The goal is to ensure that forecasts are coherent across each level of the hierarchy. Hierarchical forecasting can be particularly important when you need to generate forecasts at different granularities (e.g., country, state, region) and ensure they align with each other and aggregate correctly at higher levels. Using TimeGPT, you can create forecasts for multiple related time series and then apply hierarchical forecasting methods from HierarchicalForecast to reconcile those forecasts across your specified hierarchy.

Why use Hierarchical Forecasting?

  • Ensures consistency: Forecasts at lower levels add up to higher-level forecasts.
  • Improves accuracy: Reconciliation methods often yield more robust predictions.
  • Facilitates deeper insights: Understand how smaller segments contribute to overall trends.

Tutorial

Open In Colab

Step 1: Install, Import and Initialize

Start by installing the required packages.
Next, initialize the TimeGPT NixtlaClient.

Step 2: Load and Prepare Data

This tutorial uses the Australian Tourism dataset from Forecasting: Principles and Practices. The dataset contains different levels of hierarchical data, from the entire country of Australia down to individual regions.
Map of Australia color coded by state.Australia hierarchical structure.

Examples of Australia's Tourism Hierarchy and Map

The dataset provides only the lowest-level series, so higher-level series need to be aggregated explicitly. Let’s load and preprocess the dataset.
We define the dataset hierarchies explicitly. Each level in the list describes one view of the hierarchy:
Then, use aggregate from HierarchicalForecast to generate the aggregated series:
Next, create the train/test splits. Here, we use the last two years (eight quarters) of data for testing:

Step 3: Hierarchical Forecasting Using TimeGPT

Now we’ll generate base forecasts across all series using TimeGPT and then apply hierarchical reconciliation to ensure the forecasts align across each level.

Generate Base Forecasts with TimeGPT

Obtain forecasts with TimeGPT for all series in your training data.
Next, separate the generated forecasts into in-sample (historical) and out-of-sample (forecasted) periods:

Visualize TimeGPT Forecasts

Quickly visualize the forecasts for different hierarchy levels. Here, we look at the entire country, the state of Queensland, the Brisbane region, and holidays in Brisbane:
hier_plot1

Apply Hierarchical Reconciliation

We use MinTrace methods to reconcile forecasts across all levels of the hierarchy.
The S parameter was renamed to S_df in hierarchicalforecast. Make sure you are using S_df when calling reconcile.
Now, let’s plot the reconciled forecasts to ensure they make sense across the full country → state → region → purpose hierarchy:
hier_plot1

Step 4: Evaluate Forecast Accuracy

Finally, evaluate your forecast performance using RMSE for different levels of the hierarchy, from total (country) to bottom-level (region/purpose).

Conclusion

We made a small improvement in overall RMSE by reconciling the forecasts with MinTrace(ols), and made them slightly worse using MinTrace(mint_shrink), indicating that the base forecasts were relatively strong already. However, we now have coherent forecasts too - so not only did we make a (small) accuracy improvement, we also got coherency to the hierarchy as a result of our reconciliation step.

References