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
。- 参数:
input (Tensor) – 标签预测的张量。它应该是概率或 logits,形状为 (n_sample, )。
target (Tensor) – 真实标签的张量,形状为 (n_samples, )。
threshold – 表示 bin 数量的整数、阈值列表或阈值的张量。
- 返回值:
precision (Tensor): 精确率结果的张量。其形状为 (n_thresholds + 1, )
recall (Tensor): 召回率结果的张量。其形状为 (n_thresholds + 1, )
thresholds (Tensor): 阈值的张量。其形状为 (n_thresholds, )
- 返回类型:
元组
示例
>>> 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]))