torcheval.metrics.BinaryBinnedPrecisionRecallCurve¶
- class torcheval.metrics.BinaryBinnedPrecisionRecallCurve(*, threshold: int | List[float] | Tensor = 100, device: device | None = None)¶
使用给定阈值计算精确率-召回率曲线。其函数版本为
torcheval.metrics.functional.binary_binned_precision_recall_curve()
。- 参数:
threshold (Union[int, List[float], torch.Tensor], Optional) – 表示区间数的整数,阈值列表或阈值张量。
示例
>>> import torch >>> from torcheval.metrics import BinaryBinnedPrecisionRecallCurve >>> input = torch.tensor([0.2, 0.8, 0.5, 0.9]) >>> target = torch.tensor([0, 1, 0, 1]) >>> threshold = 5 >>> metric = BinaryBinnedPrecisionRecallCurve(threshold) >>> metric.update(input, target) >>> metric.compute() (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]) >>> metric = BinaryBinnedPrecisionRecallCurve(threshold) >>> metric.update(input, target) >>> metric.compute() (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]))
- __init__(*, threshold: int | List[float] | Tensor = 100, device: device | None = None) None ¶
初始化度量对象及其内部状态。
使用
self._add_state()
初始化度量类状态变量。状态变量应为torch.Tensor
、torch.Tensor
列表、以torch.Tensor
作为值的字典或torch.Tensor
的双端队列。
方法
__init__
(*[, threshold, device])初始化度量对象及其内部状态。
计算
()- 返回值:
precision (张量):精确率结果的张量。其形状为 (n_thresholds + 1, )
load_state_dict
(state_dict[, strict])从 state_dict 加载度量状态变量。
merge_state
(metrics)实现此方法以更新当前度量的状态变量,使其成为当前度量和输入度量的合并状态。
重置
()将度量状态变量重置为其默认值。
state_dict
()在 state_dict 中保存度量状态变量。
to
(device, *args, **kwargs)将度量状态变量中的张量移动到设备。
update
(input, target)使用真实标签和预测更新状态。
属性
设备
Metric.to()
的最后一个输入设备。