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
。- 参数:
input (Tensor) – 标签预测的张量,应该是一个概率或 logits,形状为 (n_sample, n_class)。
target (Tensor) – 地真标签的张量,形状为 (n_samples, )。
num_classes (可选) – 类别数量。如果 num_classes 为 None,则设置为输入的第二维。
threshold – 一个表示 bin 数量的整数、一个阈值列表或一个阈值张量。
- 返回值:
- List[torch.Tensor], recall: List[torch.Tensor], thresholds: torch.Tensor)
precision: 精度结果列表。每个索引表示一个类的结果。recall: 召回结果列表。每个索引表示一个类的结果。thresholds: 阈值张量。阈值用于所有类别。
- 返回类型:
一个包含 (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]))