What a confusion matrix is
A confusion matrix is a 2×2 table that summarizes how a binary classifier's predictions line up against reality. Every prediction falls into exactly one of four cells: true positives (TP) — positives correctly flagged; false positives (FP) — negatives wrongly flagged as positive (a false alarm, or Type I error); false negatives (FN) — positives the model missed (a Type II error); and true negatives (TN) — negatives correctly left alone. The four counts sum to the total number of predictions, N = TP + FP + FN + TN.
The raw four cells are more informative than any single score. From them you derive every standard performance metric, and each metric answers a different question about the same table.
The metrics this calculator computes
- Accuracy = (TP + TN) / N. The share of all predictions that were correct. Simple, but easily fooled by class imbalance.
- Precision = TP / (TP + FP). Of everything predicted positive, how much was actually positive. High precision means few false alarms.
- Recall (sensitivity, true positive rate) = TP / (TP + FN). Of all real positives, how many were caught. High recall means few misses.
- Specificity (true negative rate) = TN / (TN + FP). Of all real negatives, how many were correctly cleared.
- F1 score = 2 · Precision · Recall / (Precision + Recall). The harmonic mean of precision and recall; it is high only when both are high, so it is a good single number for imbalanced problems.
Worked example
Suppose a medical screening test is evaluated on 200 patients: TP = 80, FP = 10, FN = 20, TN = 90. Then accuracy = (80 + 90) / 200 = 0.85 (85%), precision = 80 / (80 + 10) = 0.8889 (88.89%), recall = 80 / (80 + 20) = 0.80 (80%), specificity = 90 / (90 + 10) = 0.90 (90%), and F1 = 2 · 0.8889 · 0.80 / (0.8889 + 0.80) = 0.8421. The test catches 80% of true cases while keeping false alarms fairly low.
Why accuracy alone is dangerous
On imbalanced data accuracy hides failure. If a disease affects 1% of a population, a model that predicts "healthy" for everyone is 99% accurate but has recall = 0 — it never catches a single case. Precision, recall, specificity, and F1 expose that failure; accuracy conceals it. Always report the underlying counts alongside any headline percentage.