Skip to content

[ENH] Add neuralforecast adapter and rnn forecaster#5962

Merged
fkiraly merged 3 commits intosktime:mainfrom
yarnabrina:add-neuralforecast-adapter-and-rnn-forecaster
Feb 25, 2024
Merged

[ENH] Add neuralforecast adapter and rnn forecaster#5962
fkiraly merged 3 commits intosktime:mainfrom
yarnabrina:add-neuralforecast-adapter-and-rnn-forecaster

Conversation

@yarnabrina
Copy link
Copy Markdown
Member

@yarnabrina yarnabrina commented Feb 17, 2024

Adapter class to neuralforecast from Nixtla and concrete estimator for RNN.

Notes for reviewers (not in any particular order)

  1. neuralforecast supports 3 types of exogenous features: static (constant over time), historical (unknown for prediction horizon) and future (known for prediction horizon). I felt the static type has no predictive capability if models are trained per series, and as far as I know, sktime will not be able to support historical type for framework compatibilities. Hence in this first draft of adaptation, I have added support for only future type.

  2. neuralforecast has the capability of directly supporting panel/hierarchical datasets directly. I am not sure how to take benefit of that in sktime, so have not used it in this first draft. If it's easy enough to support, I can update if some references are shared, otherwise this can definitely be a extension.

  3. RNN in neuralforecast supports specification of loss and validation loss, but they needs to be instances of pytorch loss functions. I am not sure how set these defaults in instance, as soft dependencies can not be checked there. I have hence not exposed these parameters and rely on the defaults, but this is both important and common parameter. With some suggestions and references, I will like to enhance this in this draft itself. Added some support using internal attributes.

  4. neuralforecast does support probablistic forecasts, but it seems that depends on choice of loss function (and may be something more, not sure). In this first draft, I have not added that support so far and this can be part of an extension.

  5. neuralforecast has a public NeuralForecast class which accepts pandas.DataFrame objects of special schema directly, and has the ability to train multiple models and find best one. The underlying models do not support pandas.DataFrame directly and relies of TimeSeriesDataset, a sub-class of torch.utils.data.Dataset. For simplification with most other forecasters, I opted for the higher level class.

  6. neuralforecast supports in-sample predictions, but warns that those may be inaccurate. Since the library itself is marked as Alpha, I have disabled entire support of in-sample predictions for now.

  7. neuralforecast takes a lot of dependencies, and adding it in forecasting extra may cause too much installation for users who won't use it. But adding it in dl extra means new CI is not going to test it, so we need to decide what to do.

  8. neuralforecast supports a lot of models, and (hopefully) all of them can be used with the adapter in this PR. However that is a lot of models, and it leads to the question of how should we organise them, by model or by dependency or by both or by something else. Modified only dl dependency similar to other recent PR's that affect torch/tensorflow etc.

@yarnabrina
Copy link
Copy Markdown
Member Author

@AzulGarza @jmoralez if you can please take a look at this PR and share your reviews for this adaptation, especially if you have suggestions that will help in supporting a long term stable adapter, that will be much appreciated.

@fkiraly fkiraly added interfacing algorithms Interfacing existing algorithms/estimators from third party packages module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting enhancement Adding new functionality labels Feb 17, 2024
@yarnabrina yarnabrina marked this pull request as draft February 17, 2024 19:57
Copy link
Copy Markdown
Member Author

@yarnabrina yarnabrina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of CI is disabled to quickly get test results for new addition. This is not part of the main PR goal, and will be reverted before merge. Ignore all changes in .github.

NOTE: revert 2b756d9 before marking ready for merge.

Comment thread .github/workflows/test.yml
Comment thread .github/workflows/test_module.yml
@yarnabrina
Copy link
Copy Markdown
Member Author

FYI @fkiraly @benHeid @achieveordie : all tests pass for the relevant adapter and estimators in all environment combinations (CI is modified to ensure all tests for these run on all combinations of operating systems and python versions). Other than addressing reverting CI debug commit just before merge, I have no other new changes to add in this PR (other than review comments of course).

Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!

Few questions:

  • the in-sample failures can be silenced by raising NotImplementedError if not fh_is_all_in_sample(). @benHeid had the same issue recently, probably we should do that in the base class.
  • question: how would we test this in the intended end state?
  • a bit unsettling that freq is an argument of __init__, rather than obtained from X or fh. Is the latter not possible?

Comment thread sktime/forecasting/base/adapters/_neuralforecast.py
Comment thread sktime/forecasting/neuralforecast.py
Comment thread sktime/forecasting/base/adapters/_neuralforecast.py
Comment thread docs/source/api_reference/forecasting.rst Outdated
1. added generic adapter
2. added concrete RNN estimator
3. added tests
4. added reference in docs
5. updated `dl` dependency
@yarnabrina yarnabrina marked this pull request as ready for review February 22, 2024 14:43
@yarnabrina yarnabrina marked this pull request as draft February 22, 2024 16:17
Comment thread sktime/forecasting/base/adapters/_neuralforecast.py
@yarnabrina yarnabrina marked this pull request as ready for review February 22, 2024 17:14
Copy link
Copy Markdown

@jmoralez jmoralez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the nixtla side. Thanks for working on this!

Comment thread sktime/forecasting/base/adapters/_neuralforecast.py Outdated
Comment thread sktime/forecasting/neuralforecast.py Outdated
Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thx!

@fkiraly fkiraly merged commit 7605ffc into sktime:main Feb 25, 2024
@yarnabrina yarnabrina deleted the add-neuralforecast-adapter-and-rnn-forecaster branch February 25, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adding new functionality interfacing algorithms Interfacing existing algorithms/estimators from third party packages module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants