-
-
Notifications
You must be signed in to change notification settings - Fork 26k
MNT Improve error message with implicit pos_label in brier_score_loss #15412
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
Closed
qinhanmin2014
wants to merge
17
commits into
scikit-learn:master
from
qinhanmin2014:brier_score_loss
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
840adc0
FIX Correctly infer pos_label in brier_score_loss
qinhanmin2014 b9d750c
whats new
qinhanmin2014 538317e
Apply suggestions from code review
qinhanmin2014 a8af41f
Merge branch 'master' into brier_score_loss
qinhanmin2014 bf45832
review
qinhanmin2014 de3604b
Merge remote-tracking branch 'upstream/master' into brier_score_loss
qinhanmin2014 6dfde65
new solution
qinhanmin2014 60b65e6
typo
qinhanmin2014 c03f310
address comment
qinhanmin2014 a544fdc
flake8
qinhanmin2014 bc59eda
perhaps better
qinhanmin2014 91e99cf
review
qinhanmin2014 9adb3a5
Merge remote-tracking branch 'upstream/master' into brier_score_loss
qinhanmin2014 a9d84be
consistency with merged PR
qinhanmin2014 8ba6f45
Merge remote-tracking branch 'upstream/master' into pr/15412
thomasjpfan fb199bd
CLN Address comments
thomasjpfan 8635fd8
DOC Adds comment
thomasjpfan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2246,10 +2246,24 @@ def test_brier_score_loss(): | |
assert_almost_equal(brier_score_loss([-1], [0.4]), 0.16) | ||
assert_almost_equal(brier_score_loss([0], [0.4]), 0.16) | ||
assert_almost_equal(brier_score_loss([1], [0.4]), 0.36) | ||
assert_almost_equal( | ||
brier_score_loss(['foo'], [0.4], pos_label='bar'), 0.16) | ||
assert_almost_equal( | ||
brier_score_loss(['foo'], [0.4], pos_label='foo'), 0.36) | ||
|
||
# make sure the positive class is correctly inferred | ||
y_true = np.array([0, 1, 1, 0]) | ||
y_pred = np.array([0.8, 0.6, 0.4, 0.2]) | ||
score1 = brier_score_loss(y_true, y_pred, pos_label=1) | ||
score2 = brier_score_loss(y_true, y_pred) | ||
assert score1 == pytest.approx(score2) | ||
y_true = np.array(["neg", "pos", "pos", "neg"]) | ||
# raise error when y_true contains strings and pos_label is not specified | ||
with pytest.raises(ValueError, match="pos_label must be specified"): | ||
brier_score_loss(y_true, y_pred) | ||
score2 = brier_score_loss(y_true, y_pred, pos_label="pos") | ||
assert score1 == pytest.approx(score2) | ||
|
||
# positive class if correctly inferred an object array with all ints | ||
y_pred_num_obj = np.array([0, 1, 1, 0], dtype=object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case was added which was enabled by #15412 (comment) and with this fb199bd diff |
||
score3 = brier_score_loss(y_pred_num_obj, y_pred) | ||
assert score1 == pytest.approx(score3) | ||
|
||
|
||
def test_balanced_accuracy_score_unseen(): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this?