Skip to content

We should raise an error message when n_groups > actual number of groups #7681

@raghavrv

Description

@raghavrv

In LeaveOneGroupOut and LeavePGroupsOut, when the groups supplied at split time has fewer than or equal to n_groups, we should raise an error.

>>> import numpy as np
>>> from sklearn.model_selection import LeaveOneGroupOut, LeavePGroupsOut
>>> X = y = groups = np.ones(10)
>>> list(LeaveOneGroupOut.split(X, y, groups))
[(array([], dtype=int64), array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))]
>>> list(LeavePGroupsOut(n_groups=5).split(X, y, groups))
[]

This was like that before in the cross_validation module too. I think we should raise an appropriate error message in both cases (LeavePGroupsOut and LeaveOneGroupOut)?

@amueller @jnothman

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyWell-defined and straightforward way to resolve

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions