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

Update class metrics interface of Precision/Recall/Fbeta to allow calculate them for each individual class #55

Closed
junwen-austin opened this issue Nov 20, 2020 · 4 comments · Fixed by #111
Assignees
Labels
help wanted Extra attention is needed

Comments

@junwen-austin
Copy link

🚀 Feature

I'd like to propose to update class metrics interface of Precision/Recall/Fbeta to have the average argument include none and weighted as in the corresponding functional metrics interface.

Motivation

Current interface with average argument restricts to macro and micro, and because of that one could not use class metrics interface to calculate precision/recall/fbeta for an individual class. For example, in binary classification, one is typically interested in getting metrics results for positive class (class 1) and this cannot be done with the current class interface. Therefore one has go back to the functional metric and this could defeat the purpose of having class metrics (to take care of ddp sync).

On the contrary, sklearn defaults to calculate precision/recall/fbeta for the individual class (class 1) while giving one option to calculate micro/macro/weighted average of these scores.
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html

Pitch

Update class metrics interface of Precision/Recall/Fbeta to have the average argument include none and weighted as in the corresponding functional metrics interface.

Alternatives

One can always fall back to the functional metric but I assume this is not what we would like.

Additional context

Really like the new class interface to work with DDP and appreciate all your work!

@SkafteNicki
Copy link
Member

The Fbeta metric will get that feature when this PR is merged:
Lightning-AI/pytorch-lightning#4656
When that is merged I plan on dealing with precision and recall

@junwen-austin
Copy link
Author

@SkafteNicki Thanks for the update. Any idea approximately when this feature (including for precision/recall/Fbeta) would be available?

@SkafteNicki
Copy link
Member

I was hoping to get it all done for the 1.1 release :]

@shijianjian
Copy link

shijianjian commented Dec 3, 2020

Got one question here.

For code like:
https://github.com/SkafteNicki/pytorch-lightning/blob/9d5b505f90e8d622a033666c3dbe2f0cc6ee5f26/pytorch_lightning/metrics/classification/precision_recall.py#L199-L205

It is computing the one-hot vector, which means to convert [0, 1] to [[1, 0], [0, 1]]. While in a binary case, it would put both negative and positive values into account (as true_positives as written in the code). So, I would say it will produce the wrong results for binary classification, right?

This issue somehow reported in Lightning-AI/pytorch-lightning#3035, but the reduction='none' is remaining unimplemented for the Precision and Recall classes.

I think an easy implementation of it is to have another param to set pos_labels=[0], which can receive n labels as well. I think it can be pretty helpful for both binary and multi-class classification.

@Borda Borda transferred this issue from Lightning-AI/pytorch-lightning Mar 12, 2021
@Borda Borda added the help wanted Extra attention is needed label Mar 17, 2021
@Lightning-AI Lightning-AI deleted a comment from github-actions bot Mar 17, 2021
@SkafteNicki SkafteNicki mentioned this issue Mar 19, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants