Confusion Matrix Pro

Free Confusion Matrix Calculator

Enter your model's results to instantly calculate accuracy, precision, and many other performance metrics.

Export & share
Edit any cell in the matrix on the right and every metric updates instantly. Rows are actual classes, columns are predicted. Optionally rename the two classes, or load a quick preset to see how the metrics shift at the extremes.

Class Labels

Optional. Renames the matrix axes only (e.g. Dog / Cat). All metrics keep their standard names; the positive class is the one that drives Sensitivity, Precision, and the rest.

Quick Presets

Predictions & Threshold

Have raw model outputs instead of counts? Paste predicted probabilities (0–1) and the true labels (0 or 1), or upload a CSV. The matrix is built for you, and you get a decision-threshold slider to tune the cut-off live and compare any two thresholds.
CSV, TSV, or plain text, up to 25 MB. Commas, tabs, or semicolons all work. Wide files are fine; pick the prediction and label columns after upload. Header row optional. Binary spreadsheets (.xlsx, .parquet, etc.) are not supported; export to CSV first.
Edit any cell in the matrix on the right and every metric updates instantly. Rows are actual classes, columns are predicted. Set the number of classes (3–10) and optionally name them below.

Class Setup

Optional. Comma-separated names rename the matrix rows and columns. Anything missing falls back to Class 1, Class 2…

Confusion Matrix

Predicted +
Predicted −
Total
Actual +
TP
FN
2008
Actual −
FP
TN
1961
Total
1945
2024
3969

Core Metrics

88.5%
(TP+TN)/Total
88.5%
TP/(TP+FN)
also: Recall · TPR · Power (1−β)
88.5%
TN/(TN+FP)
also: TNR
88.5%
TP/(TP+FP)
also: PPV
NPV
89.3%
TN/(TN+FN)
48.0%
(TP+FN)/Total

Composite Scores

88.5%
2(P×R)/(P+R)
88.5%
(Sens+Spec)/2
MCC
0.77
Correlation
Kappa
0.77
Agreement
79.4%
TP/(TP+FP+FN)
also: IoU · Threat Score · CSI
88.5%
√(P×R)
also: G-mean of precision & recall

Errors & Effectiveness

11.5%
FP/(TN+FP)
also: Type I Error (α)
11.5%
FN/(TP+FN)
also: Type II Error (β)
0.77
Sens+Spec−1
0.77
PPV+NPV−1

Ratios & Complements

LR+
7.69
TPR/FPR
LR−
0.13
FNR/TNR
59.00
LR+ / LR−
11.5%
(FP+FN)/Total
12.4%
FP/(TP+FP)
10.7%
FN/(TN+FN)

Multi-class Metrics

Accuracy
Macro F1
Weighted F1
Cohen's Kappa
ClassPrecisionRecallF1Support

Understanding the Confusion Matrix

01

What Is a Confusion Matrix?

A confusion matrix is a table that checks a classification model's predictions against the truth, so you can see exactly what kind of mistakes it's making instead of collapsing everything into one accuracy number. For a binary (two-class) problem it's a 2×2 grid. Every prediction lands in exactly one of four cells: true positive, true negative, false positive, or false negative. Every metric on this page, from accuracy to the diagnostic odds ratio, is arithmetic on those four counts.

02

How to Read TP, TN, FP, and FN

In this tool's matrix, rows are the actual class and columns are the model's predicted class, the same convention scikit-learn's confusion_matrix and R's caret::confusionMatrix use. That gives four outcomes:

  • True Positive (TP): predicted positive, actually positive. A correct catch.
  • True Negative (TN): predicted negative, actually negative. A correct pass.
  • False Positive (FP): predicted positive, actually negative. A false alarm (Type I error).
  • False Negative (FN): predicted negative, actually positive. A miss (Type II error).

Full definitions are in the metric glossary below, along with which trade-off matters most for your use case.

03

How to Use This Tool

Confusion Matrix Pro showing a confusion matrix with TP, FN, FP, and TN color-coded, next to class labels and quick-preset scenarios

Three ways to get your data in, depending on what you already have:

  • Binary: type TP, TN, FP, FN directly if your model is already scored.
  • Predictions & Threshold: paste predicted probabilities and true labels, or upload a CSV. The matrix builds itself at a decision threshold you drag live, with ROC and Precision-Recall curves updating alongside it.
  • Multi-Class: for 3 to 10 classes, enter the full N×N matrix and get per-class precision, recall, F1, macro/weighted averages, and multi-class Cohen's κ.

Every metric shows a value, a 95% confidence interval, and its formula. Hover any for a one-line recap. Everything runs locally in your browser, and nothing you enter is uploaded anywhere (see the privacy notes). The full site guide covers baseline comparison, class labels, export, and embedding in more depth.

04

Confusion Matrix Formulas: A Worked Example

Say a spam filter is tested against 1,000 real emails, 200 of which are actually spam. It correctly flags 180 of those 200 (catching most of the spam) and correctly lets through 760 of the 800 real emails, at the cost of wrongly flagging 40 good emails and letting 20 spam messages slip by:

Predicted spamPredicted not spam
Actually spamTP = 180FN = 20
Actually not spamFP = 40TN = 760

Every formula below is just those four counts, rearranged:

MetricFormulaCalculationResult
Accuracy(TP+TN) / Total(180+760) / 100094%
Sensitivity (Recall)TP / (TP+FN)180 / 20090%
SpecificityTN / (TN+FP)760 / 80095%
PrecisionTP / (TP+FP)180 / 22081.82%
F1-Score2·P·R / (P+R)2(.8182)(.90) / (.8182+.90)85.71%
False Positive RateFP / (TN+FP)40 / 8005%
False Negative RateFN / (TP+FN)20 / 20010%
Balanced Accuracy(Sens+Spec) / 2(90%+95%) / 292.5%
MCC(TP·TN−FP·FN) / √(…)136,000 / 165,6990.82

Accuracy (94%) looks strong on its own, but it doesn't show that the filter still misses 1 in 10 real spam messages (FNR = 10%). That's the whole case for a confusion matrix over a single number. Try your own counts in the Binary tab above, check every metric's full definition and CI method in the glossary below, or jump to the complete formula reference for all 22 at once.

Frequently Asked Questions

What is a confusion matrix used for?

Evaluating any classifier that sorts things into categories: spam filters, medical screening tests, fraud detection, image classifiers. It breaks accuracy apart into the specific ways a model gets things wrong. False positives and false negatives are rarely equally costly, and a single accuracy number can't tell them apart.

How do you calculate accuracy from a confusion matrix?

Accuracy is (TP + TN) divided by the total number of predictions: the share of all predictions the model got right. In the worked example above, (180 + 760) / 1,000 = 94%. It's the simplest metric, but it can be misleading on imbalanced data. A filter that marked every email "not spam" would still score 80% accuracy on this same dataset while catching zero spam.

What's the difference between precision and recall?

Recall (sensitivity) asks "of everything that was actually positive, how much did the model catch?" That's TP / (TP + FN). Precision asks "of everything the model flagged positive, how much was actually right?" That's TP / (TP + FP). A model can score high on one and low on the other. F1-Score balances both into a single number.

What is a good F1 score?

There's no universal cutoff. It depends on class balance and how costly each error type is for your specific problem. On a balanced, well-posed task, 0.8+ is generally considered strong and 0.9+ excellent, but the better approach is comparing against a baseline (like the Random or Perfect presets on the Binary tab) instead of a fixed number pulled from nowhere. The F1 score calculator covers this in more depth, including the F0.5 and F2 variants for when precision and recall matter unequally.

What's the difference between sensitivity and specificity?

Sensitivity measures how well the model catches actual positives: TP / (TP + FN). Specificity measures how well it clears actual negatives: TN / (TN + FP). A medical test can have high sensitivity (it rarely misses the disease) but low specificity (it also flags a lot of healthy patients). The two numbers describe different failure modes, and neither alone tells the full story.

Can this calculator handle more than two classes?

Yes. The Multi-Class tab supports 3 to 10 classes. Enter or paste the full N×N matrix and it returns per-class precision, recall, and F1, plus macro-average, weighted-average, and multi-class Cohen's kappa.

Is my data uploaded or stored anywhere?

No. Every calculation, including CSV uploads, runs locally in your browser. Nothing is sent to a server or stored anywhere, and closing the tab discards it. Full detail is in the Disclaimer tab below.

Metric Definitions & Terminology

Core Metrics

Accuracy

The number everyone asks for first, and the one most likely to fool you. It is simply the share of predictions you got right, lumping correct positives and correct negatives together. When the two classes are roughly balanced, that is an honest summary. But when one class dominates, accuracy flatters lazy models: if 95% of cases are negative, a model that blindly answers "negative" every time scores 95% while telling you nothing. Read it first, then immediately check a metric that accounts for the imbalance.

Formula: (TP + TN) / (TP + TN + FP + FN)

Sensitivity · Recall · TPR · Power (1 − β)

