Skip to content

Accept list, tuple and non-default-index Series groups in group splits - #1665

Open
Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
microsoft:mainfrom
sohailshk:fix/group-split-groups-indexing
Open

Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
microsoft:mainfrom
sohailshk:fix/group-split-groups-indexing

Conversation

@sohailshk

Copy link
Copy Markdown

Why are these changes needed?

groups is documented as "None or array-like", but split_type="group" indexes the labels positionally. Realistic repro (iris, train_test_split(X, y, df["cluster"]) which keeps the Series index, regression, split_type="group", eval_method="holdout"): KeyError: "None of [Index([9, 11, ...])] are in the [index]" on main; it runs on this branch (the cv variant already worked).
Other cases on main (each run): a list or tuple raises TypeError: only integer scalar arrays can be converted to a scalar index (holdout) or AttributeError: ... no attribute 'iloc' (cv, also with split_type=GroupKFold(3)). A Series whose index is a permutation of 0..n-1 raises nothing, but the holdout split stores other rows' labels in state.groups / state.groups_val (checked at state level; the effect on ranking metrics is from code reading only).
The change converts list, tuple and Series group labels (and groups_val) to an ndarray when the data is prepared. New tests: list, tuple, offset-index Series (holdout and cv), GroupKFold with a list (cv), and the permuted-index state check; 7 fail on main, all pass here. Existing test_split tests pass except two that import catboost (not installed).

Related issue number

Related: #1384/#1385, #1396/#1405, #1586 (same indexing, sample_weight side).

Checks

Checks run: black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.

AutoML.fit(split_type='group') indexed the group labels positionally with
groups[train_idx]. A list or tuple raised TypeError (holdout) or AttributeError
(cv, no .iloc), and a pd.Series with a non-default index raised KeyError in the
holdout split because it was indexed by label. Convert such group labels to an
ndarray when the data is prepared.

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.

1 participant