NeuralForecast
models.
The two methods to consider are:1.
NeuralForecast.save
:
Saves models into disk, allows save dataset and config.2.
NeuralForecast.load
:
Loads models from a given path.Important This Guide assumes basic knowledge on the NeuralForecast library. For a minimal example visit the Getting Started guide.You can run these experiments using GPU with Google Colab.
1. Installing NeuralForecast
2. Loading AirPassengers Data
For this example we will use the classical AirPassenger Data set. Import the pre-processed AirPassenger fromutils
.
unique_id | ds | y | |
---|---|---|---|
0 | 1.0 | 1949-01-31 | 112.0 |
1 | 1.0 | 1949-02-28 | 118.0 |
2 | 1.0 | 1949-03-31 | 132.0 |
3 | 1.0 | 1949-04-30 | 129.0 |
4 | 1.0 | 1949-05-31 | 121.0 |
3. Model Training
Next, we instantiate and train three models:NBEATS
,
NHITS
,
and
AutoMLP
.
The models with their hyperparameters are defined in the models
list.
predict
method.
unique_id | ds | NBEATS | NHITS | AutoMLP | |
---|---|---|---|---|---|
0 | 1.0 | 1961-01-31 | 446.882172 | 447.219238 | 454.914154 |
1 | 1.0 | 1961-02-28 | 465.145813 | 464.558014 | 430.188446 |
2 | 1.0 | 1961-03-31 | 469.978424 | 474.637238 | 458.478577 |
3 | 1.0 | 1961-04-30 | 493.650665 | 502.670349 | 477.244507 |
4 | 1.0 | 1961-05-31 | 537.569275 | 559.405212 | 522.252991 |

4. Save models
To save all the trained models use thesave
method. This method will
save both the hyperparameters and the learnable weights (parameters).
The save
method has the following inputs:
path
: directory where models will be saved.model_index
: optional list to specify which models to save. For example, to only save theNHITS
model usemodel_index=[2]
.overwrite
: boolean to overwrite existing files inpath
. When True, the method will only overwrite models with conflicting names.save_dataset
: boolean to saveDataset
object with the dataset.
[model_name]_[suffix].ckpt
: Pytorch Lightning checkpoint file with the model parameters and hyperparameters.[model_name]_[suffix].pkl
: Dictionary with configuration attributes.
model_name
corresponds to the name of the model in lowercase
(eg. nhits
). We use a numerical suffix to distinguish multiple models
of each class. In this example the names will be automlp_0
,
nbeats_0
, and nhits_0
.
Important TheAuto
models will be stored as their base model. For example, theAutoMLP
trained above is stored as anMLP
model, with the best hyparparameters found during tuning.
5. Load models
Load the saved models with theload
method, specifying the path
, and
use the new nf2
object to produce forecasts.
unique_id | ds | NHITS | NBEATS | AutoMLP | |
---|---|---|---|---|---|
0 | 1.0 | 1961-01-31 | 447.219238 | 446.882172 | 454.914154 |
1 | 1.0 | 1961-02-28 | 464.558014 | 465.145813 | 430.188446 |
2 | 1.0 | 1961-03-31 | 474.637238 | 469.978424 | 458.478577 |
3 | 1.0 | 1961-04-30 | 502.670349 | 493.650665 | 477.244507 |
4 | 1.0 | 1961-05-31 | 559.405212 | 537.569275 | 522.252991 |
