torcheval.metrics.functional.binary_binned_auroc¶
- torcheval.metrics.functional.binary_binned_auroc(input: Tensor, target: Tensor, *, num_tasks: int = 1, threshold: int | List[float] | Tensor = 200) Tuple[Tensor, Tensor] ¶
计算二分类的 AUROC,即 ROC 曲线下的面积。其类版本为
torcheval.metrics.BinaryBinnedAUROC
。- 参数:
input (Tensor) – 标签预测的张量。它应该是预测标签、概率或 logits,形状为 (num_tasks, n_sample) 或 (n_sample, )。
target (Tensor) – 真实标签的张量,形状为 (num_tasks, n_sample) 或 (n_sample, )。
num_tasks (int) – 需要进行 binary_binned_auroc 计算的任务数量。默认值为 1。每个任务的 binary_binned_auroc 将独立计算。
threshold – 一个表示 bin 数量的整数、一个阈值列表或一个阈值张量。
示例
>>> import torch >>> from torcheval.metrics.functional import binary_binned_auroc >>> input = torch.tensor([0.1, 0.5, 0.7, 0.8]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_binned_auroc(input, target, threshold=5) (tensor(0.5) tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])) >>> input = torch.tensor([0.1, 0.5, 0.7, 0.8]) >>> target = torch.tensor([1, 0, 1, 1]) >>> threshold = tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]) >>> binary_binned_auroc(input, target, threshold=threshold) (tensor(0.5) tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])) >>> 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, threshold=5) (tensor([0.7500, 0.5000], tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))