Skip to content
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: force consistency outputs of DummyClassifier's predict_proba when strategy is stratified #13266

Merged
Merged
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+21 −0
Diff settings

Always

Just for now

Copy path View file
@@ -95,6 +95,14 @@ Support for Python 3.4 and below has been officially dropped.
``n_components`` is changed to ``min(n_features, n_classes - 1)`` if so.
Previously the change was made, but silently. :issue:`11526` by
:user:`William de Vazelhes<wdevazelhes>`.

:mod:`sklearn.dummy`
....................................

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
....................................
....................

- |Fix| Fixed a bug in :class:`dummy.DummyClassifier` where the
``predict_proba`` method was returning int32 array instead of
float64 for the ``stratified`` strategy. :issue:`13266` by
:user:`Christos Aridas<chkoar>`.

:mod:`sklearn.ensemble`
.......................
Copy path View file
@@ -277,6 +277,7 @@ def predict_proba(self, X):

elif self.strategy == "stratified":
out = rs.multinomial(1, class_prior_[k], size=n_samples)
out = out.astype(np.float64)

elif self.strategy == "uniform":
out = np.ones((n_samples, n_classes_[k]), dtype=np.float64)
Copy path View file
@@ -709,3 +709,15 @@ def test_regressor_prediction_independent_of_X(strategy):
predictions2 = reg2.predict(X2)

assert_array_equal(predictions1, predictions2)


@pytest.mark.parametrize(
"strategy", ["stratified", "most_frequent", "prior", "uniform", "constant"]
)
def test_dtype_of_classifier_probas(strategy):
y = [0, 2, 1, 1]
X = np.zeros(4)
model = DummyClassifier(strategy=strategy, random_state=0, constant=0)
probas = model.fit(X, y).predict_proba(X)

assert probas.dtype == np.float64
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.