快捷方式

torcheval.metrics.BinaryBinnedAUROC

class torcheval.metrics.BinaryBinnedAUROC(*, num_tasks: int = 1, threshold: int | List[float] | Tensor = 200, device: device | None = None)

计算 AUROC,它是 ROC 曲线下的面积,用于二元分类。其函数式版本为 torcheval.metrics.functional.binary_binned_auroc()

参数:
  • num_tasks (int) – 需要计算二元分箱 AUROC 的任务数量。默认值为 1。每个任务的二元分箱 AUROC 将独立计算。

  • threshold – 表示箱子数量的整数、阈值的列表或阈值的张量。

示例

>>> import torch
>>> from torcheval.metrics import BinaryBinnedAUROC
>>> input = torch.tensor([0.1, 0.5, 0.7, 0.8])
>>> target = torch.tensor([1, 0, 1, 1])
>>> metric = BinaryBinnedAUROC(threshold=5)
>>> metric.update(input, target)
>>> metric.compute()
(tensor([0.5000]),
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
)
>>> input = torch.tensor([1, 1, 1, 0])
>>> target = torch.tensor([1, 1, 1, 0])
>>> metric.update(input, target)
>>> metric.compute()
(tensor([1.0]),
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
)
>>> metric = BinaryBinnedAUROC(num_tasks=2, threshold=5)
>>> 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]])
>>> metric.update(input, target)
>>> metric.compute()
(tensor([0.7500, 0.5000]),
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]
)
)
__init__(*, num_tasks: int = 1, threshold: int | List[float] | Tensor = 200, device: device | None = None) None

初始化一个指标对象及其内部状态。

使用 self._add_state() 初始化指标类的状态变量。状态变量应为 torch.Tensortorch.Tensor 列表、以 torch.Tensor 作为值的字典或 torch.Tensor 的双端队列。

方法

__init__(*[, num_tasks, threshold, device])

初始化一个指标对象及其内部状态。

compute()

返回分箱 AUROC。

load_state_dict(state_dict[, strict])

从 state_dict 加载指标状态变量。

merge_state(metrics)

实现此方法以更新当前指标的状态变量,使其成为当前指标和输入指标的合并状态。

reset()

将指标状态变量重置为其默认值。

state_dict()

将指标状态变量保存在 state_dict 中。

to(device, *args, **kwargs)

将指标状态变量中的张量移动到设备上。

update(input, target)

使用真实标签和预测更新状态。

属性

device

上次输入设备 Metric.to()

文档

获取 PyTorch 的全面开发者文档

查看文档

教程

获取初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得问题解答

查看资源