Statistical
Precision, Recall, F1 Score & Matthews Correlation (MCC) from a Confusion Matrix
Evaluate ML classifiers, spam filters, and QA inspection models on imbalanced datasets where raw Accuracy misleads.
Why 91% Accuracy can hide a 0% useless model—and F1 + MCC expose the truth!
With 90 positive cases among 1,000 observations, an always-negative classifier achieves 91% accuracy but zero recall and F1. Its MCC formula has a zero denominator; libraries may adopt a convention such as zero, but the raw correlation is undefined.
For TP=80, FP=20, FN=10 and TN=890, precision is 0.8, recall about 0.8889, F1 about 0.8421 and MCC about 0.8270. MCC uses all four counts; no single metric captures every deployment cost, threshold tradeoff or calibration issue.
Enter nonnegative integer counts from one evaluation set with a fixed positive-class definition. This example explicitly reports undefined zero-denominator cases rather than silently assigning a convention.
| Classification Metric (TP=80, FP=20, FN=10, TN=890) | Formula | Result |
|---|---|---|
| Precision (Positive Predictive Value) | =A2 / (A2 + B2) | 0.8000 (80.00%) |
| Recall / Sensitivity (True Positive Rate) | =A2 / (A2 + C2) | 0.8889 (88.89%) |
| F1 Score (Harmonic Mean of P & R) | =(2 * A2) / (2 * A2 + B2 + C2) | 0.8421 |
| Matthews Correlation Coefficient (MCC) | =(TP*TN - FP*FN) / SQRT(...) | 0.8270 ([-1, +1] balanced) |
F1 Score and Matthews Correlation Coefficient (MCC) formulas
Direct algebraic F1 = 2*TP / (2*TP + FP + FN) avoids intermediate rounding and #DIV/0! when Precision or Recall is 0 (as long as 2*TP+FP+FN > 0).
=IF(OR(COUNT(A2:D2)<>4,MIN(A2:D2)<0,SUM(MOD(A2:D2,1))<>0),"Invalid counts",IF(2*A2+B2+C2=0,"Undefined metric",ROUND((2 * A2) / (2 * A2 + B2 + C2), 4)))Matthews Correlation Coefficient (MCC) across all 4 confusion-matrix cells
Equivalent to the Pearson phi correlation between predicted and actual binary labels.
=IF(OR(COUNT(A2:D2)<>4,MIN(A2:D2)<0,SUM(MOD(A2:D2,1))<>0),"Invalid counts",IF((A2+B2)*(A2+C2)*(D2+B2)*(D2+C2)=0,"Undefined metric",ROUND((A2 * D2 - B2 * C2) / SQRT((A2 + B2) * (A2 + C2) * (D2 + B2) * (D2 + C2)), 4)))Try the example
Use the original values or change them to test your understanding.