Confusion Matrix Calculator — Accuracy, Precision, Recall, F1 & MCC
Enter the four counts of a binary confusion matrix (TP, FP, FN, TN) and read every standard classification metric — accuracy, precision, recall, specificity, F1, balanced accuracy, MCC and Cohen's kappa — each with the exact formula and your numbers substituted in. Matches scikit-learn, runs in your browser, no signup.
How it works
A binary confusion matrix has four cells. True Positives (TP) and True Negatives (TN) are correct predictions; False Positives (FP) are Type I errors (a negative flagged as positive) and False Negatives (FN)are Type II errors (a positive that slipped through). Their sum is the sample size N. Every metric below is a closed-form function of these four integers, using the definitions in the scikit-learn model-evaluation documentation and the Wikipedia confusion-matrix table.
- Accuracy = (TP + TN) / N
- Precision (PPV) = TP / (TP + FP)
- Recall / Sensitivity (TPR) = TP / (TP + FN)
- Specificity (TNR) = TN / (TN + FP)
- F1 = 2·TP / (2·TP + FP + FN)
- Fβ = (1 + β²)·TP / ((1 + β²)·TP + β²·FN + FP)
- Balanced accuracy = (Recall + Specificity) / 2
- MCC = (TP·TN − FP·FN) / √((TP+FP)(TP+FN)(TN+FP)(TN+FN))
- κ = (pₒ − pₑ) / (1 − pₑ), pₒ = Accuracy
The three summary scores earn their place by resisting the accuracy paradox. On a dataset that is 98% negative, a model that predicts "negative" for everything scores 0.98 accuracy while catching no positives at all. F1 collapses because recall is zero; balanced accuracy drops to 0.50 because it averages the two class-wise rates; MCC and Cohen's kappa fall near zero because both correct for the majority-class baseline — kappa by subtracting the chance agreement pₑ computed from the row and column totals, MCC by using all four cells as a correlation. When accuracy looks high but MCC is low, this tool shows a note so you weigh the right metric.
Two safeguards keep the numbers trustworthy. First, any metric whose denominator is zero is reported as undefinedrather than a silent 0 or NaN — precision needs TP + FP > 0, MCC needs every matrix margin non-zero. Second, F1 is computed two independent ways — from the raw counts and as the precision×recall harmonic mean — and the two are reconciled, which is what the "Matches scikit-learn" badge attests. Nothing you type is uploaded; the whole calculation happens in your browser.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — Metrics and scoring: quantifying the quality of predictions
- Wikipedia — Confusion matrix (derived-rate table)
- Chicco & Jurman (2020) — Advantages of MCC over F1 and accuracy, BMC Genomics 21:6
- Cohen (1960) — A coefficient of agreement for nominal scales
These are mathematical definitions, not rates that change over time. The formulas on this page were last cross-checked against the scikit-learn documentation on 2026-07-08.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.