Of everything that was genuinely positive, how much did the model actually catch? The same calculation travels under several names: machine learning calls it recall, ROC analysis calls it the true positive rate (TPR), and classical statistics calls it power, written 1 − β. Think of it as the model's thoroughness. It is the metric you care about most when a miss is the expensive kind of mistake: an undetected tumour, a fraud that slips through, a search-and-rescue target left behind. It says nothing about false alarms, so it is best read alongside specificity or precision.

Formula: TP / (TP + FN)

Specificity · TNR

The mirror image of sensitivity: of everything that was genuinely negative, how much did the model correctly leave alone? ROC analysis calls the same quantity the true negative rate (TNR). High specificity means the model rarely cries wolf. You lean on it whenever a false alarm is costly or disruptive: sending a healthy patient for invasive tests, or dropping a real email into the spam folder.

Formula: TN / (TN + FP)

Precision · PPV

Sensitivity asks "did we catch everything?" Precision asks the trust question instead: "when the model says positive, should I believe it?" In clinical fields the same quantity is called positive predictive value, or PPV. It is the fraction of positive calls that turned out to be correct, and high precision means few false alarms. One catch worth remembering: this number depends heavily on how common the positive class is. The rarer the positive class, the harder it becomes to keep precision high, no matter how good the model is.

Formula: TP / (TP + FP)

Negative Predictive Value (NPV)

The counterpart of precision on the other side of the matrix: given a negative result, how likely is it to be genuinely negative? This is the number that tells you whether an "all clear" can actually be trusted.

Formula: TN / (TN + FN)

Prevalence

Before judging any other metric, ask how common the positive class actually is; that is prevalence. It is not a score of the model at all; it is a property of your data. But it is the context that decides whether accuracy can be trusted and how high precision could realistically ever reach.

Formula: (TP + FN) / (TP + TN + FP + FN)

Advanced Metrics

F1-Score

Precision and recall usually pull in opposite directions; push one up and the other tends to sag. F1 is the single number that refuses to let you ignore either. It is their harmonic mean, which behaves like a stricter average: it punishes imbalance, so a brilliant precision cannot paper over a dismal recall. If both matter and you want one figure to optimise, this is the one to watch.

Formula: 2 × (Precision × Recall) / (Precision + Recall)

FPR · Type I Error (α)

The false-alarm rate. Of all the genuinely negative cases, what fraction did the model wrongly flag as positive? Classical statistics calls the same quantity the Type I error rate, α, and it is the false-alarm cost you agree to tolerate before a hypothesis test even begins. Convicting an innocent defendant is the textbook example. It is also the horizontal axis of every ROC curve, and lower is better.

Formula: FP / (TN + FP)

FNR · Type II Error (β)

The miss rate. Of all the genuinely positive cases, what fraction did the model wave through as negative? Classical statistics calls the same quantity the Type II error rate, β. Where a Type I error is a false accusation, a Type II error is a real problem walking quietly out the door. It is one minus sensitivity, and you watch it closely whenever a miss is the dangerous outcome.

Formula: FN / (TP + FN)

Balanced Accuracy

Plain accuracy can be hijacked by a dominant class. Balanced accuracy closes that loophole by averaging sensitivity and specificity: judging the model on each class separately, then giving the two equal weight. On a lopsided dataset, this is the more honest "overall" score.

Formula: (Sensitivity + Specificity) / 2

Matthews Correlation Coefficient (MCC)

If you are allowed to trust just one number on an imbalanced dataset, make it this one. MCC is a correlation coefficient between predictions and reality: +1 is perfect, 0 is no better than a coin flip, −1 is perfectly wrong. Its strength is that it only scores well when the model performs across all four cells of the matrix at once; there is nowhere to hide.

Formula: (TP×TN − FP×FN) / √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]

Cohen's Kappa

Some agreement happens by luck alone. Kappa asks how much your model agrees with the truth beyond what random guessing would already have produced. A value of 0 means "no better than chance," 1 means perfect agreement. It is the honest way to discount a score that class imbalance has quietly inflated.

Formula: (Observed − Expected agreement) / (1 − Expected agreement)

Youden's J Statistic

A compact summary of diagnostic skill: sensitivity plus specificity, minus one. Zero means the test is no use; 1 means it is flawless. Its second job is practical: the threshold that maximises J is a common and defensible choice for a decision cut-off.

Formula: Sensitivity + Specificity − 1

Markedness

Youden's J judged the model from the side of the actual classes; markedness judges it from the side of the predictions. It combines how trustworthy your positive calls and your negative calls are. Strong markedness means both kinds of prediction are genuinely worth believing.

