Hierarchical TimeSeries Reconciliation
Tags: Time Series Forecasting, Python, Reconciliation, Machine Learning, Hierarchical

What are hierarchical time series ?

Hierarchical time series(HTS) are a set of time series that are linked by a hierarchical structure. This means that we can represent this set of time series with a tree structure, where one node is a time series and whose leafs are time series themselves :

Hierarchical Time Series with 7 time series

We generally assume that all the time series follow the same temporality.

HTS are found in all industries, and their analysis give valuable insight regarding business /operational matters.

Supply chain: Forecasting the demand across all hierarchical levels is paramount for optimal supply anticipation and effectively managing the shortage/overstock risk. Typical example : in retail, you have time series at various hierarchical levels ( Total sales, sales per state, sales per store, sales per category of product etc.). Yield management: Having an accurate insight into the upcoming demand in service or product helps for dynamic pricing purposes. Typical examples: a hotels group would have time series predicting the attendance at various levels ( worldwide, country-wide, region-wise, hotel-wise). Operational maters: Forecasting accurately the demand across all hierarchical levels is useful for anticipating needs such as workforce and equipment. Typical example : in the transportation industry, companies such as public transport operators within a city, have to adapt the frequency of bus/train/subway according to the demand throughout all hierarchical levels (city as a whole, district, line, station).

This valuable insight can be provided with forecasting techniques, also know as time series analysis, a field that gathers statistical and machine learning models. You will find here a remarkable overview of methods for time series analysis and forecasting.

What is reconciliation ?

We are at this point : we have a set of time series linked by a hierarchical structure, and for each one of these time series we have computed a model for time series forecasting. The models do not have to be similar, each was just chosen according to the best results it yielded in forecasting the time series it is associated with. Hence, we gather forecasts that were generated independently, but we generally face the following issue : the forecasts are incoherent. This means that the sum of the forecasts of the leaves of a given node is not equal to the forecast generated by the model associated to the node.

For example, if the forecast AA + forecast AB from the example tree structure above are not equal to the forecast A, then the forecasts generated by the models are incoherent. On the one hand, it highlights the bias of our models, on the other hand, from a business perspective, this can be embarrassing : how come you predict 5 shoes sale for store A and 4 shoes sale for store B, and tell me that you forecast 10 shoes sale in total ?

We can attempt to overcome this biais by exploiting the information contained in the tree structure, and here comes the field of reconciliation.

HTS reconciliation is a field of study that aims at readjusting the forecasts yielded by independent models on a set of hierarchically-linked time series, in order to improve the forecasts and ensure that they are coherent and sum up correctly.

Reconciliation is a tool that comes after the forecasts process, and slightly modifies the output of your statistical or machine learning models.

Understanding when reconciliation intervenes. Forecast here is done for time t

Mathematical framework

Base forecasts Ỹ : The vector of forecasts yielded by the statistical/machine learning models ( step 1 in image above).

Reconciled forecasts Ŷ : The new vector of forecast after the reconciliation step.

Summing matrix S : The matrix that characterizes the hierarchical structure. Multiplying a vector of forecasts by S guarantees that the new vector of forecast is coherent.

Reconciliation matrix G : The whole reconciliation process comes down to determining the right G matrix.

Overview of methods (including state-of-the-art)

Bottom-up : This reconciliation method only sums up the bottom forecasts ( AA/AB/BA/BB) altogether in order to compute the higher levels forecasts. You will find the complete mathematical details of the method right here. Top-Down : This method uses only the time series at the top of the tree and aims at computing how to split recursively the forecast while you go downwards in the hierarchy. You will find the complete mathematical details of the method right here. Middle-out : This method combines both Bottom-up and Top-Down approaches in order. You will find the complete mathematical details of the method right here. MinT methods : These are a set of methods that were developed in in the years 2018–2020. Assuming that our base forecasts are unbiaised, this paper proved that in order to minimize the variance of the error of our reconciled forecasts (and hence recover better forecasts), the matrix G must be the following :

Where W is the covariance matrix of the error of the bases forecasts. Having said that, estimating the matrix W is quite demanding. Hence, various approximations exist : OLS / Structural Scaling / Variance Scaling / MinTSample / MinTShrink

You can find the mathematical details of these methods right here.

At that point, high level implementation of these methods can be found implemented in R, with the package fabletools (part of CRAN). You can find the documentation right here.

However, if you want to try reconciliation with Python, scikit-hts is a package easy to handle with a scikit-learn familiar API. It allows you do to reconciliation of hierarchical time series. However, there are two major drawbacks with this package. First, it does not dissociate the prediction step from the reconciliation step. You have to choose a predictor from a short-list of predictors (auto ARIMA, SARIMAX, Facebook Prophet and Holt-Winter’s model). Hence, if you have a specific or complex dataset for which you want to develop your own predictors ( stacked predictors, neural networks, gradient boosting -based etc.), then you can not try reconciliation. Secondly, it only implements a limited number of reconciliation methods, excluding the MinTSample and MinTShrink that are the state-of-the-art methods today.

For this reason, a new Python package was developed in order to fill this gap : reconciliation-hts.