# Binaryspecificityatsensitivity

> Compute the BinarySpecificityAtSensitivity metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute BinarySpecificityAtSensitivity, or asks how to score with BinarySpecificityAtSensitivity.

- Skill: `qhjqhj00/binaryspecificityatsensitivity` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/binaryspecificityatsensitivity`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/binaryspecificityatsensitivity/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/binaryspecificityatsensitivity

---


# binaryspecificityatsensitivity

> Metric `BinarySpecificityAtSensitivity` from `torchmetrics` (torchmetrics.classification.BinarySpecificityAtSensitivity)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with BinarySpecificityAtSensitivity, or
mentions `torchmetrics.classification.BinarySpecificityAtSensitivity` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.classification import BinarySpecificityAtSensitivity

# BinarySpecificityAtSensitivity(min_sensitivity: float, thresholds: Union[int, list[float], torch.Tensor, NoneType] = None, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> None
```

## Library docstring

```
Compute the highest possible specificity value given the minimum sensitivity thresholds provided.

This is done by first calculating the Receiver Operating Characteristic (ROC) curve for different thresholds and the
find the specificity for a given sensitivity level.

Accepts the following input tensors:

- ``preds`` (float tensor): ``(N, ...)``. Preds should be a tensor 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`` (int tensor): ``(N, ...)``. Target should be a tensor containing ground truth labels, and therefore
  only contain {0,1} values (except if `ignore_index` is specified).

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:
    min_sensitivity: float value specifying minimum sensitivity threshold.
    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 thresholds in the list as bins for the calculation
        - If set to an 1d `tensor` of floats, will use the indicated thresholds in the tensor as
          bins for the calculation.

    validate_args: bool indicating if input arguments and tensors should be validated for correctness.
        Set to ``False`` for faster computations.
    kwargs: Additional keyword arguments
```

## Quick recipe

```python
import torchmetrics.classification as _m
score = _m.BinarySpecificityAtSensitivity(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)`.

