Shortcuts

torcheval.metrics.functional.binary_precision_recall_curve

torcheval.metrics.functional.binary_precision_recall_curve(input: Tensor, target: Tensor) Tuple[Tensor, Tensor, Tensor]

返回二分类任务的精确率-召回率对及其对应的阈值。如果目标张量中缺少某个类别,则其召回率值设置为1.0。

它的类版本是 torcheval.metrics.BinaryPrecisionRecallCurve

Parameters:
  • input (Tensor) – 标签预测的张量 它应该是形状为 (n_sample, ) 的概率或对数几率。

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

Returns:

  • precision (Tensor): 精度结果的张量。其形状为 (n_thresholds + 1, )

  • recall (Tensor): 召回率结果的张量。其形状为 (n_thresholds + 1, )

  • thresholds (Tensor): 阈值的张量。其形状为 (n_thresholds, )

Return type:

元组

示例:

>>> import torch
>>> from torcheval.metrics.functional import binary_precision_recall_curve
>>> input = torch.tensor([0.1, 0.5, 0.7, 0.8])
>>> target = torch.tensor([0, 0, 1, 1])
>>> binary_precision_recall_curve(input, target)
(tensor([0.5000, 0.6667, 1.0000, 1.0000, 1.0000]),
tensor([1.0000, 1.0000, 1.0000, 0.5000, 0.0000]),
tensor([0.1000, 0.5000, 0.7000, 0.8000]))