What Is Confusion Matrix?
A confusion matrix tabulates a classifier's predictions against the true labels. From its four counts you can compute every standard classification metric, and each one answers a different question: how often the model is right, how many of its positive calls are correct, and how many real positives it finds.
Besides accuracy, precision, recall and F1, the calculator reports balanced accuracy, the false positive and false negative rates, Matthews correlation coefficient and Cohen's kappa. These matter when classes are imbalanced, where plain accuracy can look high even for a poor model.
Below you will find the formulas, a variables table, a worked example and answers to common questions such as precision versus recall and which metric to use for imbalanced data.
How to Use the Confusion Matrix Calculator
- Enter the counts of true positives, false positives, false negatives and true negatives.
- Start with precision and recall, not accuracy, if the classes are imbalanced.
- Use F1 or MCC for a single summary number, and the likelihood ratios for diagnostic tests.
- Check the chart for a quick visual comparison of the main metrics.
Confusion Matrix Formula
Accuracy
Precision and recall
Specificity
F1 score
Matthews correlation coefficient
Likelihood ratios
Confusion Matrix Variables Explained
| Symbol | Meaning | Notes |
|---|---|---|
| TP | True positives | Positive cases predicted positive |
| FP | False positives | Negative cases predicted positive |
| FN | False negatives | Positive cases predicted negative |
| TN | True negatives | Negative cases predicted negative |
| Precision | TP ÷ (TP + FP) | Share of positive calls that are right |
| Recall | TP ÷ (TP + FN) | Share of real positives found |
Confusion Matrix Worked Example
Using the example values (press “Load example” above to try them):
- TP = 85, FP = 10, FN = 15, TN = 90; total = 200.
- Accuracy = (TP + TN) ÷ total = 175 ÷ 200 = 87.5 %.
- Precision = TP ÷ (TP + FP) = 85 ÷ 95 = 89.47 %; Recall = TP ÷ (TP + FN) = 85 ÷ 100 = 85 %.
- F1 = 2TP ÷ (2TP + FP + FN) = 170 ÷ 195 = 87.18 %.
Result: Accuracy = 87.5 %; Precision (PPV) = 89.47 %; Recall (sensitivity, TPR) = 85 %; F1 score = 87.18 %.
Which metric should you use?
A model that predicts “negative” for everyone on a data set with 1% positives scores 99% accuracy and finds no positives at all. This is the accuracy paradox, and the reason to look at recall and precision together.
| Situation | Prefer | Why |
|---|---|---|
| Balanced classes, equal costs | Accuracy | Simple and sufficient |
| Rare positive class | Precision, recall, F1, MCC | Accuracy is inflated by the majority class |
| Missing a positive is costly (screening) | Recall / sensitivity | Catches as many true cases as possible |
| False alarms are costly (spam filter) | Precision | Limits wrong positive flags |
| Single balanced summary | MCC or balanced accuracy | Uses all four cells |
Diagnostic test view
In medicine, recall is called sensitivity and specificity is its counterpart for healthy people. The positive and negative predictive values depend on prevalence: the same test gives a much lower PPV when the condition is rare. Likelihood ratios do not depend on prevalence, so they are the right tool for updating the probability of disease after a test result. An LR+ above 10 or an LR− below 0.1 is considered strong evidence.
| Machine learning | Medicine | Formula |
|---|---|---|
| Recall, TPR | Sensitivity | TP / (TP + FN) |
| TNR | Specificity | TN / (TN + FP) |
| Precision | Positive predictive value | TP / (TP + FP) |
| FPR | 1 − specificity | FP / (FP + TN) |
The precision-recall trade-off
Moving the decision threshold changes the four counts together. A lower threshold finds more true positives (higher recall) but also more false positives (lower precision). A confusion matrix is one point on that curve; compare thresholds by computing a matrix for each.
Where Confusion Matrix Is Used
Evaluating a classifier
Summarising a model's performance from its prediction counts.
Imbalanced data
Using balanced accuracy, MCC or kappa when one class dominates.
Diagnostic test summaries
Computing sensitivity, specificity and error rates from a 2×2 table.
Course and report work
Checking hand-calculated metrics against a worked table.
Common Confusion Matrix Mistakes to Avoid
- Check the matrix orientation: here rows are actual (positive on top) and columns predicted.
- Report precision and recall together; either one alone can be gamed.
- On multi-class problems compute a matrix per class (one vs rest) and average with macro, micro or weighted schemes.
- Use MCC when you want one number that stays honest under class imbalance.
Confusion Matrix Terms and Definitions
- False positive (Type I)
- The model predicts positive but the truth is negative.
- False negative (Type II)
- The model predicts negative but the truth is positive.
- Prevalence
- The share of actual positives in the data.
Confusion Matrix FAQs
What is a confusion matrix?
A table summarising correct and incorrect predictions of a classifier by comparing predicted classes with actual classes.
What is the difference between precision and recall?
Precision is the share of predicted positives that are correct. Recall is the share of actual positives that were found.
Why is accuracy misleading with imbalanced data?
Predicting the majority class for every case can score a high accuracy while detecting none of the minority class.
What is the F1 score?
The harmonic mean of precision and recall. It is high only when both are high.
What is the Matthews correlation coefficient?
A correlation between predicted and actual classes that ranges from −1 to 1 and uses all four cells, so it stays reliable when classes are imbalanced.
How do I read the matrix for more than two classes?
Compute one-vs-rest metrics for each class and combine them with macro, micro or weighted averages.
What do the likelihood ratios mean?
LR+ tells how much a positive result raises the odds of the condition; LR− tells how much a negative result lowers it.
Can I use this for more than two classes?
This calculator is for a binary 2×2 matrix. For several classes, treat each class in turn as "positive" against all the others (one-vs-rest), compute the metrics for each, and then average them if you need a single figure.
Which metric should I use when classes are imbalanced?
Plain accuracy can look high even when the minority class is mostly missed. Balanced accuracy, F1, Matthews correlation or Cohen's kappa give a fairer picture.