Confusion Matrix Calculator: Precision, Recall, F1 & MCC
Enter your true positives, false positives, true negatives, and false negatives below. Every classification metric updates live, and clicking any metric shows the exact formula used to calculate it.
Confusion matrix values
Matrix and metrics
Click any metric card to see the formula used. All calculations run in your browser, nothing is uploaded or stored.
// outline
What a Confusion Matrix Actually Is
A confusion matrix is just a table comparing what your model predicted against what actually happened. For a binary classifier, it has four cells: cases you correctly called positive, cases you incorrectly called positive, cases you incorrectly called negative, and cases you correctly called negative. Every other metric on this page, accuracy, precision, recall, F1, MCC, all of it, is calculated from those four numbers.
The reason it matters more than a single accuracy number is that it separates two very different kinds of mistakes. A model that misses real fraud cases and a model that flags too many legitimate transactions as fraud can have the exact same accuracy while being wrong in opposite, and very differently costly, ways.
The Metrics Explained
- Accuracy. The share of all predictions that were correct. Simple, but misleading when one class is rare.
- Precision. Of everything the model called positive, how much actually was. High precision means few false alarms.
- Recall (sensitivity). Of everything that was actually positive, how much did the model catch. High recall means few missed cases.
- Specificity. The negative-class version of recall, how much of the actual negative cases were correctly identified.
- F1 score. The harmonic mean of precision and recall, a single number that punishes models which sacrifice one to inflate the other.
- Balanced accuracy. The average of recall and specificity, a fairer alternative to plain accuracy on imbalanced data.
- MCC. A correlation-based score from negative 1 to positive 1 that uses all four confusion matrix values, widely considered the most reliable single number for imbalanced binary classification.
Click any metric in the tool above to see its exact formula rather than taking the number on faith.
Precision vs Recall, In Practice
The right metric to optimize depends entirely on what a mistake costs you, not on which number looks better in a report.
| Scenario | Costlier mistake | Prioritize |
|---|---|---|
| Disease screening | Missing a real case (false negative) | Recall |
| Spam filter | Blocking a real email (false positive) | Precision |
| Fraud detection | Usually missing real fraud, but false alarms have real cost too | Balance both, or F1 / MCC |
| Content moderation | Depends on platform policy and legal exposure | Varies by case |
There's no metric that's universally correct. A model tuned for high recall in a medical screening context would be a poor fit for a spam filter, and vice versa, even if the underlying algorithm is identical.
Why Accuracy Fails on Imbalanced Data
Load the disease screening preset in the tool above and watch what happens to accuracy versus recall. If 98 percent of patients don't have a condition, a model that predicts "no condition" for everyone scores 98 percent accuracy while catching zero real cases. That's the exact failure mode precision, recall, F1, and MCC are built to expose.
This is why, for anything with a rare positive class, fraud, disease, defects, security threats, accuracy on its own should never be the metric you report or optimize for. Pair it with at least recall and F1, or use MCC as a single number that's harder to game.
3 Common Confusion Matrix Mistakes
- Reporting only accuracy on an imbalanced dataset. It's the single most common way a weak model looks strong on paper.
- Optimizing F1 score by default without checking the cost of each error type. F1 treats precision and recall as equally important, which is often not true for your actual problem.
- Comparing metrics across different test sets. A precision of 0.85 only means something relative to the specific dataset and class balance it was measured on, not as a universal number to compare across projects.
Once you know which metric matters for your problem, our ML Algorithm Picker can help pick a starting algorithm suited to your data and goal, and the AI Model Cost Calculator is useful once you're comparing hosted model APIs rather than training your own classifier.
Frequently Asked Questions
What is a confusion matrix?
A confusion matrix is a table that compares a classification model's predictions against the actual labels. For a binary problem it has four cells: true positives, false positives, true negatives, and false negatives, and every other classification metric is calculated from those four numbers.
What is the difference between precision and recall?
Precision measures how many of the model's positive predictions were actually correct, while recall measures how many of the actual positive cases the model successfully found. A model can have high precision and low recall, or the reverse, depending on where it makes mistakes.
When should I use F1 score instead of accuracy?
Use F1 score when your classes are imbalanced, meaning one class is much rarer than the other. Accuracy can look excellent on an imbalanced dataset simply by predicting the majority class every time, while F1 score, the harmonic mean of precision and recall, exposes that weakness.
What is a good F1 score?
It depends entirely on the problem and dataset, so there is no universal good score. As a rough starting point, above 0.9 is often considered strong, 0.7 to 0.9 is decent, and below 0.5 usually signals the model needs real improvement, but always compare against a baseline for your specific task.
What is specificity in a confusion matrix?
Specificity, also called the true negative rate, measures how many of the actual negative cases the model correctly identified as negative. It is the negative-class counterpart to recall, which measures the same idea for the positive class.
What is MCC and when should I use it?
The Matthews correlation coefficient, MCC, is a single score from negative 1 to positive 1 that accounts for all four confusion matrix values at once, including true negatives, which F1 score ignores. It is considered one of the most reliable single metrics for imbalanced binary classification.
Why is accuracy misleading for imbalanced data?
If 95 percent of your data belongs to one class, a model that always predicts that class scores 95 percent accuracy while being completely useless at its actual job. Precision, recall, F1, and MCC all expose this failure in ways plain accuracy does not.
What is the difference between recall and sensitivity?
Recall and sensitivity are the same metric with two different names. Both measure the proportion of actual positive cases that the model correctly identified, and the term used often just depends on the field, with sensitivity more common in medical and diagnostic contexts.
How do I calculate confusion matrix metrics for more than two classes?
For multi-class problems, you calculate precision, recall, and F1 separately for each class by treating it as positive against all other classes combined, then average the results, either as a simple macro average or a weighted average based on class size.
What is the difference between a false positive and a false negative?
A false positive is when the model predicts positive but the actual label is negative, sometimes called a type I error. A false negative is when the model predicts negative but the actual label is positive, a type II error. Which one matters more depends entirely on the cost of each mistake in your specific use case.
Summary: Pick the Metric That Matches the Cost
There's no single best classification metric, only the one that matches what a mistake actually costs in your situation. Use the tool above to see all of them at once for your numbers, then decide which one you'd actually stake a business or research decision on before you report just accuracy and move on.
Khalid Hussain
Founder of Review Publically. Holds a Master's in Computer Science with professional training in Google Advanced Data Analytics and ML. Built and verified every formula on this page against standard statistical definitions before publishing.
// related reads