快捷方式

torcheval.metrics.functional.binary_precision

torcheval.metrics.functional.binary_precision(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor

计算二元分类类的精确度分数,它被计算为真阳性 (TP) 数量与预测阳性总数 (TP + FP) 之间的比率。它的类版本是 torcheval.metrics.BinaryPrecision

参数::
  • input (Tensor) – 标签预测的张量 它可以是预测的标签,形状为 (n_sample, )。 torch.where(input < threshold, 0, 1) 将应用于输入。

  • target (Tensor) – 形状为 (n_sample,) 的真值标签张量。

  • threshold (float, default 0.5) – 用于将输入转换为每个样本的预测标签的阈值。

示例

>>> import torch
>>> from torcheval.metrics.functional import binary_precision
>>> input = torch.tensor([0, 0, 1, 1])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_precision(input, target)
tensor(1.)  # 2 / 2

>>> metric = BinaryPrecision(threshold=0.7)
>>> input = torch.tensor([0, 0.8, 0.6, 0.7])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_precision(input, target)
tensor(0.5)  # 1 / 2

文档

获取 PyTorch 的全面的开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源