Skip to content

Fix RetrievalPrecisionRecallCurve axis labels and swap axis#3404

Open
carandraug wants to merge 7 commits into
Lightning-AI:masterfrom
carandraug:3403-pr-curve-labels
Open

Fix RetrievalPrecisionRecallCurve axis labels and swap axis#3404
carandraug wants to merge 7 commits into
Lightning-AI:masterfrom
carandraug:3403-pr-curve-labels

Conversation

@carandraug

Copy link
Copy Markdown

What does this PR do?

Fixes #3403 .

Somehow, the plots for retrieval precision recall curves evolved to label the axis True and False positive rates (TPR and FPR). These are the same labels used in ROCs. There are three isues: the label FPR is wrong (precision and FPR are not the same thing), it is weird to use TPR (TPR and Recall are the same) as label name if the other label name is Precision, it is odd to use Precision on the x axis. This PR addresses the three things (the first two issues in the first commit), the third issue in the second commit).

I think the reason we ended up in this situation is (repeated here from the commit messages in this PR):

It seems this issue was originally introduced as part of #1623 when
the plot method was first added using plot_binary_roc_curve. ROCs do
plot TPR against FPR. I'm guessing that when plot_binary_roc_curve
was replaced with plot_curve in #1660, those wrong labels were kept.

and

It is standard to use Recall on the x axis and Precision on the y axis
but the current implementation has it flipped. This is possibly
because the implementation evolved (incorrectly) from ROCs where TPR
(aka Recall) is on the y axis and FPR on the x axis.

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

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

…ghtning-AI#3403)

While "True positive rate" is the same as "Recall", "False positive
rate" is not the same as "Precision".  Still, this commit change both
axis labels for consistency.

It seems this issue was originally introduced as part of Lightning-AI#1623 when
the plot method was first added using plot_binary_roc_curve.  ROCs do
plot TPR against FPR.  I'm guessing that when plot_binary_roc_curve
was replaced with plot_curve in Lightning-AI#1660, those wrong labels were kept.
…ning-AI#3403)

It is standard to use Recall on the x axis and Precision on the y axis
but the current implementation has it flipped.  This is possibly
because the implementation evolved (incorrectly) from ROCs where TPR
(aka Recall) is on the y axis and FPR on the x axis.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the RetrievalPrecisionRecallCurve.plot() visualization to correctly present a precision–recall curve, aligning both axis labels and axis orientation with standard PR-curve conventions and with TorchMetrics’ classification PR-curve plotting.

Changes:

  • Swap plotted axes so Recall is on the x-axis and Precision is on the y-axis.
  • Correct axis labels from ROC terminology (FPR/TPR) to PR terminology (Recall/Precision).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/torchmetrics/retrieval/precision_recall_curve.py Outdated
Comment thread src/torchmetrics/retrieval/precision_recall_curve.py
@codecov-commenter

codecov-commenter commented Jun 6, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 31%. Comparing base (d184220) to head (08dcc13).
⚠️ Report is 7 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

❗ There is a different number of reports uploaded between BASE (d184220) and HEAD (08dcc13). Click for more details.

HEAD has 792 uploads less than BASE
Flag BASE (d184220) HEAD (08dcc13)
torch2.0.1+cpu 20 2
python3.10 129 12
Windows 30 3
cpu 218 20
torch2.9.1 9 0
macOS 39 3
python3.12 89 8
torch2.9.1+cpu 30 3
torch2.8.0+cpu 30 3
torch2.8.0 10 1
Linux 149 14
torch2.10.0 10 1
torch2.7.1+cpu 20 2
torch2.10.0+cpu 20 2
torch2.4.1+cpu 10 0
torch2.2.2+cpu 10 1
torch2.1.2+cpu 10 1
torch2.5.1+cpu 10 1
torch2.0.1 10 1
torch2.3.1+cpu 9 1
torch2.6.0+cpu 10 1
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #3404     +/-   ##
========================================
- Coverage      37%     31%     -6%     
========================================
  Files         349     349             
  Lines       19901   19906      +5     
========================================
- Hits         7264    6169   -1095     
- Misses      12637   13737   +1100     
🚀 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 Jun 8, 2026
@mergify mergify Bot requested a review from a team June 8, 2026 04:42
Borda and others added 4 commits June 10, 2026 14:50
Mirror classification PR-curve pattern: assign curve_computed before
swapping axis order and add comment explaining the swap convention.

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Guard against regressions in the axis label fix from issue Lightning-AI#3403.

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda Borda enabled auto-merge (squash) June 10, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torchmetrics.retrieval.RetrievalPrecisionRecallCurve plots precision calls it False Positive Rate

5 participants