torcheval.metrics.functional.binary_precision¶
- torcheval.metrics.functional.binary_precision(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor ¶
Compute precision score for binary classification class, which is calculated as the ratio between the number of true positives (TP) and the total number of predicted positives (TP + FP). Its class version is
torcheval.metrics.BinaryPrecision
.- Parameters:
input (Tensor) – Tensor of label predictions It could be the predicted labels, with shape of (n_sample, ).
torch.where(input < threshold, 0, 1)
will be applied to the input.target (Tensor) – Tensor of ground truth labels with shape of (n_sample,).
threshold (float, default 0.5) – Threshold for converting input into predicted labels for each sample.
Examples:
>>> import torch >>> from torcheval.metrics.functional import binary_precision >>> input = torch.tensor([0, 0, 1, 1]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_precision(input, target) tensor(1.) # 2 / 2 >>> metric = BinaryPrecision(threshold=0.7) >>> input = torch.tensor([0, 0.8, 0.6, 0.7]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_precision(input, target) tensor(0.5) # 1 / 2