HierarchicalForecast contains pure Python implementations of hierarchical reconciliation methods as well as a
core.HierarchicalReconciliation wrapper class that enables easy
interaction with these methods through pandas DataFrames containing the
hierarchical time series and the base predictions.
The core.HierarchicalReconciliation reconciliation class operates with
the hierarchical time series pd.DataFrame Y_df, the base predictions
pd.DataFrame Y_hat_df, the aggregation constraints matrix S_df. For
more information on the creation of aggregation constraints matrix see
the utils aggregation
method
HierarchicalReconciliation
core.HierarchicalReconciliation class allows you to efficiently fit multiple
HierarchicaForecast methods for a collection of time series and base predictions stored in
pandas DataFrames. The Y_df dataframe identifies series and datestamps with the unique_id and ds columns while the
y column denotes the target time series variable. The Y_h dataframe stores the base predictions,
example (AutoARIMA, ETS, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- reconcilers | list[HReconciler] | A list of instantiated classes of the reconciliation methods module. | required |
HierarchicalReconciliation.reconcile
reconcile method is analogous to SKLearn fit_predict method, it
applies different reconciliation techniques instantiated in the reconcilers list.
Most reconciliation methods can be described by the following convenient
linear algebra notation:
where represent the aggregate and bottom levels, contains
the hierarchical aggregation constraints, and varies across
reconciliation methods. The reconciled predictions are
and the base predictions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y_hat_df | Frame | DataFrame, base forecasts with columns [‘unique_id’, ‘ds’] and models to reconcile. | required |
tags | dict[str, ndarray] | Each key is a level and its value contains tags associated to that level. | required |
S_df | Frame | DataFrame with summing matrix of size (base, bottom), see aggregate method. Default is None. | None |
Y_df | Optional[Frame] | DataFrame, training set of base time series with columns ['unique_id', 'ds', 'y']. If a class of self.reconciles receives y_hat_insample, Y_df must include them as columns. Default is None. | None |
level | Optional[list[int]] | positive float list [0,100), confidence levels for prediction intervals. Default is None. | None |
intervals_method | str | method used to calculate prediction intervals, one of normality, bootstrap, permbu. Default is “normality”. | ‘normality’ |
num_samples | int | if positive return that many probabilistic coherent samples. Default is -1. | -1 |
seed | int | random seed for numpy generator’s replicability. Default is 0. | 0 |
is_balanced | bool | wether Y_df is balanced, set it to True to speed things up if Y_df is balanced. Default is False. | False |
id_col | str | column that identifies each serie. Default is “unique_id”. | ‘unique_id’ |
time_col | str | column that identifies each timestep, its values can be timestamps or integers. Default is “ds”. | ‘ds’ |
target_col | str | column that contains the target. Default is “y”. | ‘y’ |
diagnostics | bool | if True, compute coherence diagnostics and store in self.diagnostics. Default is False. | False |
diagnostics_atol | float | absolute tolerance for numerical coherence check. Default is 1e-6. | 1e-06 |
| Type | Description |
|---|---|
FrameT | DataFrame, with reconciled predictions. |
HierarchicalReconciliation.bootstrap_reconcile
reconcile method
for the different reconciliation techniques instantiated in the reconcilers list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y_hat_df | Frame | DataFrame, base forecasts with columns [‘unique_id’, ‘ds’] and models to reconcile. | required |
S_df | Frame | DataFrame with summing matrix of size (base, bottom), see aggregate method. | required |
tags | dict[str, ndarray] | Each key is a level and its value contains tags associated to that level. | required |
Y_df | Optional[Frame] | DataFrame, training set of base time series with columns ['unique_id', 'ds', 'y']. If a class of self.reconciles receives y_hat_insample, Y_df must include them as columns. Default is None. | None |
level | Optional[list[int]] | positive float list [0,100), confidence levels for prediction intervals. Default is None. | None |
intervals_method | str | method used to calculate prediction intervals, one of normality, bootstrap, permbu. Default is “normality”. | ‘normality’ |
num_samples | int | if positive return that many probabilistic coherent samples. Default is -1. | -1 |
num_seeds | int | random seed for numpy generator’s replicability. Default is 1. | 1 |
id_col | str | column that identifies each serie. Default is “unique_id”. | ‘unique_id’ |
time_col | str | column that identifies each timestep, its values can be timestamps or integers. Default is “ds”. | ‘ds’ |
target_col | str | column that contains the target. Default is “y”. | ‘y’ |
| Type | Description |
|---|---|
FrameT | DataFrame, with bootstraped reconciled predictions. |

