Repository navigation
Description
Should the param_grid search in CrossSubjectEvaluation and CrossSessionEvaluation split its inner folds by subject or session? Or should the docs point users to a search inside the pipeline?
_evaluate_fold builds StratifiedKFold(3, shuffle=True) for the search (moabb/evaluations/base.py:227, also evaluations.py:144 and :366) and fits it without groups. In CrossSubjectEvaluation, each inner validation fold therefore holds trials from the same subjects as the inner training folds. In CrossSessionEvaluation it holds trials from the same sessions. The search picks parameters for generalization within a subject, while the outer score measures generalization to a new subject (Varoquaux et al. 2017, NeuroImage 145:166-179, https://doi.org/10.1016/j.neuroimage.2016.10.038).
I compared the two inner splits with a local patch: TS+LR, C in logspace(-4, 2, 7), CrossSessionEvaluation, LeftRightImagery, subjects 1 and 2 only.
| Dataset | Inner split | Median C | Mean outer AUC | Inner minus outer AUC |
|---|---|---|---|---|
| Zhou2016 (6 folds) | StratifiedKFold (current) | 1 | 0.896 | +0.014 |
| Zhou2016 (6 folds) | LeaveOneGroupOut by session | 0.55 | 0.898 | +0.003 |
| BNCI2014_004 (10 folds) | StratifiedKFold (current) | 10 | 0.741 | -0.013 |
| BNCI2014_004 (10 folds) | LeaveOneGroupOut by session | 0.55 | 0.739 | -0.0003 |
The grouped split picks a smaller C, and its inner score is closer to the outer score. The outer AUC does not change in a measurable way (Wilcoxon p = 0.5 and 0.64 over the folds). With 2 subjects this test cannot detect an effect below about 0.01 AUC, so I do not propose to change the default.
A grouped search is already possible through the metadata routing from #1305. I checked it on FakeDataset with 4 subjects, and each inner split held out one training subject:
import sklearn
from sklearn.model_selection import GridSearchCV, GroupKFold
with sklearn.config_context(enable_metadata_routing=True):
inner = GroupKFold(3).set_split_request(groups="subject")
search = GridSearchCV(pipe, {"logisticregression__C": [0.1, 1]}, cv=inner)
CrossSubjectEvaluation(...).process({"gs": search})This matches #773 (grid search inside the pipeline). The docs do not show it, and the param_grid argument does not use it.
Possible changes:
- Add an opt-in
inner_cvargument. When it is a group splitter, MOABB passes the outer group of each training trial (subject, session, or thegroups=column). The default staysStratifiedKFold. I have this as a small patch:base.py,evaluations.py, one test and one whats_new line. - Document the pipeline-level search above and leave the evaluations as they are.
Which do you prefer?
AI disclosure: this was prepared with AI assistance (Claude, Anthropic).
Activity