Skip to content

Drive splitters with stock scikit-learn CVs via groups=#1105

Merged
bruAristimunha merged 1 commit into
developfrom
copilot/allow-metadata-aware-splitter-as-cv-class
Jun 28, 2026
Merged

Drive splitters with stock scikit-learn CVs via groups=#1105
bruAristimunha merged 1 commit into
developfrom
copilot/allow-metadata-aware-splitter-as-cv-class

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

One mechanism, every evaluation, stock scikit-learn CVs only. Pass any standard scikit-learn cross-validator as cv_class and steer the folds from the metadata via groups= and/or callable cv_kwargs — no custom splitter classes, no metadata-aware detection, no subclassing.

CrossSubjectEvaluation(...)                                          # leave-one-subject-out (default, unchanged)
CrossSubjectEvaluation(..., cv_class=LeaveOneGroupOut, groups=["subject", "session"])
CrossSubjectEvaluation(..., cv_class=PredefinedSplit,
    cv_kwargs={"test_fold": lambda md: np.where((md.subject == 2) & (md.session == "1"), 0, -1)})  # single-target
WithinSubjectEvaluation(..., cv_class=GroupKFold, groups="run")      # the "special detail" case

What changed

  • groups= — a metadata column name, a list of column names (compound key, e.g. ["subject", "session"]), or a callable metadata -> array. Available on CrossSubject, CrossDataset, CrossSession (the inner held-out axis), and the Within* splitters (optional, default None = legacy behaviour). Resolved from the metadata and handed straight to the stock cv_class.
  • Callable cv_kwargs — any cv_kwargs value that is a callable is resolved against the metadata at split time, e.g. PredefinedSplit.test_fold for a single-target fold.
  • CrossSubjectSplitter and CrossDatasetSplitter are kept as separate classes (leave-one-subject-out vs leave-one-dataset-out are semantically distinct). CrossDatasetSplitter's group_column still works but is deprecated in favour of groups.

Defaults reproduce the current behaviour exactly (backward compatible).

Copilot AI changed the title [WIP] Add metadata-aware top-level splitter for CrossSubjectEvaluation Use a metadata-aware splitter directly when passed as cv_class Jun 27, 2026
Copilot AI requested a review from bruAristimunha June 27, 2026 20:42
@bruAristimunha bruAristimunha marked this pull request as ready for review June 27, 2026 21:05

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

���w� sklearn.dummy���DummyClassifier���)��}�(��strategy���prior�� random_state�N��constant�N��_sklearn_version���1.9.0�ub.

P2 Badge Remove the committed generated model artifact

Because this pickle is already present in checkouts, TestUtilEvaluation.test_save_model_cv can pass even when save_model_cv() fails to create anything—the assertion only checks that test_save_path/fitted_model_0.pkl exists after the call. This masks regressions in model saving and leaves a generated test artifact in the source tree; remove it and have the test create/clean the path.

ℹ️ 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".

Comment thread moabb/evaluations/splitters.py Outdated
@bruAristimunha bruAristimunha force-pushed the copilot/allow-metadata-aware-splitter-as-cv-class branch from 56d343e to b14c97b Compare June 28, 2026 01:02
@bruAristimunha bruAristimunha merged commit b9d01a0 into develop Jun 28, 2026
10 of 12 checks passed
@bruAristimunha bruAristimunha changed the title Use a metadata-aware splitter directly when passed as cv_class Drive splitters with stock scikit-learn CVs via groups= Jun 28, 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.

2 participants