Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amueller opened this issue Sep 12, 2017 · 1 comment
Closed

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

amueller opened this issue Sep 12, 2017 · 1 comment

Comments

@amueller
Copy link
Member

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.

@amueller
Copy link
Member Author

ah, multi-label y will actually default to KFold, but because

from sklearn.utils.multiclass import type_of_target
type_of_target(y.reshape(-1, 1))

'multiclass'

we're using StratifiedKFold here but don't convert y.

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

No branches or pull requests

1 participant