Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vjoshi253
Copy link
Contributor

Reference Issues/PRs

This PR fixes the issue #27927.

What does this implement/fix? Explain your changes.

There is an incosistency between the calculation of the micro-average in the code as compared to what the doc mentions.
The doc mentions that:

Micro average (averaging the total true positives, false negatives and false positives) is only shown for multi-label or multi-class with a subset of classes.

But the code even gives the micro-average for superset cases.

The fix is code is quite trivial and makes the code and documentation consistent.

Any other comments?

The author of the issue shared some reproduction steps and the expected output. This fix is able to get to the expected output.

print(classification_report([0, 1], [1, 0], labels=[0, 1, 2], zero_division=0.0))

Output:

image

@github-actions
Copy link

github-actions bot commented Feb 10, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 92520d5. Link to the linter CI: here

@glemaitre
Copy link
Member

We also need a non-regression test to check that we have the expected behaviour and entry in the changelog to acknowledge the bug fix.

@glemaitre glemaitre changed the title Fixed micro-average calculation bug in "classification_report" metric. FIX show only accuracy when having a subset of labels in classification report Feb 12, 2024
@vjoshi253
Copy link
Contributor Author

@glemaitre Updated as per suggested.

@glemaitre glemaitre self-requested a review February 19, 2024 10:02
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some comments.

:class:`~metrics.PrecisionRecallDisplay`, :class:`~metrics.DetCurveDisplay`,
:class:`~calibration.CalibrationDisplay`.
:pr:`28051` by :user:`Pierre de Fréminville <pidefrem>`.
- |Fix|:class:`metrics.classification_report` now shows only accuracy and not micro-average when input is a subset of labels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need to be moved in 1.4 under the 1.4.2 changelog. We will include it in the next bug fix release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make sure that you entry is less than 88 characters also in the changelog.



def test_classification_report_input_subset_of_labels():
y_true, y_pred = [0, 1], [0, 1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we want a slightly different test isntead: we want that different input in labels show or not the "accuracy". So we could parametrize the test by trying labels=([0, 1, 2], [0, 1], [0]).

@glemaitre glemaitre self-requested a review March 4, 2024 18:02
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the test just to check for the present key as this is the issue reported and I moved the entry in the right changelog as requested.

@glemaitre glemaitre added the Waiting for Second Reviewer First reviewer is done, need a second one! label Mar 4, 2024
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I move the what's new entry to target 1.5. 1.4.2

LGTM. Thanks @vjoshi253

@jeremiedbb jeremiedbb added this to the 1.4.2 milestone Mar 5, 2024
@jeremiedbb jeremiedbb added To backport PR merged in master that need a backport to a release branch defined based on the milestone. and removed Waiting for Second Reviewer First reviewer is done, need a second one! labels Mar 5, 2024
@jeremiedbb jeremiedbb enabled auto-merge (squash) March 5, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:metrics To backport PR merged in master that need a backport to a release branch defined based on the milestone.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants