Shortcuts

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

Parameters:
  • 输入 (张量) – 标签预测的张量 它可以是预测的标签,形状为 (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