Quantify uncertainty
NeuralForecast
by combining a classic Long Short Term Memory Network
(LSTM) and the Neural Hierarchical
Interpolation (NHITS) with the multi
quantile loss function (MQLoss).
In this notebook we will:plot_grid
auxiliary function defined below will be useful to plot
different time series, and different models’ forecasts.
core.NeuralForecast
provides a high-level interface with our
collection of PyTorch models.
NeuralForecast
is instantiated with a list of models=[LSTM(...), NHITS(...)]
,
configured for the forecasting task.
horizon
parameter controls the number of steps ahead of the
predictions, in this example 48 hours ahead (2 days).MQLoss
with levels=[80,90]
specializes the network’s output into the 80%
and 90% prediction intervals.max_steps=2000
, controls the duration of the network’s
training.Y_train_df
is used during a shared optimization to train a single
model with shared parameters. This is the most common practice in the
forecasting literature for deep learning models, and it is known as
“cross-learning”.
unique_id | ds | LSTM-median | LSTM-lo-90 | LSTM-lo-80 | LSTM-hi-80 | LSTM-hi-90 | NHITS-median | NHITS-lo-90 | NHITS-lo-80 | NHITS-hi-80 | NHITS-hi-90 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | H1 | 701 | 650.919861 | 526.705933 | 551.696289 | 748.392456 | 777.889526 | 615.786743 | 582.732117 | 584.717468 | 640.011841 | 647.147034 |
1 | H1 | 702 | 547.724487 | 439.353394 | 463.725464 | 638.429626 | 663.398987 | 569.632324 | 524.486023 | 522.324402 | 578.411560 | 594.515076 |
2 | H1 | 703 | 514.851074 | 421.289917 | 443.166443 | 589.451782 | 608.560425 | 518.858887 | 503.183411 | 501.016968 | 536.081543 | 549.701050 |
3 | H1 | 704 | 485.141418 | 403.336914 | 421.090546 | 547.966492 | 567.057800 | 495.627869 | 476.579742 | 468.514069 | 498.171600 | 527.931091 |
4 | H1 | 705 | 462.695831 | 383.011108 | 399.126282 | 522.579224 | 543.981750 | 481.584534 | 468.134857 | 472.723450 | 496.198975 | 513.859985 |
LSTM
and
NHITS
are giving excellent results.
Consider the output [NHITS-lo-90.0
, NHITS-hi-90.0]
, that represents
the 80% prediction interval of the
NHITS
network; its lower limit gives the 5th percentile (or 0.05 quantile)
while its upper limit gives the 95th percentile (or 0.95 quantile). For
well-trained models we expect that the target values lie within the
interval 90% of the time.