torcheval.metrics.functional.binary_accuracy¶
- torcheval.metrics.functional.binary_accuracy(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor ¶
Compute binary accuracy score, which is the frequency of input matching target. Its class version is
torcheval.metrics.BinaryAccuracy
.- Parameters:
input (Tensor) – Tensor of label predictions 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.
torch.where(input < threshold, 0, 1)
will be applied to theinput
.
Examples:
>>> import torch >>> from torcheval.metrics.functional import binary_accuracy >>> input = torch.tensor([0, 0, 1, 1]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_accuracy(input, target) tensor(0.75) # 3 / 4 >>> input = torch.tensor([0, 0.2, 0.6, 0.7]) >>> target = torch.tensor([1, 0, 1, 1]) >>> binary_accuracy(input, target, threshold=0.7) tensor(0.5) # 2 / 4