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
[MRG+2] FIX DummyEstimator and a single output 2d input list/array #13545
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the behaviour of other multioutput estimatiors?
Needs a what's new.
@jnothman borrowing your gist: import warnings
import sklearn
warnings.simplefilter('ignore')
from sklearn import *
X = [[0], [0], [0], [0], [0]]
y_1d = [1, 2, 1, 1, 1]
y = [[1], [2], [1], [1], [1]]
for clf in [tree.DecisionTreeClassifier(),
neighbors.KNeighborsClassifier(),
neural_network.MLPClassifier(),
multioutput.MultiOutputClassifier(linear_model.LogisticRegression()),
multiclass.OneVsRestClassifier(linear_model.LogisticRegression()),
dummy.DummyClassifier(),
]:
try:
clf.fit(X, y)
for method in ['predict', 'decision_function', 'predict_proba']:
if not hasattr(clf, method):
continue
s = getattr(clf, method)(X[-3:])
if hasattr(s, 'shape'):
print(type(clf).__name__, method, s.shape)
else:
print(type(clf).__name__, method, [x.shape for x in s])
except Exception as e:
print(type(clf).__name__, e) The output:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise lgtm
doc/whats_new/v0.21.rst
Outdated
@@ -146,6 +146,10 @@ Support for Python 3.4 and below has been officially dropped. | |||
float64 for the ``stratified`` strategy. :issue:`13266` by | |||
:user:`Christos Aridas<chkoar>`. | |||
|
|||
- |Fix| Fixed a bug in :class:`dummy.DummyClassifier` where 1d dimensional y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"1d dimensional y with ndim=2" makes no sense to me. Do you mean "column vector"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it was a copy paste from the old issue, sorry. Fixed.
Co-Authored-By: adrinjalali <adrin.jalali@gmail.com>
Thanks @adrinjalali ! |
* Add column_or_1d to account for dataframe y * Add test * make the diff cleaner * switched pandas import for 2d array * change test to a simple comparison between 1d and 2d y * flake8 errors in tests * Add warning to acieve consistent behaviour as in other classifiers * Update whats new file * remove redundant code, fix regression * remove unnecessary import * add comment on test * address comments * fix what's new entry * Update doc/whats_new/v0.21.rst Co-Authored-By: adrinjalali <adrin.jalali@gmail.com>
* Add column_or_1d to account for dataframe y * Add test * make the diff cleaner * switched pandas import for 2d array * change test to a simple comparison between 1d and 2d y * flake8 errors in tests * Add warning to acieve consistent behaviour as in other classifiers * Update whats new file * remove redundant code, fix regression * remove unnecessary import * add comment on test * address comments * fix what's new entry * Update doc/whats_new/v0.21.rst Co-Authored-By: adrinjalali <adrin.jalali@gmail.com>
* Add column_or_1d to account for dataframe y * Add test * make the diff cleaner * switched pandas import for 2d array * change test to a simple comparison between 1d and 2d y * flake8 errors in tests * Add warning to acieve consistent behaviour as in other classifiers * Update whats new file * remove redundant code, fix regression * remove unnecessary import * add comment on test * address comments * fix what's new entry * Update doc/whats_new/v0.21.rst Co-Authored-By: adrinjalali <adrin.jalali@gmail.com>
Fixes #10786, closes #10926
Assumes the
y
is 1d if there's only one column to it.