torcheval.metrics.functional.binary_f1_score¶
-
torcheval.metrics.functional.
binary_f1_score
(input: Tensor, target: Tensor, *, threshold: float = 0.5) Tensor [source]¶ Compute binary f1 score, the harmonic mean of precision and recall. See also
multiclass_f1_score
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_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)
- input (Tensor) – Tensor of label predictions with shape of (n_sample,).