-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Description
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