Shortcuts

torcheval.metrics.functional.binary_accuracy

torcheval.metrics.functional.binary_accuracy(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor[source]

Compute binary accuracy score, which is the frequency of input matching target. Its class version is torcheval.metrics.BinaryAccuracy. See also multiclass_accuracy, multilabel_accuracy, topk_multilabel_accuracy

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 the input.

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

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources