pairwise_f#

er_evaluation.metrics.pairwise_f(prediction, reference, beta=1.0)[source]#

Pairwise F score for the inner join of two clusterings.

Pairwise F score:

Pairwise F score is defined as the weighted harmonic mean of pairwise precision and pairwise recall:

\[F_\beta = \frac{(1 + \beta^2)PR}{ \beta^2 P+R}.\]

The \(\beta\) parameter controls the relative weight of precision and recall. When \(\beta = 1\), the F1 score is the harmonic mean of precision and recall. When \(\beta < 1\), the F1 score is weighted towards precision. When \(\beta > 1\), the F score is weighted towards recall.

Parameters:
  • prediction (Series) – Membership vector for the predicted clustering.

  • reference (Series) – Membership vector for the reference clustering.

  • beta (float) – Weight of precision in the F score.

Returns:

Pairwise F score for the inner join of prediction and reference.

Return type:

float

Examples

>>> prediction = pd.Series(index=[1,2,3,4,5,6,7,8], data=[1,1,2,3,2,4,4,4])
>>> reference = pd.Series(index=[1,2,3,4,5,6,7,8], data=["c1", "c1", "c1", "c2", "c2", "c3", "c3", "c4"])
>>> pairwise_f(prediction, reference)
0.4000000000000001

Notes

NA values are dropped from membership vectors prior to computing the metric.