Geographical Hierarchical Forecasting on Australian Tourism DataIn many applications, a set of time series is hierarchically organized. Examples include the presence of geographic levels, products, or categories that define different types of aggregations. In such scenarios, forecasters are often required to provide predictions for all disaggregate and aggregate series. A natural desire is for those predictions to be “coherent”, that is, for the bottom series to add up precisely to the forecasts of the aggregated series. In this notebook we present an example on how to use
HierarchicalForecast
to produce coherent forecasts between
geographical levels. We will use the classic Australian Domestic Tourism
(Tourism
) dataset, which contains monthly time series of the number of
visitors to each state of Australia.
We will first load the Tourism
data and produce base forecasts using
an AutoETS
model from StatsForecast
, and then reconciliate the
forecasts with several reconciliation algorithms from
HierarchicalForecast
. Finally, we show the performance is comparable
with the results reported by the Forecasting: Principles and
Practice which uses the R package
fable.
You can run these experiments using CPU or GPU with Google Colab.
Country | Region | State | Purpose | ds | y | |
---|---|---|---|---|---|---|
0 | Australia | Adelaide | South Australia | Business | 1998-01-01 | 135.077690 |
1 | Australia | Adelaide | South Australia | Business | 1998-04-01 | 109.987316 |
2 | Australia | Adelaide | South Australia | Business | 1998-07-01 | 166.034687 |
3 | Australia | Adelaide | South Australia | Business | 1998-10-01 | 127.160464 |
4 | Australia | Adelaide | South Australia | Business | 1999-01-01 | 137.448533 |
aggregate
function from HierarchicalForecast
we can get
the full set of time series.
unique_id | ds | y | |
---|---|---|---|
0 | Australia | 1998-01-01 | 23182.197269 |
1 | Australia | 1998-04-01 | 20323.380067 |
2 | Australia | 1998-07-01 | 19826.640511 |
3 | Australia | 1998-10-01 | 20830.129891 |
4 | Australia | 1999-01-01 | 22087.353380 |
unique_id | Australia/ACT/Canberra/Business | Australia/ACT/Canberra/Holiday | Australia/ACT/Canberra/Other | Australia/ACT/Canberra/Visiting | |
---|---|---|---|---|---|
0 | Australia | 1.0 | 1.0 | 1.0 | 1.0 |
1 | Australia/ACT | 1.0 | 1.0 | 1.0 | 1.0 |
2 | Australia/New South Wales | 0.0 | 0.0 | 0.0 | 0.0 |
3 | Australia/Northern Territory | 0.0 | 0.0 | 0.0 | 0.0 |
4 | Australia/Queensland | 0.0 | 0.0 | 0.0 | 0.0 |
Y_df
using the ETS
model. Observe that Y_hat_df
contains the
forecasts but they are not coherent.
HierarchicalReconciliation
class. Since the hierarchy structure is not
strict, we can’t use methods such as TopDown
or MiddleOut
. In this
example we use BottomUp
and MinTrace
.
Y_rec_df
contains the reconciled forecasts.
unique_id | ds | AutoETS | AutoETS/BottomUp | AutoETS/MinTrace_method-mint_shrink | AutoETS/MinTrace_method-ols | |
---|---|---|---|---|---|---|
0 | Australia | 2016-01-01 | 25990.068004 | 24381.911737 | 25428.089783 | 25894.399067 |
1 | Australia | 2016-04-01 | 24458.490282 | 22903.895964 | 23914.271400 | 24357.301898 |
2 | Australia | 2016-07-01 | 23974.055984 | 22412.265739 | 23428.462394 | 23865.910647 |
3 | Australia | 2016-10-01 | 24563.454495 | 23127.349578 | 24089.845955 | 24470.782393 |
4 | Australia | 2017-01-01 | 25990.068004 | 24518.118006 | 25545.358678 | 25901.362283 |
HierarchicalForecast
package includes an evaluate
function to
evaluate the different hierarchies and also is capable of compute scaled
metrics compared to a benchmark model.
level | metric | Base | BottomUp | MinTrace(mint_shrink) | MinTrace(ols) | |
---|---|---|---|---|---|---|
0 | Total | rmse | 1743.29 | 3028.62 | 2112.73 | 1818.94 |
2 | Purpose | rmse | 534.75 | 791.19 | 577.14 | 515.53 |
4 | State | rmse | 308.15 | 413.39 | 316.82 | 287.32 |
6 | Regions | rmse | 51.66 | 55.13 | 46.55 | 46.28 |
8 | Bottom | rmse | 19.37 | 19.37 | 17.80 | 18.19 |
10 | Overall | rmse | 41.12 | 49.82 | 40.47 | 38.75 |
level | metric | Base | BottomUp | MinTrace(mint_shrink) | MinTrace(ols) | |
---|---|---|---|---|---|---|
1 | Total | mase | 1.59 | 3.16 | 2.06 | 1.67 |
3 | Purpose | mase | 1.32 | 2.28 | 1.48 | 1.25 |
5 | State | mase | 1.39 | 1.90 | 1.40 | 1.25 |
7 | Regions | mase | 1.12 | 1.19 | 1.01 | 0.99 |
9 | Bottom | mase | 0.98 | 0.98 | 0.94 | 1.01 |
11 | Overall | mase | 1.02 | 1.06 | 0.97 | 1.02 |