unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.96k stars 866 forks source link

NBEATS and NBEATSx handling exogenous variables #1943

Open uomodellamansarda opened 1 year ago

uomodellamansarda commented 1 year ago

I am quite new and I am still trying to understand how NBEATS is handling exogenous variables, I know the architecture is not designed for that, and this issue is overcome in NBEATx

How are handled in Darts NBEATS version external variables/covariates?

In addition to the univariate version presented in the paper, our implementation also supports multivariate series (and covariates) by flattening the model inputs to a 1-D series and reshaping the outputs to a tensor of appropriate dimensions. Furthermore, it also supports producing probabilistic forecasts (by specifying a likelihood parameter).

Are you planning to implement NBEATSx? Here NBEATSx Paper: https://arxiv.org/pdf/2104.05522.pdf) Here a Python implementation: https://github.com/cchallu/nbeatsx/blob/main/nbeatsx_example.ipynb

madtoinou commented 1 year ago

Hi @uomodellamansarda,

Darts adaptation of NBEATS to support covariates consists (roughly) in slicing the timeseries (align the time indices), creating a single tensor containing all the values of shape (input_chunk_length, k, 1) where k = 1 + len(X.columns) before flattening it into (1, k*input_chunk_length, 1)` (this correspond to a single sample, several of them can be combined to create a batch) and passing it through the NBEATS stacks. The output is then reshaped to retain only the forecasts of the target.

It should not be too difficult to bring the NBEATSx improvements to the current implementation, by adding a stack dedicated to the covariates (as described in the paper). WDYT @dennisbader ?

uomodellamansarda commented 1 year ago

Thanks for the quick reply, very interesting!