Neuralforecast
library integrates two types of temporal scaling:
local_scaler_type
parameter of the Neuralforecast
core
class.scaler_type
parameter of each model
class.Neuralforecast
df
dataframe contains the target and exogenous variables past
information to train the model. The unique_id
column identifies the
markets, ds
contains the datestamps, and y
the electricity price.
For future variables, we include a forecast of how much electricity will
be produced (gen_forecast
), and day of week (week_day
). Both the
electricity system demand and offer impact the price significantly,
including these variables to the model greatly improve performance, as
we demonstrate in Olivares et al. (2022).
The futr_df
dataframe includes the information of the future exogenous
variables for the period we want to forecast (in this case, 24 hours
after the end of the train dataset df
).
unique_id | ds | y | gen_forecast | system_load | week_day | |
---|---|---|---|---|---|---|
0 | FR | 2015-01-01 00:00:00 | 53.48 | 76905.0 | 74812.0 | 3 |
1 | FR | 2015-01-01 01:00:00 | 51.93 | 75492.0 | 71469.0 | 3 |
2 | FR | 2015-01-01 02:00:00 | 48.76 | 74394.0 | 69642.0 | 3 |
3 | FR | 2015-01-01 03:00:00 | 42.27 | 72639.0 | 66704.0 | 3 |
4 | FR | 2015-01-01 04:00:00 | 38.41 | 69347.0 | 65051.0 | 3 |
y
and the exogenous variables are on largely different
scales. Next, we show two methods to scale the data.
Neuralforecast
classNeuralforecast
class. Each time series will be scaled before training
the model with either fit
or cross_validation
, and scaling
statistics are stored. The class then uses the stored statistics to
scale the forecasts back to the original scale before returning the
forecasts.
Neuralforecast
classTimesNet
model, recently proposed in Wu, Haixu, et
al. (2022). First instantiate the
model with the desired parameters.
NeuralForecast
object and using the fit
method. The local_scaler_type
parameter is
used to specify the type of scaling to be used. In this case, we will
use standard
, which scales the data to have zero mean and unit
variance.Other supported scalers are minmax
, robust
, robust-iqr
,
minmax
, and boxcox
.
predict
method to forecast the day-ahead prices. The
Neuralforecast
class handles the inverse normalization, forecasts are
returned in the original scale.
unique_id | ds | TimesNet | |
---|---|---|---|
0 | BE | 2016-11-01 00:00:00 | 39.523182 |
1 | BE | 2016-11-01 01:00:00 | 33.386608 |
2 | BE | 2016-11-01 02:00:00 | 27.978468 |
3 | BE | 2016-11-01 03:00:00 | 28.143955 |
4 | BE | 2016-11-01 04:00:00 | 32.332230 |
Important The inverse scaling is performed by theNeuralforecast
class before returning the final forecasts. Therefore, the hyperparmater selection withAuto
models and validation loss for early stopping or model selection are performed on the scaled data. Different types of scaling with theNeuralforecast
class can’t be automatically compared withAuto
models.
Neuralforecast
classscaler_type
argument.
Currently, it is only supported for Windows-based models
(NHITS
,
NBEATS
,
MLP
,
TimesNet
,
and all Transformers). In this example, we use the
TimesNet
model and robust
scaler, recently proposed by Wu, Haixu, et
al. (2022). First instantiate the model with the desired parameters.
Visit https://nixtla.github.io/neuralforecast/common.scalers.html for a
complete list of supported scalers.
NeuralForecast
object and using the fit
method. Note that local_scaler_type
has
None
as default to avoid scaling the data before training.
predict
method to forecast the day-ahead prices. The
forecasts are returned in the original scale.
unique_id | ds | TimesNet | |
---|---|---|---|
0 | BE | 2016-11-01 00:00:00 | 37.624653 |
1 | BE | 2016-11-01 01:00:00 | 33.069824 |
2 | BE | 2016-11-01 02:00:00 | 30.623751 |
3 | BE | 2016-11-01 03:00:00 | 28.773439 |
4 | BE | 2016-11-01 04:00:00 | 30.689444 |
Important For most applications, models with temporal normalization (section 4) produced more accurate forecasts than time series scaling (section 3). However, with temporal normalization models lose the information of the relative level between different windows. In some cases this global information within time series is crucial, for instance when an exogenous variables contains the dosage of a medication. In these cases, time series scaling (section 3) is preferred.