[FEAT] Add fold_transform support to cross_validation #603
Open
janrth wants to merge 2 commits intoNixtla:mainfrom
Open
[FEAT] Add fold_transform support to cross_validation #603janrth wants to merge 2 commits intoNixtla:mainfrom
janrth wants to merge 2 commits intoNixtla:mainfrom
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce3f3e267e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added support for custom fold-level transformations in MLForecast.cross_validation via a new fold_transform hook. This makes it possible to fit custom encoders or other train-fold-only preprocessing steps inside each cv window before fitting and prediction, without relying on sklearn pipelines.
This allows users to run cross_validation with custom encoders being build in pandas or polars.
While this seems similar to the global and groupby window functions we recently introduced, here we can build leakage free more advanced encoders.
To show how this new functionality works, I have added an example for pandas and polars on the documentation notebook.
What changed:
added fold_transform to MLForecast.cross_validation
fold_transform receives (train_df, valid_df, *, id_col, time_col, target_col) and must return the transformed (train_df, valid_df) pair
the hook is applied per split before model fitting and prediction
added a guard requiring refit=True or refit=1 when fold_transform is used, since reused models would otherwise be inconsistent with fold-fitted transformations
Checklist: