Matthews Correlation Coefficient (MCC) Calculator
Paste your binary classifier's confusion matrix — TP, TN, FP, FN — and get the Matthews Correlation Coefficient instantly, alongside accuracy, precision, recall, specificity and F1. MCC is the balanced score that plain accuracy hides on imbalanced data. Free, no signup, formula shown.
How it works
The Matthews Correlation Coefficient (MCC), also called the phi coefficient, measures the correlation between a binary classifier's predictions and the ground truth. It was introduced by B. W. Matthews in 1975 and is the metric scikit-learn exposes as matthews_corrcoef. This tool uses the same definition and returns the same numbers.
Everything starts from the four cells of a 2×2 confusion matrix: true positives (TP), true negatives (TN), false positives (FP) and false negatives (FN). The coefficient is computed in three steps:
- Numerator:
N = (TP·TN) − (FP·FN). This is positive when the correct predictions on the diagonal outweigh the errors. - Denominator:
D = √((TP+FP)(TP+FN)(TN+FP)(TN+FN))— the square root of the product of the four row and column totals (the confusion-matrix marginals). MCC = N / D, always in the range −1 to +1.
There is one important edge rule, and this tool follows the scikit-learn convention exactly: if any of the four marginals (TP+FP), (TP+FN), (TN+FP) or (TN+FN) is zero, the denominator is zero and MCC is defined as 0. A classifier that always predicts one class has no correlation with the truth, no matter how high its accuracy looks.
MCC reads −1 as total disagreement, 0 as no better than random, and +1 as perfect prediction. Because all four cells appear in the formula and the metric is symmetric under swapping the classes, it is hard to fool on skewed datasets — the property Chicco & Jurman (2020) highlight when they recommend MCC over accuracy and F1 for binary evaluation. For context the tool also derives the metrics that only use part of the matrix — accuracy (TP+TN)/n, precision TP/(TP+FP), recall TP/(TP+FN), specificity TN/(TN+FP) and F1 — so you can see exactly why MCC and accuracy can tell different stories. As a self-check it recomputes MCC through the equivalent class-proportion correlation form and shows both values.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.matthews_corrcoef (formula, range, zero-marginal convention)
- Matthews, B. W. (1975) — Comparison of the predicted and observed secondary structure of T4 phage lysozyme (original definition)
- Chicco & Jurman (2020) — The advantages of the MCC over F1 score and accuracy in binary classification evaluation, BMC Genomics 21:6
The formula and worked examples were last cross-checked against the scikit-learn matthews_corrcoef definition on 2026-07-12. All three worked examples above are reproduced exactly by the calculator.
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, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.