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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+18 −0
Diff settings

Always

Just for now

Next

Fix dtype of predict_proba when strategy is stratified

  • Loading branch information...
chkoar committed Feb 25, 2019
commit 6a220c84f8205fdaddef946db1c37fb450034aea
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,20 @@ def test_regressor_prediction_independent_of_X(strategy):
predictions2 = reg2.predict(X2)

assert_array_equal(predictions1, predictions2)


@pytest.mark.parametrize("strategy", [

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
@pytest.mark.parametrize("strategy", [
@pytest.mark.parametrize(
"strategy", ["stratified", "most_frequent", "prior", "uniform", "constant"]
)

If it fits on the 80 characters it would be more compact

"stratified",
"most_frequent",
"prior",
"uniform",
"constant"
])
def test_dtype_of_classifier_probas(strategy):
y = [0, 2, 1, 1]
X = [[0]] * 4

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
X = [[0]] * 4
X = np.zeros(4)
model = DummyClassifier(strategy=strategy, random_state=0, constant=0)
model.fit(X, y)

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
model.fit(X, y)
probas = model.fit(X, y).predict_proba(X)
probas = model.predict_proba(X)

assert probas.dtype == np.float

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
assert probas.dtype == np.float
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.