Closed
Conversation
jnothman
reviewed
Jun 20, 2017
| from .validation import check_array | ||
|
|
||
|
|
||
|
|
Member
There was a problem hiding this comment.
My life wasn't complete without reviewing this part of the PR.
| clf = DummyClassifier(strategy="constant", random_state=0, | ||
| constant=[1]) | ||
| clf.fit(X, y) | ||
| assert_array_equal(clf.predict(X), np.ones((n_samples, 1))) |
Member
There was a problem hiding this comment.
It seems the convention elsewhere is that even when trained on a column vector, predict should return a 1d array:
In [6]: %paste
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
for y in [[0, 1], [[0], [1]]]:
for clf in [LogisticRegression(), RandomForestClassifier(), SVC(probability=True)]:
print(clf.__class__.__name__, y)
clf.fit([[0], [0]], y)
for m in ['predict', 'predict_proba', 'decision_function']:
try:
print(m, getattr(clf, m)([[0], [0]]).shape)
except AttributeError:
pass
## -- End pasted text --
LogisticRegression [0, 1]
predict (2,)
predict_proba (2, 2)
decision_function (2,)
RandomForestClassifier [0, 1]
predict (2,)
predict_proba (2, 2)
SVC [0, 1]
predict (2,)
predict_proba (2, 2)
decision_function (2,)
LogisticRegression [[0], [1]]
/Users/joel/repos/scikit-learn/sklearn/utils/validation.py:547: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
predict (2,)
predict_proba (2, 2)
decision_function (2,)
RandomForestClassifier [[0], [1]]
/Users/joel/anaconda3/envs/scipy3k/bin/ipython:7: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().
from IPython import start_ipython
predict (2,)
predict_proba (2, 2)
SVC [[0], [1]]
/Users/joel/repos/scikit-learn/sklearn/utils/validation.py:547: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
predict (2,)
predict_proba (2, 2)
decision_function (2,)
Member
Author
There was a problem hiding this comment.
Hm I thought for multi-output it was different, but RandomForestClassifier is multi-output. But apparently there's no common test for that? Gah!
Member
|
I'm closing this PR in favor of #20603. It intends to add common test and find a way forward to consistently address the issue. |
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.
Another fix from the estimator tags branch. If
y.shape == (n_samples, 1)master crashes.