Skip to content

fix(pr-curve): set precision to NaN when TP+FP == 0#3227

Merged
Borda merged 6 commits into
Lightning-AI:masterfrom
iamkulbhushansingh:fix/pr-curve-nan-precision
Aug 15, 2025
Merged

fix(pr-curve): set precision to NaN when TP+FP == 0#3227
Borda merged 6 commits into
Lightning-AI:masterfrom
iamkulbhushansingh:fix/pr-curve-nan-precision

Conversation

@iamkulbhushansingh

@iamkulbhushansingh iamkulbhushansingh commented Aug 13, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Completely Fixes #2873

Before submitting
  • [x ] Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • [x ] Did you read the contributor guideline, Pull Request section?
  • [ x] Did you make sure to update the docs?
  • [x ] Did you write any new necessary tests?

Summary

This change updates BinaryPrecisionRecallCurve so that when no predictions meet a given threshold (TP + FP = 0), precision is returned as NaN (undefined) while recall remains at 0.0.
This reflects the mathematically correct definitions for these metrics and avoids misleading (0, 0) points caused by forced zero precision.


Motivation

Previously, when no predictions met the threshold, both precision and recall were set to 0.0.

  • Precision in this case is undefined because the denominator (TP + FP) is zero, and returning 0.0 is misleading.
  • Recall, however, remains well-defined as 0.0 since the denominator (TP + FN) is non-zero.

By returning NaN for precision, users can filter out these undefined points in PR curve analysis while retaining meaningful recall values.


Did you have fun?

💯


📚 Documentation preview 📚: https://torchmetrics--3227.org.readthedocs.build/en/3227/

iamkulbhushansingh added a commit to iamkulbhushansingh/torchmetrics that referenced this pull request Aug 13, 2025
@iamkulbhushansingh
iamkulbhushansingh force-pushed the fix/pr-curve-nan-precision branch from dcb4197 to 011096f Compare August 13, 2025 20:29
@iamkulbhushansingh
iamkulbhushansingh marked this pull request as draft August 13, 2025 20:33
@iamkulbhushansingh
iamkulbhushansingh marked this pull request as ready for review August 15, 2025 10:53
@codecov

codecov Bot commented Aug 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 40%. Comparing base (58249cb) to head (7d1a69d).
⚠️ Report is 32 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (58249cb) and HEAD (7d1a69d). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (58249cb) HEAD (7d1a69d)
gpu 2 0
unittest 2 0
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #3227     +/-   ##
========================================
- Coverage      69%     40%    -28%     
========================================
  Files         364     349     -15     
  Lines       20073   19882    -191     
========================================
- Hits        13788    7993   -5795     
- Misses       6285   11889   +5604     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mergify mergify Bot added the ready label Aug 15, 2025
@Borda
Borda merged commit e286bf7 into Lightning-AI:master Aug 15, 2025
63 checks passed
Borda added a commit that referenced this pull request Sep 3, 2025
* fix(pr-curve): set precision to NaN when TP+FP == 0
* fixed average precision affected due to precision recall curve
* fix doctest for precision recall curve
* updated chlog

---------

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit e286bf7)
Borda added a commit that referenced this pull request Sep 3, 2025
* fix(pr-curve): set precision to NaN when TP+FP == 0
* fixed average precision affected due to precision recall curve
* fix doctest for precision recall curve
* updated chlog

---------

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit e286bf7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report nan in PR curve above max threshold

2 participants