Confusion Matrix Calculator

Quick answer

The confusion matrix calculator turns the four counts of a binary classifier – true positives, false positives, false negatives and true negatives – into accuracy, precision, recall, F1 score, all four rates, the false discovery rate, Matthews correlation coefficient and Cohen’s kappa.

Accuracy
80 %
Precision (positive predictive value)
90 %
Recall (sensitivity, true positive rate)
75 %
F1 score
0.8182
Specificity (true negative rate)
87.5 %
False positive rate (fall-out)
12.5 %
False negative rate (miss rate)
25 %
False discovery rate
10 %
Negative predictive value
70 %
False omission rate
30 %
Matthews correlation coefficient (MCC)
0.6124
Balanced accuracy
81.25 %
Cohen’s kappa
0.6
Informedness (Youden’s J)
0.625
Prevalence of the positive class
60 %
Total cases
100

A confusion matrix summarises how a yes/no classifier performed on labelled data. Rows (or columns) separate the true classes, and the four cells count true positives (correct alarms), false positives (false alarms), false negatives (misses) and true negatives (correct all-clears). Every popular evaluation metric for binary classification is a ratio of these four numbers.

Which metric matters depends on the cost of each mistake. Recall (sensitivity) matters when missing a positive is expensive – cancer screening, fraud detection. Precision matters when false alarms are expensive – spam filtering, recommending a costly follow-up. The F1 score balances the two. For imbalanced data, the Matthews correlation coefficient and balanced accuracy are more honest than plain accuracy because they use all four cells.

Enter your counts and the calculator returns sixteen measures at once, so you can quote the ones your field uses: data scientists usually report precision, recall and F1, clinicians sensitivity, specificity and predictive values, and statisticians MCC or kappa.

How to use the Confusion Matrix Calculator

  1. True positives (TP)
  2. False positives (FP)
  3. False negatives (FN)
  4. True negatives (TN)

Results update as you type, and everything is calculated in your browser.

How it works

Each rate divides one cell by the row or column it belongs to. F1 is the harmonic mean of precision and recall. MCC is the correlation between predicted and actual labels. Kappa compares observed agreement with the agreement expected by chance from the row and column totals.

Worked example

A classifier is tested on 100 cases: TP = 45, FP = 5, FN = 15, TN = 35. Accuracy = 80 ÷ 100 = 80%. Precision = 45 ÷ 50 = 90%, recall = 45 ÷ 60 = 75%, so F1 = 90 ÷ 110 = 0.8182. Specificity = 35 ÷ 40 = 87.5% and FPR = 12.5%. MCC = (45 × 35 − 5 × 15) ÷ √(50 × 60 × 40 × 50) = 1,500 ÷ 2,449.49 = 0.6124. Chance agreement is (50 × 60 + 50 × 40) ÷ 100² = 0.5, so kappa = (0.8 − 0.5) ÷ 0.5 = 0.6.

Layout of the matrix

Predicted positive Predicted negative
Actually positive TP – true positive FN – false negative (miss)
Actually negative FP – false positive (false alarm) TN – true negative

Inputs explained

Field What to enter
True positives (TP) A number
False positives (FP) A number
False negatives (FN) A number
True negatives (TN) A number

What each result means

  • Accuracy = ([True positives (TP)] + [True negatives (TN)])÷([True positives (TP)] + [False positives (FP)] + [False negatives (FN)] + [True negatives (TN)])×100
  • Precision (positive predictive value) = [True positives (TP)]÷([True positives (TP)] + [False positives (FP)])×100
  • Recall (sensitivity, true positive rate) = [True positives (TP)]÷([True positives (TP)] + [False negatives (FN)])×100
  • F1 score = 2×[True positives (TP)]÷(2×[True positives (TP)] + [False positives (FP)] + [False negatives (FN)])
  • Specificity (true negative rate) = [True negatives (TN)]÷([True negatives (TN)] + [False positives (FP)])×100
  • False positive rate (fall-out) = [False positives (FP)]÷([False positives (FP)] + [True negatives (TN)])×100
  • False negative rate (miss rate) = [False negatives (FN)]÷([False negatives (FN)] + [True positives (TP)])×100
  • False discovery rate = [False positives (FP)]÷([False positives (FP)] + [True positives (TP)])×100
  • Negative predictive value = [True negatives (TN)]÷([True negatives (TN)] + [False negatives (FN)])×100
  • False omission rate = [False negatives (FN)]÷([False negatives (FN)] + [True negatives (TN)])×100
  • Matthews correlation coefficient (MCC) = ([True positives (TP)]×[True negatives (TN)] – [False positives (FP)]×[False negatives (FN)])÷sqrt(([True positives (TP)] + [False positives (FP)])×([True positives (TP)] + [False negatives (FN)])×([True negatives (TN)] + [False positives (FP)])×([True negatives (TN)] + [False negatives (FN)]))
  • Balanced accuracy = ([Recall (sensitivity, true positive rate)] + [Specificity (true negative rate)])÷2
  • Informedness (Youden’s J) = [Recall (sensitivity, true positive rate)]÷100 + [Specificity (true negative rate)]÷100 – 1
  • Prevalence of the positive class = ([True positives (TP)] + [False negatives (FN)])÷([True positives (TP)] + [False positives (FP)] + [False negatives (FN)] + [True negatives (TN)])×100
  • Total cases = [True positives (TP)] + [False positives (FP)] + [False negatives (FN)] + [True negatives (TN)]

Formula

Accuracy = (TP + TN) ÷ N · Precision = TP ÷ (TP + FP) · Recall = TP ÷ (TP + FN) F1 = 2TP ÷ (2TP + FP + FN) MCC = (TP·TN − FP·FN) ÷ √((TP + FP)(TP + FN)(TN + FP)(TN + FN))

Worked example

Inputs — True positives (TP): 45; False positives (FP): 5; False negatives (FN): 15; True negatives (TN): 35.
Results — Accuracy = 80 %; Precision (positive predictive value) = 90 %; Recall (sensitivity, true positive rate) = 75 %; F1 score = 0.8182; Specificity (true negative rate) = 87.5 %; False positive rate (fall-out) = 12.5 %; False negative rate (miss rate) = 25 %; False discovery rate = 10 %; Negative predictive value = 70 %; False omission rate = 30 %; Matthews correlation coefficient (MCC) = 0.6124; Balanced accuracy = 81.25 %; Cohen’s kappa = 0.6; Informedness (Youden’s J) = 0.625; Prevalence of the positive class = 60 %; Total cases = 100.

Key terms

True positive (TP)
A positive case correctly predicted positive.
False positive (FP)
A negative case wrongly predicted positive (type I error).
False negative (FN)
A positive case wrongly predicted negative (type II error).
F1 score
The harmonic mean of precision and recall.
Matthews correlation coefficient
A correlation between −1 and 1 summarising all four cells.

Frequently asked questions

What is a confusion matrix?

A 2 × 2 table comparing predicted and actual classes: true positives, false positives, false negatives and true negatives.

How do I calculate precision and recall?

Precision = TP ÷ (TP + FP); recall = TP ÷ (TP + FN). With TP 45, FP 5, FN 15: precision 90%, recall 75%.

What is a good F1 score?

It ranges from 0 to 1. Above 0.8 is usually good, but compare it with a baseline – a model that always predicts the majority class – for your data.

Why use MCC instead of accuracy?

MCC uses all four cells and is near 0 for a useless classifier even when classes are very imbalanced, whereas accuracy can look excellent.

What is the difference between the false positive rate and the false discovery rate?

FPR = FP ÷ (FP + TN) is the share of actual negatives flagged; FDR = FP ÷ (FP + TP) is the share of positive predictions that are wrong.

What does Cohen’s kappa measure?

Agreement between predictions and truth beyond what chance would give; 0 means chance level and 1 means perfect.

Does it work for multi-class problems?

Compute one matrix per class (that class vs the rest) and average the metrics – macro or weighted averages.

Sources

  1. scikit-learn – Model evaluation: classification metrics
  2. NCBI Bookshelf – Diagnostic testing accuracy: sensitivity, specificity, predictive values and likelihood ratios
  3. NIST/SEMATECH e-Handbook of Statistical Methods

Cite this calculator

Speedy Calculator. (2026). Confusion Matrix Calculator. Speedy Calculator. https://speedycalculator.com/calculators/statistics/confusion-matrix/