Matthews Correlation Coefficient (MCC) Calculator
Compute the Matthews Correlation Coefficient from a confusion matrix or two pasted label columns. See the substituted formula, the −1…+1 interpretation, and how MCC compares with accuracy and F1 on the same data — all in your browser, no signup.
How it works
The Matthews Correlation Coefficient treats a binary classifier's output and the ground truth as two binary variables and measures their correlation — it is the Pearson phi coefficient applied to a 2×2 confusion matrix, first proposed by Matthews in 1975. Unlike accuracy or F1, it uses all four cells of the matrix, so it cannot be fooled by class imbalance.
For a confusion matrix with True Positives (TP), True Negatives (TN), False Positives (FP) and False Negatives (FN), the coefficient is:
- Numerator = (TP · TN) − (FP · FN). This rewards correct predictions on both classes and penalises both error types.
- Denominator = √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]. The four factors are the row and column totals of the matrix.
- MCC = numerator ÷ denominator, which always lands in the range −1 to +1.
- Zero-denominator rule. If any of those four sums is 0 (for example the model never predicts the positive class), the denominator is mathematically 0. Following scikit-learn, MCC is then defined as 0 — there is no correlation to measure.
The scale is intuitive: +1 is a perfect classifier, 0 is no better than flipping a coin, and −1 is total disagreement (every prediction wrong). This calculator also reports accuracy = (TP+TN)/total and F1 = 2·TP/(2·TP+FP+FN) on the same numbers, so you can see directly how much rosier those metrics look on imbalanced data.
Every result is verified two ways. The main path uses the formula above; an independent cross-check recomputes MCC as a Pearson correlation from the marginal totals, (TP·N − S·P) / √(S·P·(N−S)·(N−P)), where N is the total, S the actual positives and P the predicted positives. Both forms are algebraically identical and must agree to within floating-point precision before the "verified 2 ways" badge shows.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — matthews_corrcoef (reference implementation, range and zero-denominator convention)
- Chicco & Jurman (2020), BMC Genomics 21:6 — MCC over F1 and accuracy on imbalanced data
- Matthews, B. W. (1975), Biochimica et Biophysica Acta 405(2):442–451 — the original definition
The formula and the zero-denominator convention were last cross-checked against the scikit-learn documentation on 2026-06-14. The three worked examples (0.7035, 1.0, 0) match scikit-learn's output exactly.
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.