Skip to content

Precision Recall and F-score: behavior when all negative #14876

@marctorsoc

Description

@marctorsoc

I've seen these already closed issues (and probably there are more):

#13453
#13143

about the behavior of prec/rec/f1 when both predictions and ground truth are all negatives. See for some discussion about the topic

https://stats.stackexchange.com/questions/8025/what-are-correct-values-for-precision-and-recall-when-the-denominators-equal-0

My opinion is that sklearn should be flexible about this. I agree with having a default behavior of returning 0 + warning, but I would like to have the option to say: For these special cases, if the true positives, false positives and false negatives are all 0, the precision, recall and F1-measure are 1.

I use this in my day-to-day and atm I have a wrapper around these scorers to force this. It's not exactly the same scenario but to simplify assume you're doing named entity recognition (with one entity to make it easy) and want to apply f1-score to each document, and then average them. If a document has no entities and your model gives no entities you would like a perfect score. Unfortunately, the current sklearn scores don't allow you to do that

This is a proposal, and I can do the PR if people here find it useful. My idea is to add a parameter to these scorers so that the default is to raise a warning (and return 0), and the user can set to new modes:

a) raise an error
b) warning + return 1

Please let me know your thoughts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions