Confusion Matrix Calculator

This confusion matrix calculator turns the four cells of a binary classification matrix (true positives, false positives, false negatives, true negatives) into accuracy, precision, recall, specificity, F1 and other metrics, with a heat-mapped matrix and a confidence interval for accuracy.

Checks on your data

  • Classes are reasonably balanced and the sample is large enough for stable rates.

Results

Accuracy
87.5 %
95% CI 82.2% to 91.39%
Precision (PPV)
89.47 %
TP ÷ (TP + FP)
Recall (sensitivity, TPR)
85 %
TP ÷ (TP + FN)
Specificity (TNR)
90 %
TN ÷ (TN + FP)
F1 score
87.18 %
Negative predictive value
85.71 %
False positive rate
10 %
False negative rate (miss rate)
15 %
Balanced accuracy
87.5 %
Matthews correlation (MCC)
0.7509
from −1 to 1; robust to imbalance
Cohen’s kappa
0.75
Prevalence
50 %
Positive likelihood ratio
8.5
Negative likelihood ratio
0.1667
Youden’s J
0.75
Total cases
200
Confusion matrix
Predicted: positive | negativeActual: positive | negativeTP85FN15FP10TN90
Key metrics (0 to 1)
00.5Accuracy: 0.875Accuracy0.875Precision: 0.894737Precision0.895Recall: 0.85Recall0.85Specificity: 0.9Specificity0.9F1: 0.871795F10.872
Show step-by-step solution
  1. TP = 85, FP = 10, FN = 15, TN = 90; total = 200.
  2. Accuracy = (TP + TN) ÷ total = 175 ÷ 200 = 87.5 %.
  3. Precision = TP ÷ (TP + FP) = 85 ÷ 95 = 89.47 %; Recall = TP ÷ (TP + FN) = 85 ÷ 100 = 85 %.
  4. F1 = 2TP ÷ (2TP + FP + FN) = 170 ÷ 195 = 87.18 %.
InputsTP, FP, FN, TN
PrecisionTP / (TP + FP)
RecallTP / (TP + FN)
Imbalance-safeF1, MCC, balanced accuracy

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

  1. Enter the counts of true positives, false positives, false negatives and true negatives.
  2. Start with precision and recall, not accuracy, if the classes are imbalanced.
  3. Use F1 or MCC for a single summary number, and the likelihood ratios for diagnostic tests.
  4. Check the chart for a quick visual comparison of the main metrics.

Confusion Matrix Formula

Accuracy

Acc=TP+TNTP+TN+FP+FNAcc=\frac{TP+TN}{TP+TN+FP+FN}

Precision and recall

P=TPTP+FP,R=TPTP+FNP=\frac{TP}{TP+FP},\quad R=\frac{TP}{TP+FN}

Specificity

Spec=TNTN+FPSpec=\frac{TN}{TN+FP}

F1 score

F1=2PRP+R=2TP2TP+FP+FNF_1=\frac{2PR}{P+R}=\frac{2TP}{2TP+FP+FN}

Matthews correlation coefficient

MCC=TP⋅TN−FP⋅FN(TP+FP)(TP+FN)(TN+FP)(TN+FN)MCC=\frac{TP\cdot TN-FP\cdot FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}

Likelihood ratios

LR+=Sens1−Spec,LR−=1−SensSpecLR^{+}=\frac{Sens}{1-Spec},\quad LR^{-}=\frac{1-Sens}{Spec}

Confusion Matrix Variables Explained

SymbolMeaningNotes
TPTrue positivesPositive cases predicted positive
FPFalse positivesNegative cases predicted positive
FNFalse negativesPositive cases predicted negative
TNTrue negativesNegative cases predicted negative
PrecisionTP ÷ (TP + FP)Share of positive calls that are right
RecallTP ÷ (TP + FN)Share of real positives found

Confusion Matrix Worked Example

Using the example values (press “Load example” above to try them):

  1. TP = 85, FP = 10, FN = 15, TN = 90; total = 200.
  2. Accuracy = (TP + TN) ÷ total = 175 ÷ 200 = 87.5 %.
  3. Precision = TP ÷ (TP + FP) = 85 ÷ 95 = 89.47 %; Recall = TP ÷ (TP + FN) = 85 ÷ 100 = 85 %.
  4. 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.

Choosing a classification metric
SituationPreferWhy
Balanced classes, equal costsAccuracySimple and sufficient
Rare positive classPrecision, recall, F1, MCCAccuracy is inflated by the majority class
Missing a positive is costly (screening)Recall / sensitivityCatches as many true cases as possible
False alarms are costly (spam filter)PrecisionLimits wrong positive flags
Single balanced summaryMCC or balanced accuracyUses 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.

Naming across fields
Machine learningMedicineFormula
Recall, TPRSensitivityTP / (TP + FN)
TNRSpecificityTN / (TN + FP)
PrecisionPositive predictive valueTP / (TP + FP)
FPR1 − specificityFP / (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.

Related calculators

Last updated 2026-11-09. See our disclaimer.