You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow a metadata-aware splitter as cv_class (used directly, not wrapped as the inner groups-CV) #1104
CrossSubjectEvaluation (and the CrossSubjectSplitter/CrossSessionSplitter wrappers)
always treat cv_class as the inner CV: they instantiate it and call split(X=index, y, [groups=subject]), forwarding only the subject column. There is no
public way to plug in a metadata-aware top-level splitter — one that needs split(y, metadata)
and other columns (e.g. session) to build the fold.
Why this matters
We want a single-target cross-subject fold that restricts the test set to one session while
excluding the target's other sessions from training (test = target@session, train = other
subjects). That decision needs the session column, which the inner-CV path never passes.
A splitter that already follows the moabb convention (subclasses BaseCrossValidator, declares metadata_columns = ("subject", "session"), implements split(self, y, metadata)) cannot be
passed via cv_class:
importpandasaspdfrommoabb.evaluations.splittersimportCrossSubjectSplitter# MySplitter: BaseCrossValidator with metadata_columns=("subject","session") and split(self, y, metadata)md=pd.DataFrame({"subject": [1, 1, 2, 2], "session": ["0", "1", "0", "1"]})
list(CrossSubjectSplitter(cv_class=MySplitter, target=2, test_session="1").split(y=None, metadata=md))
# TypeError: MySplitter.split() got an unexpected keyword argument 'X'
Current workaround
Subclass the evaluation and override _create_splitter to use cv_class directly:
The evaluation already inspects cv_class.metadata_columns in __init__ (to extend additional_columns). Extend that: when cv_class declares metadata_columns, use it directly
as the top-level splitter — call split(y, metadata) — instead of wrapping it as the inner
groups-CV. Backward compatible (group CVs without metadata_columns keep wrapping), and it lets
metadata-driven folds be configured through the public cv_class / cv_kwargs API with no subclass.
Status after #1105 (groups=) — the core need is still open
#1105 lets CrossSubjectSplitter key folds on a compound metadata column (groups=["subject", "session"]) through the stock inner CV. That's useful, but it doesn't cover this issue, because the inner CV runs over all rows and can only partition them (train ⊎ test). The single-target case here needs a 3-way split — train / test / excluded — where the held-out subject's non-test sessions are dropped from both sets.
Verified against our workaround splitter (TargetSubjectSplitter, which declares metadata_columns=("subject","session") and does split(self, y, metadata)):
# subjects 1–3, sessions {0train, 1test}; target=2, test_session="1test"# train : subjects 1, 3 (all their sessions)# test : subject 2 @ 1test# -> subject 2 @ 0train is DROPPED — not in train, not in test
No stock scikit-learn CV expresses that drop:
PredefinedSplit(test_fold=-1) puts the excluded rows in train → the held-out subject leaks into training.
LeaveOneGroupOut never excludes rows.
The keep-filter that makes this correct lives inside the splitter (subset the metadata to the kept rows, then PredefinedSplit over those). That's exactly why this issue's proposal — use a metadata_columns-declaring splitter directly as cv_class, calling split(y, metadata) instead of wrapping it as the inner groups-CV — is the clean fix; it lets the splitter own both the fold and the exclusion. (A narrower alternative would be a drop/exclude callable on CrossSubjectSplitter, metadata -> bool mask, applied before the inner CV.)
Concretely it's the only thing still keeping a small shim (TargetSubjectEvaluation + TargetSubjectSplitter) in our downstream code after #1105/#1107/#1109 retired the others. Happy to PR the metadata_columns-as-cv_class direction if that's the preferred shape.
Activity
bruAristimunha commentedon Jun 28, 2026
Status after #1105 (
groups=) — the core need is still open#1105 lets
CrossSubjectSplitterkey folds on a compound metadata column (groups=["subject", "session"]) through the stock inner CV. That's useful, but it doesn't cover this issue, because the inner CV runs over all rows and can only partition them (train ⊎ test). The single-target case here needs a 3-way split — train / test / excluded — where the held-out subject's non-test sessions are dropped from both sets.Verified against our workaround splitter (
TargetSubjectSplitter, which declaresmetadata_columns=("subject","session")and doessplit(self, y, metadata)):No stock scikit-learn CV expresses that drop:
PredefinedSplit(test_fold=-1)puts the excluded rows in train → the held-out subject leaks into training.LeaveOneGroupOutnever excludes rows.The keep-filter that makes this correct lives inside the splitter (subset the metadata to the kept rows, then
PredefinedSplitover those). That's exactly why this issue's proposal — use ametadata_columns-declaring splitter directly ascv_class, callingsplit(y, metadata)instead of wrapping it as the inner groups-CV — is the clean fix; it lets the splitter own both the fold and the exclusion. (A narrower alternative would be adrop/excludecallable onCrossSubjectSplitter,metadata -> bool mask, applied before the inner CV.)Concretely it's the only thing still keeping a small shim (
TargetSubjectEvaluation+TargetSubjectSplitter) in our downstream code after #1105/#1107/#1109 retired the others. Happy to PR themetadata_columns-as-cv_classdirection if that's the preferred shape.ENH use a metadata-aware cv_class directly as the top-level splitter (N…
Do not store reserved result columns (subject, session, ...) as split…
ENH use a metadata-aware cv_class directly as the top-level splitter (#…
Review follow-ups for the merged w42 PRs (#1257-#1270) (#1271)