Confusion Matrix Calculator
This calculator turns the four raw counts behind any binary classification model - true positives, false positives, false negatives and true negatives - into every standard performance metric analysts and machine learning practitioners rely on. You enter TP, FP, FN and TN from your model's test results (or use the worked defaults of 50, 10, 5 and 35), and the tool builds a live matrix visualisation showing predicted versus actual outcomes alongside the total observations, predicted positives and negatives, and actual positives and negatives. From those counts it instantly returns accuracy, precision, recall (sensitivity), specificity, F1 score and the Matthews correlation coefficient (MCC), plus a fuller breakdown covering false positive rate, false negative rate and negative predictive value. A plain-language verdict summarises what the numbers mean and flags whether performance is strong, moderate or weak based on the MCC. Use it to check a model quickly during development, to compare two classifiers on the same test set, or to understand which trade-off - precision against recall - matters most for your problem. Because accuracy alone can be misleading on imbalanced datasets, pay close attention to the F1 score and MCC alongside it, since both weigh false positives and false negatives more evenly. The calculator applies standard formulas for two-class problems only; multi-class classification needs an extended confusion matrix with macro or micro-averaged metrics instead.
1. Enter Confusion Matrix Values
Please enter valid non-negative numbers (total must be greater than zero).
2. Matrix Visualisation
Predicted → / Actual ↓
Full Metric Breakdown
Derived Metrics
Understanding Confusion Matrix Metrics
A confusion matrix is the starting point for evaluating any binary classification model. It records four counts that describe how well a model separates the positive class from the negative class, and from those four numbers every standard classification metric can be derived.
The Four Core Counts
| Term | Symbol | Meaning |
|---|---|---|
| True Positives | TP | The model predicted positive and the actual label is positive. Correct positive predictions. |
| False Positives | FP | The model predicted positive but the actual label is negative. Also called Type I errors or false alarms. |
| False Negatives | FN | The model predicted negative but the actual label is positive. Also called Type II errors or misses. |
| True Negatives | TN | The model predicted negative and the actual label is negative. Correct negative predictions. |
Formulas Used in This Calculator
| Metric | Formula | Interpretation |
|---|---|---|
| Accuracy | (TP + TN) / (TP + FP + FN + TN) | Proportion of all predictions that are correct. |
| Precision (PPV) | TP / (TP + FP) | Of all predicted positives, what fraction are actually positive. |
| Recall / Sensitivity (TPR) | TP / (TP + FN) | Of all actual positives, what fraction did the model detect. |
| Specificity (TNR) | TN / (TN + FP) | Of all actual negatives, what fraction did the model correctly reject. |
| F1 Score | 2 * (Precision * Recall) / (Precision + Recall) | Harmonic mean of precision and recall. Balances both metrics into one. |
| MCC | (TP*TN - FP*FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN)) | A balanced measure even for imbalanced classes. Ranges from -1 to +1. |
| False Positive Rate (FPR) | FP / (FP + TN) | Proportion of actual negatives that are incorrectly classified as positive. |
| False Negative Rate (FNR) | FN / (FN + TP) | Proportion of actual positives that are incorrectly classified as negative. |
| Negative Predictive Value (NPV) | TN / (TN + FN) | Of all predicted negatives, what fraction are actually negative. |
Worked Example
Using the calculator defaults: TP = 50, FP = 10, FN = 5, TN = 35 (total = 100 observations).
- Accuracy: (50 + 35) / 100 = 85.00%
- Precision: 50 / (50 + 10) = 50 / 60 = 83.33%
- Recall: 50 / (50 + 5) = 50 / 55 = 90.91%
- Specificity: 35 / (35 + 10) = 35 / 45 = 77.78%
- F1 Score: 2 * (0.8333 * 0.9091) / (0.8333 + 0.9091) = 86.96%
- MCC: (50*35 - 10*5) / sqrt(60 * 55 * 45 * 40) = 1700 / sqrt(5,940,000) = 0.698
Choosing the Right Metric
Accuracy is intuitive but misleading when classes are imbalanced. For example, if 95% of samples are negative, a model that always predicts negative achieves 95% accuracy while being entirely useless for detecting positives.
Precision is critical when false positives are costly (for example, a spam filter that mistakenly blocks legitimate emails). Recall matters more when false negatives are costly (for example, a cancer screening test that misses actual cases). The F1 score balances the two. The MCC is widely considered the most reliable single-value summary for binary classification because it takes all four quadrants of the confusion matrix into account symmetrically.
Related Calculators
- Maths and Stats Calculators Hub
- Bayes Theorem Calculator
- Effect Size (Cohen's d) Calculator
- ANOVA Calculator
- Probability Calculator
Sources and method: Formulas sourced from Fawcett T. (2006), "An introduction to ROC analysis", Pattern Recognition Letters 27(8):861-874; Powers D.M.W. (2011), "Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness and Correlation", Journal of Machine Learning Technologies 2(1):37-63. MCC formula as defined by Matthews B.W. (1975), Biochimica et Biophysica Acta 405(2):442-451.
This calculator applies standard binary classification evaluation formulas to the values you enter. Results are valid for two-class (binary) problems only. For multi-class classification, an extended confusion matrix and macro/micro-averaged metrics are required.