快捷方式

torcheval.metrics.functional.binary_accuracy

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

计算二元准确率得分,即输入与目标匹配的频率。它的类版本是 torcheval.metrics.BinaryAccuracy

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

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

  • threshold (float, default 0.5) – 用于将输入转换为每个样本的预测标签的阈值。 torch.where(input < threshold, 0, 1) 将应用于 input

示例

>>> import torch
>>> from torcheval.metrics.functional import binary_accuracy
>>> input = torch.tensor([0, 0, 1, 1])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_accuracy(input, target)
tensor(0.75)  # 3 / 4

>>> input = torch.tensor([0, 0.2, 0.6, 0.7])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_accuracy(input, target, threshold=0.7)
tensor(0.5)  # 2 / 4

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

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

查看资源