bigframes.ml.metrics.f1_score#

bigframes.ml.metrics.f1_score(y_true: DataFrame | Series, y_pred: DataFrame | Series, *, average: str | None = 'binary') Series[source]#

Compute the F1 score, also known as balanced F-score or F-measure.

The F1 score can be interpreted as a harmonic mean of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is: F1 = 2 * (precision * recall) / (precision + recall).

In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the average parameter.

Examples:

>>> import bigframes.pandas as bpd
>>> import bigframes.ml.metrics
>>> y_true = bpd.DataFrame([0, 1, 2, 0, 1, 2])
>>> y_pred = bpd.DataFrame([0, 2, 1, 0, 0, 1])
>>> f1_score = bigframes.ml.metrics.f1_score(y_true, y_pred, average=None)
>>> f1_score
0    0.8
1    0.0
2    0.0
dtype: float64
Parameters:
  • y_true – Series or DataFrame of shape (n_samples,). Ground truth (correct) target values.

  • y_pred – Series or DataFrame of shape (n_samples,). Estimated targets as returned by a classifier.

  • average – {‘micro’, ‘macro’, ‘samples’, ‘weighted’, ‘binary’} or None, default=’binary’ This parameter is required for multiclass/multilabel targets. Possible values are ‘None’, ‘micro’, ‘macro’, ‘samples’, ‘weighted’, ‘binary’.

Returns:

float or Series of float, shape = [n_unique_labels]

F1 score of the positive class in binary classification or weighted average of the F1 scores of each class for the multiclass task.

Return type:

f1_score