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

Scoring for dummy classifier does not work without test samples #11951

Closed
JarnoRFB opened this Issue Aug 30, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@JarnoRFB
Contributor

JarnoRFB commented Aug 30, 2018

When using the Dummy classifier, it is possible to fit the classifier without providing any examples, which makes sense as the classifier only operates on the targets. However, it is not possible to score the classifier without providing examples. Using DummyClassifier without examples is helpful if the examples, but not the targets, are to big to fit into memory. One can still get around this by constructing
artificial examples, say just zeros, but avoiding this would make things a bit easier.

Code to Reproduce

from sklearn.dummy import DummyClassifier
import numpy as np

y = [1, 1, 2]
y_ = [1, 1, 2]

d = DummyClassifier()
d.fit(None, y)
print(d.score(None, y_))

Expected Results

The score is printed.

Actual Results

An exception is thrown

ValueError: Found input variables with inconsistent numbers of samples: [3, 1]

So one has to do

from sklearn.dummy import DummyClassifier
import numpy as np

y = [1, 1, 2]
y_ = [1, 1, 2]
x = np.zeros(shape=(3, 1))

d = DummyClassifier()
d.fit(None, y)
print(d.score(x,  y_))

If this seems like a useful feature, I would be happy to submit a PR.

Versions

Linux-4.15.0-33-generic-x86_64-with-debian-buster-sid
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0]
NumPy 1.14.3
SciPy 1.0.0
Scikit-Learn 0.19.2

@JarnoRFB JarnoRFB changed the title from Scoring for dummy classifier does not work without test samples. to Scoring for dummy classifier does not work without test samples Aug 30, 2018

@jnothman

This comment has been minimized.

Show comment
Hide comment
@jnothman

jnothman Aug 30, 2018

Member
Member

jnothman commented Aug 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment