Shortcuts

torcheval.metrics.functional.binary_f1_score

torcheval.metrics.functional.binary_f1_score(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor

Compute binary f1 score, the harmonic mean of precision and recall.

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_f1_score
>>> input = torch.tensor([0, 1, 0.7, 0.6])
>>> target = torch.tensor([0, 1, 1, 0])
>>> binary_f1_score(input, target, threshold=0.5)
tensor(0.8000)

>>> input = torch.tensor([1, 1, 0, 0])
>>> target = torch.tensor([0, 1, 1, 1])
>>> binary_f1_score(input, target, threshold=1)
tensor(0.4000)

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