Skip to content

Fix CrossSubjectEvaluation crash when n_splits and random_state are both set - #1374

Open
ptlnextdoor wants to merge 1 commit into
NeuroTechX:developfrom
ptlnextdoor:fix/oss-moabb-crosssubject-groupkfold-random-state
Open

ptlnextdoor wants to merge 1 commit into
NeuroTechX:developfrom
ptlnextdoor:fix/oss-moabb-crosssubject-groupkfold-random-state

Conversation

@ptlnextdoor

Copy link
Copy Markdown

What was wrong

CrossSubjectEvaluation(n_splits=k, random_state=s) raised ValueError: Setting a random_state has no effect since shuffle is False. With n_splits set, the inner CV is GroupKFold. Since scikit-learn 1.6, GroupKFold has a random_state argument but refuses a seed while shuffle=False. CrossSubjectSplitter passed random_state whenever the class accepts it. Without a seed the same call worked.

What changed

  • moabb/evaluations/splitters.py: CrossSubjectSplitter no longer passes random_state to a CV class that has a shuffle argument which is off. The folds are the same as without a seed. CrossSessionSplitter already guards the same case.
  • moabb/tests/test_evaluations.py: a regression test builds the splitter from CrossSubjectEvaluation(n_splits=2, random_state=42) on FakeDataset and checks that it makes 2 folds identical to the unseeded ones. It fails on develop with the ValueError above.
  • docs/source/whats_new.rst: one line under Bugs.

How tested

  • pytest moabb/tests/test_evaluations.py: the new test fails on develop and passes with the change (scikit-learn 1.9.1).
  • pre-commit run --files on the three changed files: pass.

AI disclosure: this PR was prepared with AI assistance (Claude, Anthropic).

GroupKFold accepts random_state but rejects it while shuffle is False, so CrossSubjectEvaluation(n_splits=k, random_state=s) raised ValueError. The splitter now skips the seed in that case, as CrossSessionSplitter already does.
Copilot AI balanced review requested due to automatic review settings November 24, 2026 22:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
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