Shortcuts

torcheval.metrics.functional.binary_binned_precision_recall_curve

torcheval.metrics.functional.binary_binned_precision_recall_curve(input: Tensor, target: Tensor, *, threshold: int | List[float] | Tensor = 100) Tuple[Tensor, Tensor, Tensor]

使用给定的阈值计算精确率-召回率曲线。 其类版本为torcheval.metrics.BinaryBinnedPrecisionRecallCurve

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

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

  • threshold – 一个表示分箱数量的整数,一个阈值列表,或一个阈值张量。

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_binned_precision_recall_curve
>>> input = torch.tensor([0.2, 0.8, 0.5, 0.9])
>>> target = torch.tensor([0, 1, 0, 1])
>>> threshold = 5
>>> binary_binned_precision_recall_curve(input, target, threshold)
(tensor([0.5000, 0.6667, 0.6667, 1.0000, 1.0000, 1.0000]),
tensor([1., 1., 1., 1., 0., 0.]),
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

>>> input = torch.tensor([0.2, 0.3, 0.4, 0.5])
>>> target = torch.tensor([0, 0, 1, 1])
>>> threshold = torch.tensor([0.0000, 0.2500, 0.7500, 1.0000])
>>> binary_binned_precision_recall_curve(input, target, threshold)
(tensor([0.5000, 0.6667, 1.0000, 1.0000, 1.0000]),
tensor([1., 1., 0., 0., 0.]),
tensor([0.0000, 0.2500, 0.7500, 1.0000]))