torcheval.metrics.functional.binary_auroc¶
- torcheval.metrics.functional.binary_auroc(input: Tensor, target: Tensor, *, num_tasks: int = 1, weight: Tensor | None = None, use_fbgemm: bool | None = False) Tensor ¶
计算 AUROC,它是二元分类中 ROC 曲线下的面积。其类版本为
torcheval.metrics.BinaryAUROC
。- 参数:
input (Tensor) – 标签预测的张量。它应该是预测标签、概率或对数,形状为 (num_tasks, n_sample) 或 (n_sample, )。
target (Tensor) – 形状为 (num_tasks, n_sample) 或 (n_sample, ) 的真实标签张量。
num_tasks (int) – 需要计算二元 AUROC 的任务数。默认值为 1。将独立计算每个任务的二元 AUROC。
weight (Tensor) – 可选。手动重新缩放权重,以匹配输入张量形状 (num_tasks, num_samples) 或 (n_sample, )。
use_fbgemm (bool) – 可选。如果设置为 True,则使用
fbgemm_gpu.metrics.auc
(手工融合内核)。FBGEMM AUC 是 AUC 的近似值。如果输入值是冗余的,它不会屏蔽数据。对于高度冗余的输入情况,FBGEMM AUC 可能会给出明显不同的结果。
示例
>>> import torch >>> from torcheval.metrics.functional import binary_auroc >>> input = torch.tensor([0.1, 0.5, 0.7, 0.8]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_auroc(input, target) tensor(0.6667) >>> input = torch.tensor([1, 1, 1, 0]) >>> target = torch.tensor([1, 0, 1, 0]) >>> binary_auroc(input, target) tensor(0.7500) >>> input = torch.tensor([[1, 1, 1, 0], [0.1, 0.5, 0.7, 0.8]]) >>> target = torch.tensor([[1, 0, 1, 0], [1, 0, 1, 1]]) >>> binary_auroc(input, target, num_tasks=2) tensor([0.7500, 0.6667])