Hello everyone, could anyone provide working docum...
# mlforecast
s
Hello everyone, could anyone provide working documents on incorporating exogenous variables in hierarchical forecasting? Alternatively, any key points or guidance on how to work with them would also be appreciated.
m
Hi @Sai krishna Sirikonda 👋, Great question! The
HierarchicalForecast
library is primarily designed for *forecast reconciliation*—ensuring coherence across different levels of a hierarchy—rather than generating forecasts itself. To incorporate exogenous variables in hierarchical forecasting, here’s a step-by-step guide: Step-by-Step Guide 1. Prepare Your Data using `HierarchicalForecast`:
Copy code
hierarchy_levels = [['top_level'],
                    ['top_level', 'middle_level'],
                    ['top_level', 'middle_level', 'bottom_level']]
Y_hier_df, S_df, tags = aggregate(df=bottom_df, spec=hierarchy_levels)
•
Y_hier_df
: DataFrame with your time series at all hierarchical levels. •
S_df
: Structural matrix encoding the aggregation constraints. •
tags
: Dictionary identifying the hierarchy levels of each series. 2. Generate Base Forecasts: Use any model that supports exogenous variables. Options include: • StatsForecast: e.g.,
AutoARIMA
• MLForecast: e.g.,
LightGBM
• NeuralForecast: e.g.,
NBEATSx
Make sure to include exogenous features (
X_df
) aligned with your target series. 3. Reconcile Forecasts: Use a reconciliation method from
HierarchicalForecast
, such as: •
bottom_up
•
top_down
•
min_trace
This ensures that forecasts across all levels of the hierarchy are coherent. Helpful Resources • HierarchicalForecast Tutorial • https://nixtlaverse.nixtla.io/hierarchicalforecast/examples/mlframeworksexample.html • Using Exogenous Variables ◦ StatsForecast: https://nixtlaverse.nixtla.io/statsforecast/docs/how-to-guides/exogenous.html ◦ MLForecast: https://nixtlaverse.nixtla.io/mlforecast/docs/how-to-guides/exogenous_features.html ◦ NeuralForecast: https://nixtlaverse.nixtla.io/neuralforecast/docs/capabilities/exogenous_variables.html
s
Thank you, Max 💯.