Issue
I tried calculating the 'weighted' f1 score using sklearns classification report and it seems to be different from when calculating the f1 score using F1 = 2*((p*r)/(p+r))
. For example:
looking at the example found here looking at the weighted average line:
precision recall f1-score support
weighted avg 0.70 0.60 0.61 5
when calculating it out I get: 0.646153846 = 2*((0.70*0.60)/(0.70+0.60))
which is different from 0.61
. Why is this? How is this f1 score calculated?
Solution
The F1 score i.e. the F1 score for the positive class in a binary classification model. And this is calculated as the F1 = 2*((p*r)/(p+r)
The weighted F1 score is a special case where we report not only the score of positive class, but also the negative class. This is important where we have imbalanced classes. Because the simple F1 score gives a good value even if our model predicts positives all the times.
So the weighted average takes into account the number of samples of both the classes as well and can't be calculated by the formula you mentioned above.
Hope it helps.
Answered By - Vatsal Gupta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.