Confusion Matrix Pro

Confusion Matrix Formulas

All 22 formulas in one table, with plain-English meanings and a worked example.

Free · No sign-up · Runs in your browser

Open the calculator Loads TP 45 · FN 5 · FP 27 · TN 423 Jump to the cheat sheet

The Complete Formula Reference

01

The Four Building Blocks

Every formula uses four counts: TP (true positive), TN (true negative), FP (false positive) and FN (false negative). New to them? Start with the walkthrough.

02

All 22 Formulas

MetricFormulaPlain English
Core Metrics
Accuracy(TP+TN) / TotalShare of all predictions that were correct
Sensitivity (Recall, TPR)TP / (TP+FN)Of actual positives, how many were caught
Specificity (TNR)TN / (TN+FP)Of actual negatives, how many were cleared
Precision (PPV)TP / (TP+FP)Of positive calls, how many were right
Negative Predictive ValueTN / (TN+FN)Of negative calls, how many were right
Prevalence(TP+FN) / TotalHow common the positive class actually is
Composite Scores
F1-Score2·P·R / (P+R)Harmonic mean of precision and recall
Balanced Accuracy(Sens+Spec) / 2Honest accuracy when classes are imbalanced
Matthews Correlation (MCC)(TP·TN−FP·FN) / √(...)Correlation between predictions and truth, −1 to 1
Cohen's Kappa(p₀−pₑ) / (1−pₑ)Agreement with the truth beyond chance
Youden's JSens+Spec−10 is useless, 1 is flawless
MarkednessPPV+NPV−1How trustworthy both predictions are, together
Jaccard Index (IoU, CSI)TP / (TP+FP+FN)Overlap of predicted and actual positives, ignoring TN
Fowlkes–Mallows√(P·R)Geometric mean of precision and recall
Rate Complements
False Positive RateFP / (TN+FP)False-alarm rate on actual negatives
False Negative RateFN / (TP+FN)Miss rate on actual positives
Error Rate(FP+FN) / Total1 − Accuracy
False Discovery RateFP / (TP+FP)1 − Precision
False Omission RateFN / (TN+FN)1 − NPV
Diagnostic Ratios
Positive Likelihood RatioTPR / FPRHow much a positive result shifts the odds up
Negative Likelihood RatioFNR / TNRHow much a negative result shifts the odds down
Diagnostic Odds RatioLR+ / LR−Overall discriminative power in one number
03

Worked Example: A Diagnostic Test

A test screens 500 patients, 50 of whom have the condition. It catches 45 (TP=45, FN=5) and clears 423 of the 450 healthy ones (TN=423), with 27 false alarms (FP=27).

Test positiveTest negative
Actually has itTP = 45FN = 5
Actually doesn'tFP = 27TN = 423
MetricCalculationResult
Accuracy(45+423) / 50093.6%
Sensitivity45 / 5090%
Specificity423 / 45094%
Precision45 / 7262.5%
NPV423 / 42898.83%
F1-Score2(.625)(.90) / (.625+.90)73.77%
MCC(TP·TN−FP·FN) / √(...)0.72
Positive Likelihood Ratio90% / 6%15.0

Accuracy (93.6%) and sensitivity (90%) look good, but precision is 62.5%: over a third of positives are false alarms. That is low prevalence (10%) at work, and accuracy alone hides it. See also likelihood ratios, or try your own counts.

Frequently Asked Questions

Why isn't there just one confusion matrix formula?

Because errors cost different things. A spam filter that lets spam through and one that blocks real mail are both wrong, but not equally. Each formula isolates one failure mode.

What's the difference between a rate and a ratio in this table?

A rate (accuracy, sensitivity, FPR) is a proportion from 0 to 1. A ratio (LR+, DOR) divides one rate by another and has no upper bound. LR+ = 15 means a positive result is 15 times likelier from a true case than from a false alarm.

Which formula should I use to compare two models?

On imbalanced data, Balanced Accuracy or MCC, since both use all four cells. If one error costs more, use the metric that captures it: precision, recall or a weighted F-beta.

Do these formulas work for multi-class problems?

Not directly; they assume a 2×2 matrix. For 3+ classes, compute each one per class (one vs. rest), then macro-average (classes equal) or weighted-average (by class size). The calculator's Multi-Class tab does this.