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。- Parameters:
input (Tensor) – 标签预测的张量 它应该是预测的标签、概率或logits,形状为(num_tasks, n_sample)或(n_sample, )。
target (Tensor) – 形状为 (num_tasks, n_sample) 或 (n_sample, ) 的真实标签张量。
num_tasks (int) – 需要进行BinaryAUROC计算的任务数量。默认值为1。每个任务的BinaryAUROC将独立计算。
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])