Shortcuts

torcheval.metrics.functional.multilabel_precision_recall_curve

torcheval.metrics.functional.multilabel_precision_recall_curve(input: Tensor, target: Tensor, *, num_labels: int | None = None) Tuple[List[Tensor], List[Tensor], List[Tensor]]

返回多标签分类任务的精确率-召回率对及其对应的阈值。如果目标张量中没有某个标签的样本,则其召回率值设置为1.0。

它的类版本是 torcheval.metrics.MultilabelPrecisionRecallCurve

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

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

  • num_labels (可选) – 标签数量。

Returns:

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

precision: 精度结果列表。每个索引表示一个标签的结果。 recall: 召回结果列表。每个索引表示一个标签的结果。 thresholds: 阈值列表。每个索引表示一个标签的结果。

Return type:

一个元组(precision

示例:

>>> import torch
>>> from torcheval.metrics.functional import multilabel_precision_recall_curve
>>> input = torch.tensor([[0.75, 0.05, 0.35], [0.45, 0.75, 0.05], [0.05, 0.55, 0.75], [0.05, 0.65, 0.05]])
>>> target = torch.tensor([[1, 0, 1], [0, 0, 0], [0, 1, 1], [1, 1, 1]])
>>> multilabel_precision_recall_curve(input, target, num_labels=3)
([tensor([0.5, 0.5, 1.0, 1.0]),
tensor([0.5, 0.66666667, 0.5, 0.0, 1.0]),
tensor([0.75, 1.0, 1.0, 1.0])],
[tensor([1.0, 0.5, 0.5, 0.0]),
tensor([1.0, 1.0, 0.5, 0.0, 0.0]),
tensor([1.0, 0.66666667, 0.33333333, 0.0])],
[tensor([0.05, 0.45, 0.75]),
tensor([0.05, 0.55, 0.65, 0.75]),
tensor([0.05, 0.35, 0.75])])