sklearn/missing-groups
| Rule | missing-groups |
|---|---|
| Pack | scikit-learn |
| Severity | error |
| Fix | none, edit by hand |
| Library versions | every version |
A group splitter without groups= raises ValueError. Pass groups= with the group of each row.
search = GridSearchCV(model, grid, cv=GroupKFold(n_splits=5))search.fit(X, y)search.fit(X, y, groups=patient_id)What the rule reports
Section titled “What the rule reports”The rule reports a group splitter that gets no groups, such as
cross_val_score(model, X, y, cv=GroupKFold(5)) or GroupKFold(5).split(X, y), which raises
ValueError.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
On scikit-learn 1.9.1 each form raises "The 'groups' parameter should not be None", and
StratifiedGroupKFold raises that it found 1 group. The rule covers GroupKFold,
StratifiedGroupKFold, GroupShuffleSplit, LeaveOneGroupOut and LeavePGroupsOut in the
following places:
- as
cvofcross_val_score,cross_validate,cross_val_predict,learning_curve,validation_curveandpermutation_test_score - in their own
split(X, y), called directly or through a name - in a
GridSearchCV,RandomizedSearchCV,HalvingGridSearchCV,HalvingRandomSearchCVorRFECVwhosefitgets nogroups=
A call with params= or ** is left alone, because it can carry the groups.
SequentialFeatureSelector and LogisticRegressionCV take groups only through metadata routing,
so the rule doesn't read them. Recall was 48 of 50.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
$K splits by group, and $F gets no groups=, so it raises a ValueError. Pass groups= with the group of each row.Browse the other rules of the scikit-learn pack.