-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG + 1] Sort labels in precision_recall_fscore_support #4147
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 + 1] Sort labels in precision_recall_fscore_support #4147
Conversation
I guess this is also fixed in #2610 but I'm not sure what the state of that is.... (actually not sure, but definitely related) |
4e5221b
to
b2ffd3e
Compare
I've not looked at the fix, but I think you should probably do so, even if I get #2610 up... |
@@ -303,6 +303,18 @@ def test_precision_recall_f1_score_multiclass(): | |||
assert_array_equal(s, [24, 20, 31]) | |||
|
|||
|
|||
def test_precision_refcall_f1_score_multilabel_unordered_labels(): |
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.
Might as well test this in the multiclass case and for different averaging strategies, too, no?
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.
Sure, will add.
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.
This could be made into an invariant tests.
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.
I'll look into it.
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.
If I use average="sample"
then support is None
. Is that expected?
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.
I guess it is...
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.
Yes, it is.
Thanks @amueller |
Was that a 👍 @arjoly ? ;) |
@@ -847,7 +847,7 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None, | |||
if labels is None: | |||
labels = unique_labels(y_true, y_pred) | |||
else: | |||
labels = np.asarray(labels) | |||
labels = np.sort(labels) |
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.
Is there a regression test for this?
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.
Don't take this comment into account. :-)
Besides Joel comment and my small addendum, +1 |
@arjoly I tried import numpy as np
y_true = np.array([[1, 1, 0, 0], [1, 1, 0, 0]])
y_pred = np.array([[0, 0, 1, 1], [0, 1, 1, 0]])
labels = np.array([4, 1, 2, 3])
for name in set(MULTILABELS_METRICS).intersection(METRICS_WITH_LABELS):
metric = ALL_METRICS[name]
score_labels = metric(y_true, y_pred, labels=labels)
score = metric(y_true, y_pred)
assert_equal(score_labels, score) but that already passes on master, I'm not sure why :-/ |
Shouldn't the same problem pop up in |
e2abb81
to
bfea61c
Compare
Ok, never mind, forgot to add |
bfea61c
to
3566167
Compare
3566167
to
fd9b03a
Compare
FIX Sort labels in precision_recall_fscore_support
Great thanks @amueller ! |
def test_no_averaging_labels(): | ||
# test labels argument when not using averaging | ||
# in multi-class and multi-label cases | ||
y_true_multilabel = np.array([[1, 1, 0, 0], [1, 1, 0, 0]]) |
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.
Why are you referencing label 4
when the only labels available are 0, 1, 2, 3
? It's a wonder that this works... Or rather, it's no surprise this breaks #4287...
Fixes #3670.
The code already stores and restores the ordering, so we can discard it here.