# F1 calculation test

The formula for F1 harmonic mean F1 score is

$$F1 =2*\frac{precision*recall}{precision + recall}$$

The values under the column F1 don't agree with the formula. Any answers

• Please provide your calculation. It seems everything is fine – Daniel Chepenko Jun 22 '18 at 6:39
• Lets take the example of Logistic regression F1=2*(0.831*0.811)/(0.831+0.811)=0.8208. The value given under F1 is 0.788 – Arvind Prasad Jun 22 '18 at 7:45
• I had posted this question as a bug. It was address. The calculations are okay. The values that we see are the average of F1 for Y and N responses. – Arvind Prasad Jun 27 '18 at 13:51
• The same issue (reported scores is average of the class statistics) here: datascience.stackexchange.com/q/60850/55122 – Ben Reiniger Oct 4 '19 at 21:06

It is not a bug just weighted averaging is used in computing F1, precision or recall. That means that score is computed per each label/class and then averaged. See the documention by sklearn.

In case of the classifier with 3 classes, the F1 score is computed for class 1 as a target class using the rule you wrote, class 2 as a target class and class 3 as a target class. Those scores are then averaged to retrieve the final score. Recall and precision are computed the same way, all of them are averaging over class scores. The rule you wrote is used in per class calculation but it does not hold for averages.