aggregate_temporal
function from hierarchicalforecast
. Note that we
have different aggregation matrices S
for the train- and test set, as
the test set contains temporal hierarchies that are not included in the
train set.
Y_train
contains our training data, for both 1-hour and 2-hour
periods. For example, if we look at the first two timestamps of the
training data, we have a 2-hour period ending at 2017-10-22 01:00, and
two 1-hour periods, the first ending at 2017-10-22 00:00, and the second
at 2017-10-22 01:00, the latter corresponding to when the first 2-hour
period ends.
Also, the ground truth value y
of the first 2-hour period is 38.13,
which is equal to the sum of the first two 1-hour periods (19.10 +
19.03). This showcases how the higher frequency 1-hour-period
has been
aggregated into the 2-hour-period
frequency.
temporal_id | unique_id | ds | y | |
---|---|---|---|---|
0 | 2-hour-period-1 | DE | 2017-10-22 01:00:00 | 38.13 |
816 | 1-hour-period-1 | DE | 2017-10-22 00:00:00 | 19.10 |
817 | 1-hour-period-2 | DE | 2017-10-22 01:00:00 | 19.03 |
S_train
and S_test
detail how the lowest
temporal granularity (hour) can be aggregated into the 2-hour periods.
For example, the first 2-hour period, named 2-hour-period-1
, can be
constructed by summing the first two hour-periods, 1-hour-period-1
and
1-hour-period-2
- which we also verified above in our inspection of
Y_train
.
temporal_id | 1-hour-period-1 | 1-hour-period-2 | 1-hour-period-3 | 1-hour-period-4 | |
---|---|---|---|---|---|
0 | 2-hour-period-1 | 1.0 | 1.0 | 0.0 | 0.0 |
1 | 2-hour-period-2 | 0.0 | 0.0 | 1.0 | 1.0 |
2 | 2-hour-period-3 | 0.0 | 0.0 | 0.0 | 0.0 |
3 | 2-hour-period-4 | 0.0 | 0.0 | 0.0 | 0.0 |
4 | 2-hour-period-5 | 0.0 | 0.0 | 0.0 | 0.0 |
Y_train
using TimeGPT.
Note that both frequency and horizon are different for each temporal
aggregation. In this example, the lowest level has a hourly frequency,
and a horizon of 48
. The 2-hourly-period
aggregation thus has a
2-hourly frequency with a horizon of 24
.
Y_hat
contains all the forecasts but they are not
coherent with each other. For example, consider the forecasts for the
first time period of both frequencies.
unique_id | temporal_id | ds | y | TimeGPT | |
---|---|---|---|---|---|
0 | DE | 2-hour-period-1 | 2017-12-29 01:00:00 | 10.45 | 16.949448 |
24 | DE | 1-hour-period-1 | 2017-12-29 00:00:00 | 9.73 | -0.241489 |
25 | DE | 1-hour-period-2 | 2017-12-29 01:00:00 | 0.72 | -3.456482 |
y
for the first 2-hour period is 10.45, and the
sum of the ground truth values for the first two 1-hour periods is
(9.73 + 0.72) = 10.45. Hence, these values are coherent with each other.
However, the forecast for the first 2-hour period is 16.95, but the sum
of the forecasts for the first two 1-hour periods is -3.69. Hence, these
forecasts are clearly not coherent with each other.
We will use reconciliation techniques to make these forecasts better
coherent with each other and improve their accuracy.
HierarchicalReconciliation
class to reconcile the
forecasts. In this example we use MinTrace
. Note that we have to set
temporal=True
in the reconcile
function.
HierarchicalForecast
package includes the evaluate
function to
evaluate the different hierarchies.
We evaluate the temporally aggregated forecasts across all temporal
aggregations.
level | metric | TimeGPT | TimeGPT/MinTrace_method-wls_struct | |
---|---|---|---|---|
0 | 2-hour-period | mae | 25.2 | 12.00 |
1 | 1-hour-period | mae | 18.5 | 6.16 |
2 | Overall | mae | 20.8 | 8.12 |
unique_id | temporal_id | ds | y | TimeGPT | TimeGPT/MinTrace_method-wls_struct | |
---|---|---|---|---|---|---|
0 | DE | 2-hour-period-1 | 2017-12-29 01:00:00 | 10.45 | 16.949448 | 6.625738 |
24 | DE | 1-hour-period-1 | 2017-12-29 00:00:00 | 9.73 | -0.241489 | 4.920365 |
25 | DE | 1-hour-period-2 | 2017-12-29 01:00:00 | 0.72 | -3.456482 | 1.705373 |