← AI and Data Science Studio
🎯

Confusion Matrix, Precision & Recall Calculator

Binary classifier evaluation metrics from TP/FP/FN/TN counts

When to use: Enter the four counts from a binary classifier's confusion matrix (true positives, false positives, false negatives, true negatives) — from a test set evaluation, a scikit-learn confusion_matrix() output, or any classifier report — to get accuracy, precision, recall, specificity, F1 score, and Matthews correlation coefficient.

Confusion Matrix
True Positive
False Positive
False Negative
True Negative
Total samples: 300
F1 Score
0.872
Accuracy91.7%
Precision89.5%
Recall (Sensitivity)85.0%
Specificity95.0%
False Positive Rate5.0%
False Negative Rate15.0%
Matthews Correlation (MCC)0.811

About the Confusion Matrix, Precision & Recall Calculator

This calculator computes the standard set of binary classifier evaluation metrics from a confusion matrix's four counts — true positives, false positives, false negatives, and true negatives. It's the fastest way to sanity-check what a model's raw TP/FP/FN/TN breakdown actually means in terms of accuracy, precision, recall, specificity, F1, and Matthews correlation coefficient, without writing evaluation code for a quick check.

The four confusion matrix counts

For a binary classifier predicting a "positive" class against a "negative" class, every prediction falls into one of four buckets: True Positive (TP) — correctly predicted positive; False Positive (FP) — incorrectly predicted positive (a "false alarm," Type I error); False Negative (FN) — incorrectly predicted negative when it was actually positive (a "miss," Type II error); True Negative (TN) — correctly predicted negative. Every other classification metric — accuracy, precision, recall, and the rest — is derived purely from these four counts, which is why the confusion matrix is considered the foundational summary of classifier performance, more informative than accuracy alone.

Why accuracy alone is misleading, and precision/recall aren't

Accuracy = (TP+TN)/Total treats false positives and false negatives as equally costly and ignores class imbalance — on a dataset that's 95% negative, a classifier that always predicts "negative" scores 95% accuracy while catching zero actual positives, which is useless for most real detection tasks (fraud, defects, disease). Precision = TP/(TP+FP) answers "of everything I flagged positive, how much was actually positive?" — it penalizes false alarms. Recall = TP/(TP+FN) answers "of everything that was actually positive, how much did I catch?" — it penalizes misses. These two metrics trade off against each other (a model can trivially get 100% recall by flagging everything positive, tanking precision, or 100% precision by only flagging its single most-confident prediction, tanking recall), which is exactly why they're reported together rather than either alone.

F1 score and Matthews correlation coefficient

F1 = 2 × (Precision × Recall) / (Precision + Recall) is the harmonic mean of precision and recall — it penalizes an extreme imbalance between the two more heavily than a simple average would, making it a useful single summary number when you want to compare models without picking a specific precision/recall trade-off point. Matthews Correlation Coefficient (MCC) uses all four confusion matrix counts symmetrically (unlike F1, which ignores true negatives entirely) and ranges from −1 (total disagreement) to +1 (perfect prediction), with 0 representing performance no better than random guessing — MCC is widely considered more informative than F1 specifically for imbalanced datasets, since it doesn't artificially look good just because the negative class is large and mostly correctly classified.

How to use this calculator

Get the four counts from your model evaluation — most ML frameworks provide this directly (e.g. scikit-learn's confusion_matrix(y_true, y_pred) returns a 2×2 array you can read TP/FP/FN/TN from, keeping in mind which class is treated as "positive"). Enter them here to get the full set of derived metrics at once, useful for a quick sanity check, for reporting results without re-deriving formulas by hand, or for comparing two models' confusion matrices side by side to see which metric actually differs between them.

Frequently asked questions

Which metric should I optimize for — precision or recall?

It depends entirely on the relative cost of false positives versus false negatives in your specific application, not on a general rule. For a cancer screening test, a false negative (missing an actual case) is typically far more costly than a false positive (an unnecessary follow-up test), so you'd prioritize recall. For a spam filter, a false positive (a real email marked as spam and possibly missed) is often more costly than a false negative (a spam email that gets through), so you'd prioritize precision. When you don't have a clear asymmetric cost, F1 or MCC are reasonable single-number summaries that don't require picking a side.

Why does my model show high accuracy but a low F1 score?

This is the classic signature of class imbalance: if the negative class dominates the dataset, a model that's biased toward predicting "negative" racks up a large true-negative count that inflates accuracy, while its precision and/or recall for the positive class — which F1 is built from — can still be poor. Always check the confusion matrix directly (not just accuracy) whenever your classes aren't roughly balanced, which in real engineering/industrial applications (defect detection, fault prediction, anomaly detection) is the common case, not the exception.

What is the difference between recall and specificity?

Recall (also called sensitivity or true positive rate) measures how well the model catches actual positives: TP/(TP+FN). Specificity measures how well the model correctly identifies actual negatives: TN/(TN+FP), and is the complement of the false positive rate (specificity = 1 − FPR). They are mirror-image metrics for the two classes — a model can have high recall and low specificity (catches most positives but also falsely flags many negatives) or the reverse, and reporting only one without the other hides that trade-off, similar to reporting precision without recall.

Why is Matthews correlation coefficient considered better than F1 for imbalanced data?

F1 is computed only from precision and recall, both of which depend solely on TP, FP, and FN — true negatives never enter the F1 calculation at all. On a heavily imbalanced dataset with a large negative class, this means F1 can look deceptively reasonable even when the model is doing something strange with the (unreported) negative class, whereas MCC's formula incorporates all four confusion matrix counts and only returns a high score when the model does well across true positives, true negatives, false positives, and false negatives simultaneously — which is why many ML practitioners consider it the more honest single-number summary for imbalanced problems specifically.

Can I use this for a multi-class classification problem?

Not directly — this calculator models the standard binary (2-class) confusion matrix. For multi-class problems, the usual approach is to compute a confusion matrix per class using a "one-vs-rest" framing (that class = positive, all other classes combined = negative) and either report per-class precision/recall/F1 separately, or average them (macro-average treats each class equally regardless of size; micro-average and weighted-average account for class size) — you can still use this calculator for each individual one-vs-rest breakdown if you compute those TP/FP/FN/TN counts yourself.

🎓

Try our AI and Data Science Studio

More calculators, simulators, and guides for this discipline.

Related tools & guides

Train/Test Split PlannerMachine Learning Basics for EngineersMLOps for Engineering AIPython Script Generator