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。- Parameters:
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 – 一个整数,表示分箱的数量,一个阈值列表,或一个阈值张量。
示例:
>>> 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]))