Skip to content

[MRG+2] FIX DummyEstimator and a single output 2d input list/array#13545

Merged
NicolasHug merged 15 commits intoscikit-learn:masterfrom
adrinjalali:dummyestimator
Apr 5, 2019
Merged

[MRG+2] FIX DummyEstimator and a single output 2d input list/array#13545
NicolasHug merged 15 commits intoscikit-learn:masterfrom
adrinjalali:dummyestimator

Conversation

@adrinjalali
Copy link
Copy Markdown
Member

Fixes #10786, closes #10926

Assumes the y is 1d if there's only one column to it.

Copy link
Copy Markdown
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@jnothman jnothman left a 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.

@adrinjalali
Copy link
Copy Markdown
Member Author

@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:

DecisionTreeClassifier predict (3,)
DecisionTreeClassifier predict_proba (3, 2)
KNeighborsClassifier predict (3,)
KNeighborsClassifier predict_proba (3, 2)
MLPClassifier predict (3,)
MLPClassifier predict_proba (3, 2)
MultiOutputClassifier predict (3, 1)
MultiOutputClassifier predict_proba [(3, 2)]
OneVsRestClassifier unhashable type: 'list'
DummyClassifier predict (3,)
DummyClassifier predict_proba (3, 2)

Copy link
Copy Markdown
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise lgtm

float64 for the ``stratified`` strategy. :issue:`13266` by
:user:`Christos Aridas<chkoar>`.

- |Fix| Fixed a bug in :class:`dummy.DummyClassifier` where 1d dimensional y
Copy link
Copy Markdown
Member

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"?

Copy link
Copy Markdown
Member Author

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.

@adrinjalali adrinjalali changed the title FIX DummyEstimator and a single output 2d input list/array [MRG+2] FIX DummyEstimator and a single output 2d input list/array Apr 5, 2019
@adrinjalali adrinjalali added this to the 0.21 milestone Apr 5, 2019
Co-Authored-By: adrinjalali <adrin.jalali@gmail.com>
@NicolasHug NicolasHug merged commit f483a70 into scikit-learn:master Apr 5, 2019
@NicolasHug
Copy link
Copy Markdown
Member

Thanks @adrinjalali !

@adrinjalali adrinjalali deleted the dummyestimator branch April 5, 2019 12:24
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Apr 25, 2019
* 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>
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
* 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>
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
* 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>
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

Successfully merging this pull request may close these issues.

DummyClassifier bug with putting arrays into lists

4 participants