Confusion Matrix Calculator
Enter the four counts of a confusion matrix (TP, FP, FN, TN) to instantly get accuracy, precision, recall, specificity and F1 score, shown as proportions or percentages.
Accuracy, Precision, Recall and F1 from a Confusion Matrix
Confusion Matrix
Where:
- \(TP\) — true positives: positive cases correctly classified as positive
- \(FP\) — false positives: negative cases incorrectly classified as positive (type I errors)
- \(FN\) — false negatives: positive cases incorrectly classified as negative (type II errors)
- \(TN\) — true negatives: negative cases correctly classified as negative
- \(n\) — total number of classified cases
These five metrics all range from 0 (worst) to 1 (perfect) and summarize different aspects of a binary classifier's performance. When a denominator is zero, the corresponding metric is undefined and the calculator shows "—".
Confusion Matrix – Calculation Example
Example: a model screened 150 cases. It correctly flagged 45 positive cases (TP) and missed 15 (FN), while correctly passing 80 negative cases (TN) and raising 10 false alarms (FP).
\[ n = 45 + 10 + 15 + 80 = 150 \]
\[ \text{Accuracy} = \frac{45 + 80}{150} = 0.8333 \quad (83.33\%) \]
\[ \text{Precision} = \frac{45}{45 + 10} = 0.8182 \quad (81.82\%) \]
\[ \text{Recall} = \frac{45}{45 + 15} = 0.75 \quad (75\%) \]
\[ \text{Specificity} = \frac{80}{80 + 10} = 0.8889 \quad (88.89\%) \]
\[ F_1 = \frac{2 \times 45}{2 \times 45 + 10 + 15} = \frac{90}{115} = 0.7826 \quad (78.26\%) \]
Result: Accuracy 83.33%, precision 81.82%, recall 75%, specificity 88.89%, F1 score 78.26% (with the output set to percentages).
How to use the calculator
- Count how many cases fall in each cell of your confusion matrix: enter them under True positives, False positives, False negatives and True negatives. All four values must be whole numbers \(\ge 0\).
- Choose Show metrics as: "Proportions (0–1)" for decimal values or "Percentages (0–100%)" for percent values.
- Read the results: Total predictions, Accuracy, Precision (positive predictive value), Recall (sensitivity, true positive rate), Specificity (true negative rate) and F1 score, followed by a summary of how the metrics were computed and how to interpret them.
- If a metric is shown as "—", its denominator was zero — for example, precision is undefined when the model never predicted a positive case (\(TP + FP = 0\)).
What is a confusion matrix?
A confusion matrix is the basic report card of a binary classifier. It is a 2×2 table that cross-tabulates the true class of each case (positive or negative) against the class the model predicted. The four cells — true positives, false positives, false negatives and true negatives — contain every possible outcome, so their sum \(n\) is the total number of classified cases. From these four numbers alone you can derive every standard measure of classification quality.
The five metrics computed here each answer a different question. Accuracy asks: overall, what fraction of predictions were correct? Precision asks: when the model says "positive", how often is it right? Low precision means many false alarms. Recall (also called sensitivity or true positive rate) asks: of all cases that really are positive, how many did the model catch? Low recall means missed cases. Specificity is the recall of the negative class — how well the model recognizes true negatives. F1 is the harmonic mean of precision and recall, which balances the two: it is high only when both are high.
Why not just use accuracy? Because accuracy is misleading when classes are imbalanced. If only 1% of cases are positive, a trivial model that labels everything negative scores 99% accuracy while catching zero positives. Precision, recall and F1 focus on the positive class and expose such failures immediately. Which metric matters most depends on the cost of errors: in cancer screening, a missed tumor (false negative) is far worse than a false alarm, so recall is prioritized; in spam filtering, a lost legitimate email (false positive) may be worse, so precision matters more.
In medical and epidemiological contexts the same numbers carry different names: recall is sensitivity, precision is the positive predictive value (PPV), and the share of actual positives \((TP + FN)/n\) is the prevalence. If you know the sensitivity, specificity and prevalence of a test, you can work forward to the predictive values with Bayes' Theorem.
Assumptions, limitations and practical tips
- The calculator treats the four counts as exact integers from a single classification run. It assumes each case belongs to exactly one cell and that the "positive" class is the one you care about detecting.
- All metrics are computed on the entered sample, so they are estimates subject to sampling error. With small counts (say, under 30 positives), report a confidence interval — a Wilson interval is a good choice for proportions — rather than a bare percentage.
- Metrics with a zero denominator are undefined and shown as "—": precision when no positives were predicted, recall when there are no actual positives, specificity when there are no actual negatives, and F1 when both precision and recall are zero.
- F1 weights precision and recall equally. If one matters more in your application, use the \(F_\beta\) score instead (e.g. \(F_2\) favors recall, \(F_{0.5}\) favors precision).
- The confusion matrix says nothing about why the model errs or how it compares to another model on the same data. To test whether two classifiers (or two raters) differ significantly on paired outcomes, use McNemar's Test; for independent proportions, the Two-Proportion Z-Test or Fisher's Exact Test applies.
- A confusion matrix requires hard (binary) decisions. If your model outputs probabilities, the counts — and therefore every metric — depend on the threshold you choose to convert scores into labels, so always report the threshold alongside the metrics.
Frequently Asked Questions
What is a good F1 score or accuracy value?
There is no universal "good" value — it depends entirely on the domain and the cost of errors. As rough rules of thumb: above 0.9 is excellent in well-studied tasks like digit recognition, 0.7–0.9 is often acceptable in text classification, and 0.5–0.7 may already be valuable in noisy fields like medical prediction. Always compare against a baseline (e.g. always predicting the majority class) rather than an absolute number.
How do I compute the metrics by hand without a calculator?
Write the four counts in a 2×2 grid with predicted classes as columns and actual classes as rows. Accuracy is the diagonal sum divided by the total, precision is TP divided by the first column sum, recall is TP divided by the first row sum, and specificity is TN divided by the second row sum. F1 is the harmonic mean: multiply precision by recall, double it, and divide by their sum. Each value lies between 0 and 1; multiply by 100 for a percentage.
What are the most common mistakes when filling in a confusion matrix?
The classic error is swapping false positives and false negatives. Remember: a false positive is a case the model predicted positive that was actually negative (a false alarm), while a false negative was predicted negative but is actually positive (a miss). Also make sure the matrix orientation matches your convention — some tools put actual classes in columns and predictions in rows, which transposes the table and changes which cells are FP and FN.
Can this calculator handle multi-class confusion matrices?
No — it works only for binary (two-class) problems. For multi-class problems, you can build one 2×2 matrix per class by treating that class as "positive" and all others as "negative", then compute per-class precision, recall and F1, and average them (macro or micro averaging). Alternatively, metrics like the Matthews Correlation Coefficient (MCC) and Cohen's kappa generalize directly to larger square matrices.
How do I convert between proportions, percentages and odds?
A proportion of 0.85 equals 85%; just multiply by 100 (or divide by 100 to go back). Some fields report odds instead: the odds ratio of a classifier is \( (TP \cdot TN)/(FP \cdot FN) \), and Youden's J statistic is recall + specificity − 1. If a source gives you a percentage, convert it to a proportion before using it in formulas like the harmonic mean for F1.
Why is my F1 score lower than both precision and recall?
That is expected behavior, not a bug. F1 is the harmonic mean, which is dominated by the smaller of the two values. For example, with precision 0.95 and recall 0.55, F1 is about 0.70 — much closer to the weak recall than the arithmetic mean (0.75) would suggest. This penalizes classifiers that excel at one metric while failing at the other, which is exactly why F1 is preferred over the simple average.
What about the negative class — is there a negative predictive value?
Yes. The counterpart of precision for the negative class is the negative predictive value (NPV): \( TN/(TN + FN) \), the probability that a "negative" prediction is truly negative. Unlike sensitivity and specificity, both PPV and NPV depend on class prevalence, so the same test can have a high NPV in a low-prevalence population even with modest specificity. Use it when the reliability of negative results matters, such as ruling out disease.