Compute the PrecisionRecallCurve metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute PrecisionRecallCurve, or asks how to score with PrecisionRecallCurve.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill precisionrecallcurve --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Precisionrecallcurve?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-precisionrecallcurve)More formats (shields.io, HTML) on the badges page.
---
name: precisionrecallcurve
description: Compute the PrecisionRecallCurve metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute PrecisionRecallCurve, or asks how to score with PrecisionRecallCurve.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.PrecisionRecallCurve
source: library_introspection
---
# precisionrecallcurve
> Metric `PrecisionRecallCurve` from `torchmetrics` (torchmetrics.PrecisionRecallCurve)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with PrecisionRecallCurve, or
mentions `torchmetrics.PrecisionRecallCurve` directly, or wants the standard torchmetrics implementation.
## Reference signature
```python
from torchmetrics import PrecisionRecallCurve
# PrecisionRecallCurve(task: Literal['binary', 'multiclass', 'multilabel'], thresholds: Union[int, list[float], torch.Tensor, NoneType] = None, num_classes: Optional[int] = None, num_labels: Optional[int] = None, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> torchmetrics.metric.Metric
```
## Library docstring
```
Compute the precision-recall curve.
The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
tradeoff between the two values can been seen.
This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the
``task`` argument to either ``'binary'``, ``'multiclass'`` or ``'multilabel'``. See the documentation of
:class:`~torchmetrics.classification.BinaryPrecisionRecallCurve`,
:class:`~torchmetrics.classification.MulticlassPrecisionRecallCurve` and
:class:`~torchmetrics.classification.MultilabelPrecisionRecallCurve` for the specific details of each argument
influence and examples.
Legacy Example:
>>> pred = torch.tensor([0, 0.1, 0.8, 0.4])
>>> target = torch.tensor([0, 1, 1, 0])
>>> pr_curve = PrecisionRecallCurve(task="binary")
>>> precision, recall, thresholds = pr_curve(pred, target)
>>> precision
tensor([0.5000, 0.6667, 0.5000, 1.0000, 1.0000])
>>> recall
tensor([1.0000, 1.0000, 0.5000, 0.5000, 0.0000])
>>> thresholds
tensor([0.0000, 0.1000, 0.4000, 0.8000])
>>> pred = torch.tensor([[0.75, 0.05, 0.05, 0.05, 0.05],
... [0.05, 0.75, 0.05, 0.05, 0.05],
... [0.05, 0.05, 0.75, 0.05, 0.05],
... [0.05, 0.05, 0.05, 0.75, 0.05]])
>>> target = torch.tensor([0, 1, 3, 2])
>>> pr_curve = PrecisionRecallCurve(task="multiclass", num_classes=5)
>>> precision, recall, thresholds = pr_curve(pred, target)
>>> precision
[tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 0.0000, 1.0000]),
tensor([0.2500, 0.0000, 1.0000]), tensor([0., 1.])]
>>> recall
[tensor([1., 1., 0.]), tensor([1., 1., 0.]), tensor([1., 0., 0.]), tensor([1., 0., 0.]), tensor([nan, 0.])]
>>> thresholds
[tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]),
tensor(0.0500)]
```
## Quick recipe
```python
import torchmetrics as _m
score = _m.PrecisionRecallCurve(y_true, y_pred)
```
## Don'ts
- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!