Probabilistic Forecasting
Quantify uncertainty
Probabilistic forecasting is a natural answer to quantify the uncertainty of target variable’s future. The task requires to model the following conditional predictive distribution:
We will show you how to tackle the task with
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:
1. Install NeuralForecast Library
2.
Explore the M4-Hourly data.
3. Train the LSTM and NHITS
4.
Visualize the LSTM/NHITS prediction intervals.
You can run these experiments using GPU with Google Colab.
1. Installing NeuralForecast
Useful functions
The plot_grid
auxiliary function defined below will be useful to plot
different time series, and different models’ forecasts.
2. Loading M4 Data
For testing purposes, we will use the Hourly dataset from the M4 competition.
In this example we will use a subset of the data to avoid waiting too long. You can modify the number of series if you want.
3. Model Training
The 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.
- The
horizon
parameter controls the number of steps ahead of the predictions, in this example 48 hours ahead (2 days). - The
MQLoss
withlevels=[80,90]
specializes the network’s output into the 80% and 90% prediction intervals. - The
max_steps=2000
, controls the duration of the network’s training.
For more network’s instantiation details check their documentation.
All the models of the library are global, meaning that all time series
in 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 | 603.491211 | 526.534119 | 544.686646 | 650.893799 | 673.805603 | 611.634888 | 575.999146 | 582.778687 | 677.277039 | 674.705872 |
1 | H1 | 702 | 548.415710 | 438.868591 | 472.805237 | 608.017822 | 639.063293 | 569.997803 | 513.014282 | 518.707153 | 598.849609 | 616.793457 |
2 | H1 | 703 | 502.010681 | 382.608643 | 411.710419 | 570.315308 | 608.669250 | 510.787628 | 454.184448 | 465.425232 | 538.964172 | 554.563354 |
3 | H1 | 704 | 460.870483 | 339.368988 | 370.636719 | 544.232666 | 579.824402 | 478.482330 | 429.657104 | 452.395508 | 500.892090 | 502.507141 |
4 | H1 | 705 | 436.451843 | 313.868744 | 343.514191 | 520.812988 | 559.734741 | 463.763611 | 432.906342 | 427.853577 | 486.854492 | 487.539062 |
4. Plotting Predictions
Here we finalize our analysis by plotting the prediction intervals and
verifying that both the
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.
LSTM
NHITS
References
- Roger Koenker and Gilbert Basset (1978). Regression Quantiles,
Econometrica.
- Jeffrey L. Elman (1990). “Finding Structure in
Time”.
- Cristian Challu, Kin G. Olivares, Boris N. Oreshkin, Federico
Garza, Max Mergenthaler-Canseco, Artur Dubrawski (2021). NHITS:
Neural Hierarchical Interpolation for Time Series Forecasting.
Accepted at AAAI 2023.