Skip to content

[FEAT] Add fold_transform support to cross_validation #603

Open
janrth wants to merge 2 commits intoNixtla:mainfrom
janrth:enhancement/pipeline_cross_validation
Open

[FEAT] Add fold_transform support to cross_validation #603
janrth wants to merge 2 commits intoNixtla:mainfrom
janrth:enhancement/pipeline_cross_validation

Conversation

@janrth
Copy link
Copy Markdown
Contributor

@janrth janrth commented Mar 21, 2026

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:

  • This PR has a meaningful title and a clear description.
  • The tests pass.
  • All linting tasks pass.
  • The notebooks are clean.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@janrth janrth changed the title Add fold_transform support to cross_validation with docs examples [FEAT] Add fold_transform support to cross_validation with docs examples Mar 21, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 21, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing janrth:enhancement/pipeline_cross_validation (09abef1) with main (dad51e8)

Open in CodSpeed

@janrth janrth changed the title [FEAT] Add fold_transform support to cross_validation with docs examples [FEAT] Add fold_transform support to cross_validation Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant