Compute the BinaryAUROC metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute BinaryAUROC, or asks how to score with BinaryAUROC.
Installs into .claude/skills of the current project.
Are you the author of Binaryauroc?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-binaryauroc)
---
name: binaryauroc
description: Compute the BinaryAUROC metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute BinaryAUROC, or asks how to score with BinaryAUROC.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.classification.BinaryAUROC
source: library_introspection
---
# binaryauroc
> Metric `BinaryAUROC` from `torchmetrics` (torchmetrics.classification.BinaryAUROC)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with BinaryAUROC, or
mentions `torchmetrics.classification.BinaryAUROC` directly, or wants the standard torchmetrics implementation.
## Reference signature
```python
from torchmetrics.classification import BinaryAUROC
# BinaryAUROC(max_fpr: Optional[float] = None, thresholds: Union[int, list[float], torch.Tensor, NoneType] = None, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> None
```
## Library docstring
```
Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for binary tasks.
The AUROC score summarizes the ROC curve into an single number that describes the performance of a model for
multiple thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
corresponds to random guessing.
As input to ``forward`` and ``update`` the metric accepts the following input:
- ``preds`` (:class:`~torch.Tensor`): A float tensor of shape ``(N, ...)`` containing probabilities or logits for
each observation. If preds has values outside [0,1] range we consider the input to be logits and will auto apply
sigmoid per element.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)`` containing ground truth labels, and
therefore only contain {0,1} values (except if `ignore_index` is specified). The value 1 always encodes the
positive class.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``b_auroc`` (:class:`~torch.Tensor`): A single scalar with the auroc score.
Additional dimension ``...`` will be flattened into the batch dimension.
The implementation both supports calculating the metric in a non-binned but accurate version and a
binned version that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will
activate the non-binned version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the
`thresholds` argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
size :math:`\mathcal{O}(n_{thresholds})` (constant memory).
Args:
max_fpr: If not ``None``, calculates standardized partial AUC over the range ``[0, max_fpr]``.
thresholds:
Can be one of:
- If set to `None`, will use a non-binned approach where thresholds are dynamically calculated from
all the data. Most accurate but also most memory consuming approach.
- If set to an `int` (larger than 1), will use that number of thresholds linearly spaced from
0 to 1 as bins for the calculation.
- If set to an `list` of floats, will use the indicated thres
```
## Quick recipe
```python
import torchmetrics.classification as _m
score = _m.BinaryAUROC(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)`.