Confusion Matrix calculator
Build a confusion matrix from true positives, false positives, true negatives and false negatives. Get sensitivity, specificity, precision, recall, PPV, NPV, accuracy, F1 and Youden's J, each explained in plain terms.
What it does
Sorts every case into one of four boxes — correctly flagged, wrongly flagged, correctly cleared, wrongly cleared — for one chosen cutoff, and derives every performance measure from those four numbers.
When to use it
Whenever you are going to act on a classifier at a particular threshold. AUC tells you how well a score ranks cases; only the confusion matrix tells you what a decision actually costs.
Worked example
A screening test flags 45 of the 60 people who really have the condition (missing 15), and wrongly flags 30 of the 440 who do not. Sensitivity is 75% and specificity 93% — but of the 75 people it flagged, only 45 truly have it, so precision is 60%. Two in five people told they might be ill are not. That gap is invisible in an AUC.
Cautions
- Accuracy is the most quoted and least useful figure here. If 1 in 100 has the condition, a test that says "no" to everyone is 99% accurate and completely worthless.
- Precision (PPV) and NPV move with prevalence; sensitivity and specificity do not. A test with excellent sensitivity and specificity can still have poor PPV in a low-prevalence setting — that is arithmetic, not a fault in the test, and it is the single most misread result in diagnostics.
- Moving the cutoff trades the two error types against each other. There is no threshold that improves both, so the right one depends on which mistake costs more — missing a case, or a false alarm.
- Computed on the same data the model was fitted to, every one of these numbers is optimistic. Validate on cases the model has not seen.
Alternatives
- ROC curve / AUC — you want performance across every possible cutoff rather than at one
- Precision-recall curve — the positive class is rare — accuracy and specificity both look flattering when almost everyone is negative
- Calibration measures — you need the predicted probabilities themselves to be right, not just the ordering
How to read the output
- Sensitivity (recall, TPR)
- Of everyone who truly has the condition, the share the test flags. TP / (TP + FN). A sensitive test is good at ruling OUT: a negative from a highly sensitive test is reassuring.
- Specificity (TNR)
- Of everyone who truly does not, the share the test clears. TN / (TN + FP). A specific test is good at ruling IN: a positive from a highly specific test is convincing.
- Precision (PPV)
- Of everyone the test flagged, the share who truly have it. TP / (TP + FP). This is the number a flagged patient actually cares about — and the one that collapses when the condition is rare.
- NPV
- Of everyone the test cleared, the share who truly are clear. TN / (TN + FN).
- F1 score
- The harmonic mean of precision and recall — one number when both matter and you cannot favour either. It ignores true negatives entirely, so it says nothing about how the test treats healthy people.
- Youden's J
- Sensitivity + specificity − 1. Zero is useless, one is perfect; commonly used to pick a cutoff. It weights the two error types equally, which is rarely true in practice — a missed cancer is not equivalent to a needless recall.
How this calculator is validated · Which statistical test should I use?