Formula: PPV + NPV − 1

Jaccard Index · IoU · Threat Score

Every other score on this page counts the true negatives somewhere. This one throws them away and asks a narrower question: of everything that was positive in prediction or in truth, what fraction was both? That is exactly the intersection over the union, which is why image segmentation and object detection live by it — there the background is the overwhelming majority of the picture, and a metric that credits you for correctly ignoring it would rate a model that predicts nothing at 99%. Meteorologists reached the same conclusion independently and call it the critical success index. It is a strict relative of F1, always a little lower, and it never flatters a rare-event model.

Formula: TP / (TP + FP + FN)

Fowlkes–Mallows Index

The same two ingredients as F1, combined a shade more generously. F1 takes the harmonic mean of precision and recall; this takes their geometric mean, which still punishes a lopsided pair but not as harshly. The practical use is as a second opinion: when F1 and Fowlkes–Mallows sit close together your precision and recall are balanced, and when they drift apart one of the two is carrying the score. Read them side by side rather than picking a favourite.

Formula: √(Precision × Recall)

Rate Complements

Error Rate (Misclassification Rate)

Accuracy told from the pessimist's chair: the share of predictions that came out wrong. It is exactly one minus accuracy, and it carries the same blind spot: on imbalanced data, a reassuringly low error rate can still hide a model that misses every case that matters.

Formula: (FP + FN) / (TP + TN + FP + FN) = 1 − Accuracy

False Discovery Rate (FDR)

Of all the cases your model called positive, what fraction were false alarms? That is the False Discovery Rate, the complement of precision. It is the natural language for fields that make many positive calls at once, such as screening thousands of genes, where you want a firm bound on how many "discoveries" are really just noise.

Formula: FP / (TP + FP) = 1 − Precision

False Omission Rate (FOR)

The quieter counterpart to FDR: of all the cases called negative, what fraction were actually positive? A high False Omission Rate means your "all clear" is concealing real cases, precisely the failure you most fear in screening triage.

Formula: FN / (TN + FN) = 1 − NPV

Diagnostic Ratios

Positive Likelihood Ratio (LR+)

How much should a positive result move your belief? LR+ compares how often positives turn up among true cases versus false ones. A value of 1 is useless noise; the higher it climbs, the more a positive result genuinely shifts the odds toward "real." It can run anywhere from 0 to infinity.

Formula: TPR / FPR = Sensitivity / (1 − Specificity)

Negative Likelihood Ratio (LR−)

The same idea applied to a negative result: how much should a negative finding lower your suspicion? Here you want a small number: the closer to 0, the more confidently a negative result rules the condition out. A value of 1 again means the result told you nothing.

Formula: FNR / TNR = (1 − Sensitivity) / Specificity

Diagnostic Odds Ratio (DOR)

One number to rank overall discriminative power: the positive likelihood ratio divided by the negative one. A DOR of 1 means the test cannot tell the classes apart at all; the larger it grows, the cleaner the separation. Meta-analyses favour it because it compresses a test's quality into a single, comparable figure.

Formula: LR+ / LR− = (TP × TN) / (FP × FN)

Confusion Matrix Components

True Positive (TP)

The model said positive and reality agreed: a clean hit.

True Negative (TN)

The model said negative and reality agreed: a correct pass.

False Positive (FP)

The model raised a flag that should never have gone up. This is the false alarm, known in hypothesis testing as a Type I error.

False Negative (FN)

The model stayed quiet on a case that was genuinely real. This is the miss, known in hypothesis testing as a Type II error.

Confusion Matrices in Python & R

Python (scikit-learn)

The functions behind this tool's Copy Python / R export, in the official scikit-learn reference.

R (caret, yardstick, pROC)

The R equivalents the export emits, plus the tidymodels option for a modern workflow.

Confusion Matrix Pro is a free, browser-based tool for evaluating binary classification models. Enter your true positives, true negatives, false positives, and false negatives, or paste raw predicted probabilities and labels, to instantly calculate performance metrics, including accuracy, precision, recall, sensitivity, specificity, F1-score, Matthews correlation coefficient (MCC), and Cohen's kappa, alongside an interactive confusion matrix, ROC and precision-recall curves, and a live decision-threshold slider. It is designed for data scientists, machine learning engineers, students, and researchers who want a fast, no-install way to interpret model results, tune classification thresholds, and compare diagnostic performance across medical screening, fraud detection, spam filtering, and other binary classification problems.