Confusion Matrix Calculator, Precision, Recall, F1 & MCC
Paste the four cells of a binary confusion matrix and get every standard classification metric at once, accuracy, precision, recall, specificity, F1, F-beta, balanced accuracy, the Matthews correlation coefficient and Cohen's kappa, each shown with the exact formula it came from. Free, no signup, runs in your browser.
How it works
A confusion matrix is the 2×2 table a binary classifier produces when you compare its predictions against the truth. It has four cells: true positives (TP) and true negatives (TN), where the model agreed with reality, and false positives (FP, a Type I error) and false negatives (FN, a Type II error), where it did not. Every metric on this page is derived from those four counts, with the sample size N = TP + FP + FN + TN.
The headline metrics follow the standard definitions used by scikit-learn and the Wikipedia confusion-matrix table:
- Accuracy = (TP + TN) / N
- Precision (PPV) = TP / (TP + FP)
- Recall / Sensitivity (TPR) = TP / (TP + FN)
- Specificity (TNR) = TN / (TN + FP)
- F1 = 2·TP / (2·TP + FP + FN)
- F-beta = (1 + β²)·P·R / (β²·P + R)
F1 is the harmonic mean of precision and recall, which is why it drops hard when either one is weak. The F-beta form, from van Rijsbergen's 1979 information-retrieval text, lets you weight recall β times as heavily as precision, β > 1 favours recall, β < 1 favours precision. This calculator computes F-beta from the raw counts and cross-checks it against the precision/recall form so the two always agree to the last decimal.
The Matthews correlation coefficient takes the whole table into account:
MCC = (TP·TN − FP·FN) / √((TP+FP)(TP+FN)(TN+FP)(TN+FN))
Because MCC uses all four cells, including the true negatives that precision, recall and F1 ignore. It stays trustworthy when one class vastly outnumbers the other. It ranges from −1 to +1, where 0 means the predictions are no better than chance. Balanced accuracy, (TPR + TNR) / 2, and informedness (Youden's J), TPR + TNR − 1, are two other imbalance-aware summaries shown in the full table, alongside Cohen's kappa, κ = (pₒ − pₑ) / (1 − pₑ): accuracy (pₒ) corrected for the agreement pₑ that the row and column totals would produce by chance alone. Each metric is computed independently from the integer counts, never from rounded intermediates, so no rounding error compounds. When a denominator is zero the metric is genuinely undefined (for example precision when nothing is predicted positive), and the tool labels it “undefined” rather than printing a misleading 0.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn: Model evaluation: classification metrics (precision, recall, F1, F-beta, balanced accuracy, MCC)
- Wikipedia: Confusion matrix (canonical table of every derived rate)
- Matthews correlation coefficient (phi coefficient): definition and properties
- B. W. Matthews (1975), Biochim. Biophys. Acta 405(2):442–451: original MCC paper
- scikit-learn: cohen_kappa_score (after J. Cohen, 1960, Educational and Psychological Measurement 20(1):37–46)
Every formula on this page was cross-checked against the scikit-learn and Wikipedia definitions on 2026-06-07, and Cohen's kappa against scikit-learn's cohen_kappa_score on 2026-07-08. The tool runs entirely in your browser, your counts never leave your device.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us, our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, an edge case, or want multi-class support added?
Email me at [email protected] , most fixes ship within 24 hours.