FPRx#
- class torch_uncertainty.metrics.classification.FPRx(recall_level, pos_label, **kwargs)[source]#
Compute the False Positive Rate at x% Recall.
The False Positive Rate at x% Recall (FPR@x) is used in anomaly detection, out-of-distribution (OOD) detection, and binary classification. It measures the proportion of false positives (normal samples misclassified as anomalies) when the model reaches a specified recall level for the positive class.
Formally, let \(\tau_x\) be the threshold such that the true positive rate equals the target recall level \(x\):
\[\tau_x = \inf \left\{ \tau \;\middle|\; \frac{|\{i : s_i \geq \tau,\, y_i = 1\}|}{|\{i : y_i = 1\}|} \geq x \right\},\]where \(s_i\) is the confidence score assigned to sample \(i\) and \(y_i \in \{0, 1\}\) is its label. The metric is then
\[\text{FPR}@x = \frac{|\{i : s_i \geq \tau_x,\, y_i = 0\}|}{|\{i : y_i = 0\}|}.\]- Parameters:
recall_level (
float) – The recall level at which to compute the FPR.pos_label (
int) – The positive label.kwargs – Additional keyword arguments for the metric class.
- Reference:
Improved from anomaly-seg and translated to torch.
Example
from torch_uncertainty.metrics.classification import FPRx # Initialize the metric with 95% recall and positive label as 1 (e.g., OOD) metric = FPRx(recall_level=0.95, pos_label=1) # Simulated model predictions (confidence scores) and ground-truth labels confidences = torch.tensor([0.9, 0.8, 0.7, 0.6, 0.4, 0.2, 0.1]) targets = torch.tensor([1, 0, 1, 0, 0, 1, 0]) # 1: OOD, 0: In-Distribution # Update the metric with predictions and labels metric.update(confidences, targets) # Compute FPR at 95% recall result = metric.compute() print(f"FPR at 95% Recall: {result.item()}") # output: FPR at 95% Recall: 0.75