快捷方式

torcheval.metrics.functional.binary_f1_score

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

计算二元 F1 分数,即精确率和召回率的调和平均数。

参数:
  • 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_f1_score
>>> input = torch.tensor([0, 1, 0.7, 0.6])
>>> target = torch.tensor([0, 1, 1, 0])
>>> binary_f1_score(input, target, threshold=0.5)
tensor(0.8000)

>>> input = torch.tensor([1, 1, 0, 0])
>>> target = torch.tensor([0, 1, 1, 1])
>>> binary_f1_score(input, target, threshold=1)
tensor(0.4000)

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源