Confusion Matrix Pro

Confusion Matrix Formulas

Every formula, in one table, with a live calculator so you can check your own numbers against them.

The Complete Formula Reference

01

The Four Building Blocks

Every formula below reduces to arithmetic on four counts: TP (true positive), TN (true negative), FP (false positive), and FN (false negative). Each one is what a model predicted, checked against what was actually true. If those four aren't familiar yet, the full walkthrough on the main calculator covers them with a worked example first.

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 diagnostic test screens 500 patients. 50 actually have the condition. The test correctly flags 45 of them (TP=45, FN=5 missed) and correctly clears 423 of the 450 who don't have it, at the cost of 27 false alarms (FP=27, TN=423):

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%) both look reassuring, but precision is only 62.5%. Of everyone the test flags positive, more than a third don't actually have the condition. That gap is prevalence at work (only 10% of this population actually has it), and it's exactly the kind of thing a single accuracy number hides. See the Prevalence and likelihood ratio definitions for how that connects to real-world test interpretation, or plug in your own counts above.

Frequently Asked Questions

Why isn't there just one confusion matrix formula?

Because "correct" depends on what a wrong answer costs. Accuracy alone hides which kind of mistake a model is making. A spam filter that misses spam and a spam filter that blocks real mail are both "wrong" but not equally wrong. Different formulas isolate different failure modes on purpose, so you can pick the one that matches what actually matters for your problem.

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

A rate (Accuracy, Sensitivity, FPR, Error Rate, ...) is a proportion between 0 and 1, computed as one count divided by a sum that includes it. A ratio like LR+ or the Diagnostic Odds Ratio divides two rates against each other, so it isn't bounded the same way. LR+ of 15 simply means a positive result is 15 times more likely from a true case than a false alarm, with no upper limit.

Which formula should I use to compare two models?

It depends on your data and what an error costs. Balanced Accuracy or MCC are reasonable defaults on imbalanced data since both account for all four confusion matrix cells at once. If false positives and false negatives cost differently, compare on whichever single metric captures that cost (Precision, Recall, or a weighted F-beta) instead of a general-purpose one.

Do these formulas work for multi-class problems?

As written, no. They assume a 2×2 matrix. For 3+ classes each formula is computed per class (treating that class as "positive" and everything else as "negative"), then usually averaged (macro-average treats every class equally; weighted-average accounts for class size). The Multi-Class tab in the calculator above does this automatically.