Shortcuts

torcheval.metrics.functional.multiclass_binned_precision_recall_curve

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

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

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

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

  • num_classes (可选) – 类别数量。如果 num_classes 为 None,则设置为输入的第二维度。

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

Returns:

List[torch.Tensor], recall: List[torch.Tensor], thresholds: torch.Tensor)

precision: 精度结果列表。每个索引表示一个类的结果。 recall: 召回结果列表。每个索引表示一个类的结果。 thresholds: 阈值张量。该阈值用于所有类别。

Return type:

一个元组(precision

示例:

>>> import torch
>>> from torcheval.metrics.functional import multiclass_binned_precision_recall_curve
>>> input = torch.tensor([[0.1, 0.1, 0.1, 0.1], [0.5, 0.5, 0.5, 0.5], [0.7, 0.7, 0.7, 0.7], [0.8, 0.8, 0.8, 0.8]])
>>> target = torch.tensor([0, 1, 2, 3])
>>> multiclass_binned_precision_recall_curve(input, target, num_classes=4, threshold=5)
([tensor([0.2500, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 1.0000, 1.0000, 1.0000])],
[tensor([1., 0., 0., 0., 0., 0.]),
tensor([1., 1., 1., 0., 0., 0.]),
tensor([1., 1., 1., 0., 0., 0.]),
tensor([1., 1., 1., 1., 0., 0.])],
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

>>> input = torch.tensor([[0.1, 0.1, 0.1, 0.1], [0.5, 0.5, 0.5, 0.5], [0.7, 0.7, 0.7, 0.7], [0.8, 0.8, 0.8, 0.8]])
>>> target = torch.tensor([0, 1, 2, 3])
>>> threshold = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
>>> multiclass_binned_precision_recall_curve(input, target, num_classes=4, threshold=threshold)
([tensor([0.2500, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.5000, 0.5000, 0.0000, 1.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.5000, 0.5000, 1.0000, 1.0000, 1.0000])],
[tensor([1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),
tensor([1., 1., 1., 1., 1., 0., 0., 0., 0., 0.]),
tensor([1., 1., 1., 1., 1., 1., 1., 0., 0., 0.]),
tensor([1., 1., 1., 1., 1., 1., 1., 1., 0., 0.])],
tensor([0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000, 0.7000, 0.8000, 0.9000]))