快捷方式

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

参数:
  • input (Tensor) – 标签预测的张量,其形状为 (n_sample, n_label),应为概率或 logits。

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

  • num_labels (Optional) – 标签的数量。

返回值:

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

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

返回类型:

一个包含 (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])])

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取针对初学者和高级开发者的深入教程

查看教程

资源

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

查看资源