Skip to content

GridSearchCV (or rather check_cv) doesn't handle 2d y #9742

@amueller

Description

@amueller

Via #9741.

from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_blobs
X, y = make_blobs()

grid = GridSearchCV(LogisticRegression(), {'C': [.1, 1]})
grid.fit(X, y.reshape(-1, 1))

IndexError: too many indices for array

While

from sklearn.model_selection import KFold
grid = GridSearchCV(LogisticRegression(), {'C': [.1, 1]}, cv=KFold(3))
grid.fit(X, y.reshape(-1, 1))

works and raises DataConversionWarning.
I'm pretty sure using multi-label y will also crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions