langtest.utils.util_metrics.calculate_f1_score#

calculate_f1_score(y_true: List[str | int], y_pred: List[str | int], average: str = 'macro', zero_division: int = 0) float#

Calculate the F1 score for the provided true and predicted labels.

Parameters:
  • y_true (List[Union[str, int]]) – List of true labels.

  • y_pred (List[Union[str, int]]) – List of predicted labels.

  • average (str, optional) – Method to calculate F1 score, can be ‘micro’, ‘macro’ or ‘weighted’. Defaults to ‘macro’.

  • zero_division (int, optional) – Value to return when there is a zero division case, i.e., when all predictions and true values are negative. Defaults to 0.

Returns:

Calculated F1 score.

Return type:

float

Raises:
  • AssertionError – If lengths of y_true and y_pred are not equal.

  • ValueError – If invalid averaging method is provided.