HierarchicalForecast package provides the most comprehensive
collection of Python implementations of hierarchical forecasting
algorithms that follow classic hierarchical reconciliation. All the
methods have a reconcile function capable of reconciling base
forecasts using numpy arrays.
Cross-sectional hierarchies
Traditionally, hierarchical forecasting methods reconcile cross-sectional aggregations. For example, we may have forecasts for individual product demand, but also for the overall product group, department and store, and we are interested in making sure these forecasts are coherent with each other. This can be formalized as: where denotes the matrix of forecasts for all time series for all time steps in the hierarchy, is a matrix that defines the hierarchical relationship between the bottom-level time series and the aggregations, is a matrix that encapsulates the contribution of each forecast to the final estimate, and is the matrix of reconciled forecasts. We can use the matrix to define various forecast contribution scenarios. Cross-sectional reconciliation methods aim to find the optimal matrix.Temporal hierarchies
We can also perform temporal reconciliation. For example, we may have forecasts for daily demand, weekly, and monthly, and we are interested in making sure these forecasts are coherent with each other. We formalize the temporal hierarchical forecasting problem as: where is a matrix that defines the hierarchical relationship between the bottom-level time steps and the aggregations and is a matrix that encapsulates the contribution of each forecast to the final estimate. We can use the matrix to define various forecast contribution scenarios. Temporal reconciliation methods aim to find the optimal matrix.Cross-temporal reconciliation
We can combine cross-sectional and temporal hierarchical forecasting by performing cross-sectional reconciliation and temporal reconciliation in a two-step procedure.References
-Hyndman, Rob. Notation for forecast reconciliation.1. Bottom-Up
BottomUp
Bases: HReconciler
Bottom Up Reconciliation Class.
The most basic hierarchical reconciliation is performed using an Bottom-Up strategy. It was proposed for
the first time by Orcutt in 1968.
The corresponding hierarchical “projection” matrix is defined as:
References:
BottomUp.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | required |
y_insample | Optional[ndarray] | In-sample values of size (base, horizon). Default is None. | None |
y_hat_insample | Optional[ndarray] | In-sample forecast values of size (base, horizon). Default is None. | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | Optional[int] | Seed for reproducibility. Default is None. | None |
tags | Optional[dict[str, ndarray]] | Tags for hierarchical structure. Default is None. | None |
| Name | Type | Description |
|---|---|---|
BottomUp | object | fitted reconciler. |
BottomUp.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
BottomUp.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | required |
y_insample | Optional[ndarray] | In-sample values of size (base, insample_size). Default is None. | None |
y_hat_insample | Optional[ndarray] | In-sample forecast values of size (base, insample_size). Default is None. | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. Default is None. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | Optional[int] | Seed for reproducibility. Default is None. | None |
tags | Optional[dict[str, ndarray]] | Tags for hierarchical structure. Default is None. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated y_hat using the Bottom Up approach. |
BottomUp.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
BottomUpSparse
Bases: BottomUp
BottomUpSparse Reconciliation Class.
This is the implementation of a Bottom Up reconciliation using the sparse
matrix approach. It works much more efficient on datasets with many time series.
[makoren: At least I hope so, I only checked up until ~20k time series, and
there’s no real improvement, it would be great to check for smth like 1M time
series, where the dense S matrix really stops fitting in memory]
See the parent class for more details.
BottomUpSparse.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | required |
y_insample | Optional[ndarray] | In-sample values of size (base, horizon). Default is None. | None |
y_hat_insample | Optional[ndarray] | In-sample forecast values of size (base, horizon). Default is None. | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | Optional[int] | Seed for reproducibility. Default is None. | None |
tags | Optional[dict[str, ndarray]] | Tags for hierarchical structure. Default is None. | None |
| Name | Type | Description |
|---|---|---|
BottomUp | object | fitted reconciler. |
BottomUpSparse.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
BottomUpSparse.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | required |
y_insample | Optional[ndarray] | In-sample values of size (base, insample_size). Default is None. | None |
y_hat_insample | Optional[ndarray] | In-sample forecast values of size (base, insample_size). Default is None. | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. Default is None. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | Optional[int] | Seed for reproducibility. Default is None. | None |
tags | Optional[dict[str, ndarray]] | Tags for hierarchical structure. Default is None. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated y_hat using the Bottom Up approach. |
BottomUpSparse.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
2. Top-Down
TopDown
HReconciler
Top Down Reconciliation Class.
The Top Down hierarchical reconciliation method, distributes the total aggregate predictions and decomposes
it down the hierarchy using proportions that can be actual historical values
or estimated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method | str | One of forecast_proportions, average_proportions and proportion_averages. | required |
- CW. Gross (1990). “Disaggregation methods to expedite product line forecasting”. Journal of Forecasting, 9 , 233-254. doi:10.1002/for.3980090304.
- G. Fliedner (1999). “An investigation of aggregate variable time series forecast strategies with specific subaggregate time series statistical correlation”. Computers and Operations Research, 26 , 1133-1149. doi:10.1016/S0305-0548(99)00017-9.
TopDown.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
y_insample | ndarray | Insample values of size (base, insample_size). Optional for forecast_proportions method. | required |
y_hat_insample | ndarray | Insample forecast values of size (base, insample_size). Optional for forecast_proportions method. | None |
sigmah | ndarray | Estimated standard deviation of the conditional marginal distribution. | None |
interval_method | str | Sampler for prediction intervals, one of normality, bootstrap, permbu. | required |
num_samples | int | Number of samples for probabilistic coherent distribution. | None |
seed | int | Seed for reproducibility. | None |
tags | dict[str, ndarray] | Each key is a level and each value its S indices. | None |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
TopDown | object | fitted reconciler. |
TopDown.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
TopDown.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
tags | dict[str, ndarray] | Each key is a level and each value its S indices. | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). Default is None. | None |
y_insample | ndarray | Insample values of size (base, insample_size). Optional for forecast_proportions method. Default is None. | None |
y_hat_insample | ndarray | Insample forecast values of size (base, insample_size). Optional for forecast_proportions method. Default is None. | None |
sigmah | ndarray | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
level | list[int] | float list 0-100, confidence levels for prediction intervals. Default is None. | None |
intervals_method | str | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | int | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | int | Seed for reproducibility. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | ndarray | Reconciliated y_hat using the Top Down approach. |
TopDown.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
TopDownSparse
Bases: TopDown
TopDownSparse Reconciliation Class.
This is an implementation of top-down reconciliation using the sparse matrix
approach. It works much more efficiently on data sets with many time series.
See the parent class for more details.
TopDownSparse.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
y_insample | ndarray | Insample values of size (base, insample_size). Optional for forecast_proportions method. | required |
y_hat_insample | ndarray | Insample forecast values of size (base, insample_size). Optional for forecast_proportions method. | None |
sigmah | ndarray | Estimated standard deviation of the conditional marginal distribution. | None |
interval_method | str | Sampler for prediction intervals, one of normality, bootstrap, permbu. | required |
num_samples | int | Number of samples for probabilistic coherent distribution. | None |
seed | int | Seed for reproducibility. | None |
tags | dict[str, ndarray] | Each key is a level and each value its S indices. | None |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
TopDown | object | fitted reconciler. |
TopDownSparse.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
TopDownSparse.fit_predict
TopDownSparse.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
3. Middle-Out
MiddleOut
HReconciler
Middle Out Reconciliation Class.
This method is only available for strictly hierarchical structures. It anchors the base predictions
in a middle level. The levels above the base predictions use the Bottom-Up approach, while the levels
below use a Top-Down.
Parameters:
References:
MiddleOut.fit
MiddleOut.predict
MiddleOut.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
tags | dict[str, ndarray] | Each key is a level and each value its S indices. | required |
y_insample | ndarray | Insample values of size (base, insample_size). Only used for forecast_proportions. Default is None. | None |
y_hat_insample | ndarray | In-sample forecast values of size (base, insample_size). Only used for forecast_proportions. Default is None. | None |
sigmah | ndarray | Estimated standard deviation of the conditional marginal distribution. Default is None. | None |
level | list[int] | Confidence levels for prediction intervals. Default is None. | None |
intervals_method | str | Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None. | None |
num_samples | int | Number of samples for probabilistic coherent distribution. Default is None. | None |
seed | int | Seed for reproducibility. Default is None. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | Reconciliated y_hat using the Middle Out approach. |
MiddleOut.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
MiddleOutSparse
Bases: MiddleOut
MiddleOutSparse Reconciliation Class.
This is an implementation of middle-out reconciliation using the sparse matrix
approach. It works much more efficiently on data sets with many time series.
See the parent class for more details.
MiddleOutSparse.fit
MiddleOutSparse.predict
MiddleOutSparse.fit_predict
MiddleOutSparse.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
4. Min-Trace
MinTrace
HReconciler
MinTrace Reconciliation Class.
This reconciliation algorithm proposed by Wickramasuriya et al. depends on a generalized least squares estimator
and an estimator of the covariance matrix of the coherency errors . The Min Trace algorithm
minimizes the squared errors for the coherent forecasts under an unbiasedness assumption; the solution has a
closed form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method | str | One of ols, wls_struct, wls_var, mint_shrink, mint_cov. | required |
nonnegative | bool | Reconciled forecasts should be nonnegative? | False |
mint_shr_ridge | float | Ridge numeric protection to MinTrace-shr covariance estimator. | 2e-08 |
num_threads | int | Number of threads to use for solving the optimization problems (when nonnegative=True). | 1 |
- Wickramasuriya, S. L., Athanasopoulos, G., & Hyndman, R. J. (2019). “Optimal forecast reconciliation for hierarchical and grouped time series through trace minimization”. Journal of the American Statistical Association, 114 , 804-819. doi:10.1080/01621459.2018.1448825..
- Wickramasuriya, S.L., Turlach, B.A. & Hyndman, R.J. (2020). “Optimal non-negative forecast reconciliation”. Stat Comput 30, 1167-1182. https://doi.org/10.1007/s11222-020-09930-0.
MinTrace.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | Summing matrix of size (base, bottom). | required | |
y_hat | Forecast values of size (base, horizon). | required | |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”. | None |
y_hat_insample | Optional[ndarray] | Insample forecast values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink” | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
idx_bottom | Optional[ndarray] | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
self | object, fitted reconciler. |
MinTrace.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
MinTrace.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
y_hat_insample | Optional[ndarray] | Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | Reconciliated y_hat using the MinTrace approach. |
MinTrace.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
MinTraceSparse
MinTrace
MinTraceSparse Reconciliation Class.
This is the implementation of OLS and WLS estimators using sparse matrices. It is not guaranteed
to give identical results to the non-sparse version, but works much more efficiently on data sets
with many time series.
See the parent class for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method | str | One of ols, wls_struct, or wls_var. | required |
nonnegative | bool | Return non-negative reconciled forecasts. | False |
num_threads | int | Number of threads to execute non-negative quadratic programming calls. | 1 |
qp | bool | Implement non-negativity constraint with a quadratic programming approach. Setting | True |
MinTraceSparse.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | csr_matrix | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used with “wls_var”. | None |
y_hat_insample | Optional[ndarray] | Insample forecast values of size (base, insample_size). Only used with “wls_var” | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
idx_bottom | Optional[ndarray] | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
self | MinTraceSparse | object, fitted reconciler. |
MinTraceSparse.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
MinTraceSparse.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
y_hat_insample | Optional[ndarray] | Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | Reconciliated y_hat using the MinTrace approach. |
MinTraceSparse.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
5. Optimal Combination
OptimalCombination
MinTrace
Optimal Combination Reconciliation Class.
This reconciliation algorithm was proposed by Hyndman et al. 2011, the method uses generalized least squares
estimator using the coherency errors covariance matrix. Consider the covariance of the base forecast
, the matrix of this method is defined by:
where denotes the variance pseudo-inverse. The method was later proven equivalent to
MinTrace variants.
Parameters:
OptimalCombination.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | Summing matrix of size (base, bottom). | required | |
y_hat | Forecast values of size (base, horizon). | required | |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”. | None |
y_hat_insample | Optional[ndarray] | Insample forecast values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink” | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
idx_bottom | Optional[ndarray] | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
self | object, fitted reconciler. |
OptimalCombination.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
OptimalCombination.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
y_insample | Optional[ndarray] | Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
y_hat_insample | Optional[ndarray] | Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrink | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | Reconciliated y_hat using the MinTrace approach. |
OptimalCombination.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
6. Emp. Risk Minimization
ERM
HReconciler
Empirical Risk Minimization Reconciliation Class.
The Empirical Risk Minimization reconciliation strategy relaxes the unbiasedness assumptions from
previous reconciliation methods like MinT and optimizes square errors between the reconciled predictions
and the validation data to obtain an optimal reconciliation matrix P.
The exact solution for (method='closed') follows the expression:
The alternative Lasso regularized solution (method='reg_bu') is useful when the observations
of validation data is limited or the exact solution has low numerical stability.
Parameters:
ERM.fit
| Name | Type | Description | Default |
|---|---|---|---|
S | Summing matrix of size (base, bottom). | required | |
y_hat | Forecast values of size (base, horizon). | required | |
y_insample | Train values of size (base, insample_size). | required | |
y_hat_insample | Insample train predictions of size (base, insample_size). | required | |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
idx_bottom | Optional[ndarray] | Indices corresponding to the bottom level of S, size (bottom). | None |
| Name | Type | Description |
|---|---|---|
self | object, fitted reconciler. |
ERM.predict
Returns:
| Name | Type | Description |
|---|---|---|
y_tilde | dict | Reconciliated predictions. |
ERM.fit_predict
| Name | Type | Description | Default |
|---|---|---|---|
S | ndarray | Summing matrix of size (base, bottom). | required |
y_hat | ndarray | Forecast values of size (base, horizon). | required |
idx_bottom | ndarray | Indices corresponding to the bottom level of S, size (bottom). | None |
y_insample | Optional[ndarray] | Train values of size (base, insample_size). | None |
y_hat_insample | Optional[ndarray] | Insample train predictions of size (base, insample_size). | None |
sigmah | Optional[ndarray] | Estimated standard deviation of the conditional marginal distribution. | None |
level | Optional[list[int]] | float list 0-100, confidence levels for prediction intervals. | None |
intervals_method | Optional[str] | Sampler for prediction intervals, one of normality, bootstrap, permbu. | None |
num_samples | Optional[int] | Number of samples for probabilistic coherent distribution. | None |
seed | Optional[int] | Seed for reproducibility. | None |
tags | Optional[dict[str, ndarray]] | Each key is a level and each value its S indices. | None |
| Name | Type | Description |
|---|---|---|
y_tilde | Reconciliated y_hat using the ERM approach. |
ERM.sample
intervals_method selected during the reconciler’s
instantiation. Currently available: normality, bootstrap, permbu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples | int | number of samples generated from coherent distribution. | required |
| Name | Type | Description |
|---|---|---|
samples | ndarray | Coherent samples of size (num_series, horizon, num_samples). |
References
General Reconciliation
- Orcutt, G.H., Watts, H.W., & Edwards, J.B.(1968). Data aggregation and information loss. The American Economic Review, 58 , 773(787).
- Disaggregation methods to expedite product line forecasting. Journal of Forecasting, 9 , 233–254. doi:10.1002/for.3980090304.
- An investigation of aggregate variable time series forecast strategies with specific subaggregate time series statistical correlation. Computers and Operations Research, 26 , 1133–1149. doi:10.1016/S0305-0548(99)00017-9.
- Hyndman, R.J., & Athanasopoulos, G. (2021). “Forecasting: principles and practice, 3rd edition: Chapter 11: Forecasting hierarchical and grouped series.”. OTexts: Melbourne, Australia. OTexts.com/fpp3 Accessed on July 2022.
- Rob J. Hyndman, Roman A. Ahmed, George Athanasopoulos, Han Lin Shang. “Optimal Combination Forecasts for Hierarchical Time Series” (2010).
- Shanika L. Wickramasuriya, George Athanasopoulos and Rob J. Hyndman. “Optimal Combination Forecasts for Hierarchical Time Series” (2010).
- Ben Taieb, S., & Koo, B. (2019). Regularized regression for hierarchical forecasting without unbiasedness conditions. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining KDD ’19 (p. 1337-1347). New York, NY, USA: Association for Computing Machinery.
Hierarchical Probabilistic Coherent Predictions
- Puwasala Gamakumara Ph. D. dissertation. Monash University, Econometrics and Business Statistics. “Probabilistic Forecast Reconciliation”.
- Taieb, Souhaib Ben and Taylor, James W and Hyndman, Rob J. (2017). Coherent probabilistic forecasts for hierarchical time series. International conference on machine learning ICML.

