The worked example: TP=8, FP=2, FN=4, TN=8
With these four counts, precision is 80%, recall is 66.67%, F1 is about 72.73% and accuracy is 80% over 20 cases.
Start with the cells: TP=8, FP=2, FN=4, TN=8. The total is 8 + 2 + 4 + 8 = 20 evaluated cases. The number of actual positives is TP + FN = 8 + 4 = 12. The number of predicted positives is TP + FP = 8 + 2 = 10. Those two derived counts are the denominators for recall and precision respectively, and it helps to write them down before dividing.
Precision is 8 / (8 + 2) = 8 / 10 = 0.80, or 80%. Recall is 8 / (8 + 4) = 8 / 12 ≈ 0.6667, or 66.67%. F1 is 2 × 0.80 × 0.6667 / (0.80 + 0.6667), which is approximately 0.7273, or 72.73%. Accuracy is (8 + 8) / 20 = 16 / 20 = 0.80, or 80%.
Read the four numbers together. Precision of 80% means two in ten positive predictions were wrong. Recall of 66.67% means four of the twelve actual positives were missed. Accuracy of 80% matches precision here only by coincidence of these counts; in general the two diverge as class balance changes, which is why accuracy alone is a weak summary when positives are rare.
- Precision: 8 / 10 = 80%.
- Recall: 8 / 12 = 66.67%.
- F1: about 72.73%.
- Accuracy: 16 / 20 = 80%.