Repository navigation
Accept list, tuple and non-default-index Series groups in group splits - #1665
Open
Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
Open
Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
groupsis documented as "None or array-like", butsplit_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) orAttributeError: ... no attribute 'iloc'(cv, also withsplit_type=GroupKFold(3)). A Series whose index is a permutation of 0..n-1 raises nothing, but the holdout split stores other rows' labels instate.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.