Matthews Correlation Coefficient Calculator

Classification metrics

MCC0.704
Accuracy85.0 %
Numerator TP x TN - FP x FN1,750
Total cases100
How this was calculated
  1. Numerator: 40 x 45 - 5 x 10 = 1,750.
  2. Denominator: sqrt(45 x 50 x 50 x 55) = 2,487.47.
  3. Matthews correlation coefficient: 1,750 / 2,487.47 = 0.704.
  4. Accuracy on the same table is 85.0 %, which the MCC of 0.704 judges more honestly when classes are unbalanced.

Accuracy lies politely on imbalanced data: a classifier can score in the high nineties while failing the class that matters. The Matthews correlation coefficient refuses the flattery. It treats the confusion matrix as a correlation between truth and prediction, returning +1 only for a perfect classifier, 0 for chance, and -1 for a perfectly inverted one - and it uses all four cells, so no majority class can hide the minority's fate.

Enter true positives, false positives, false negatives and true negatives. The calculator returns the MCC with the accuracy, the numerator TP x TN - FP x FN, and the total number of cases. The precision-recall page on this site grades the same classifiers along the F1 axis; this page is the all-four-cells judge.

Worked examples

40/45/5/10, MCC 0.704

(40 · 45 · 5 · 10)

MCC0.704
Accuracy85.0 %
Numerator TP x TN - FP x FN1,750
Total cases100

Lopsided table, MCC 0.641

(90 · 5 · 3 · 2)

MCC0.641
Accuracy95.0 %
Numerator TP x TN - FP x FN444
Total cases100

Coin-flip table, MCC 0.000

(25 · 25 · 25 · 25)

MCC0.000
Accuracy50.0 %
Numerator TP x TN - FP x FN0
Total cases100

A correlation, not a rate

MCC is the Pearson correlation between the true and predicted binary labels - the phi coefficient of the 2x2 table - which expands to (TP x TN - FP x FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN)). The numerator is the determinant of the confusion matrix: positive when the diagonal dominates, zero when predictions and truth are independent, negative when the classifier is systematically backwards.

The first example - TP 40, TN 45, FP 5, FN 10, 100 cases in all - has numerator 40 x 45 - 5 x 10 = 1,750 and denominator sqrt(45 x 50 x 50 x 55) = 2,487.47, giving MCC 0.704. Its accuracy of 85.0 % sounds better than 0.704 feels, and that gap is the statistic doing its job.

Because it is a correlation, MCC inherits correlation's interpretive scale and its honesty under class imbalance: duplicate every negative case and accuracy climbs while MCC barely moves.

  • MCC = (TP TN - FP FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN))
  • +1 perfect, 0 chance, -1 perfectly inverted
  • Uses all four cells - no hiding in the majority class
  • Chi-square of the 2x2 table = n x MCC squared

Worked examples: three confusion matrices

Balanced competence: TP 40, TN 45, FP 5, FN 10. MCC 0.704, accuracy 85.0 %, numerator 1,750 over a denominator of 2,487.47. A solid classifier whose 10 missed positives are fully visible in the score.

The lopsided table: TP 90, TN 5, FP 3, FN 2. Accuracy gleams at 95.0 % while MCC says 0.641 - numerator only 444 against a denominator of 692.20, because the 3 false positives are weighed against a mere 5 true negatives. Both numbers are arithmetically correct; only one warns you how thin the negative evidence is. This is the imbalance case the statistic exists for.

The coin flip: all four cells at 25. Numerator exactly 0, MCC exactly 0.000, accuracy 50.0 %. A classifier at chance earns a chance score, however the cells are arranged - the control experiment every metric should pass.

MCC versus F1 and accuracy

F1 ignores true negatives entirely, which makes it the right score when negatives are an uninteresting background (retrieval) and the wrong one when they carry information (screening, fraud, diagnosis). MCC counts them; that is the whole difference in philosophy, and the second example shows its size - with only 5 true negatives in the table, every false positive is expensive and MCC says so.

Accuracy counts everything but weights by prevalence, so it grades the class distribution as much as the classifier. MCC's chance level stays 0 at any prevalence, which is why cross-study comparisons - different hospitals, different fraud rates - are meaningful in MCC and treacherous in accuracy.

The precision, recall and F-scores live on this site's F1 page, which computes that family from TP, FP and FN. When a single number must headline a report on imbalanced binary data, the methodological literature's recommendation is increasingly MCC, and this page exists to make it one form away.

Imbalance test: if duplicating the negative class changes your headline metric, the metric was grading prevalence, not the classifier. MCC barely moves; accuracy climbs.

The chi-square connection

Square the MCC, multiply by the number of cases, and you have the chi-square statistic of the 2x2 table (without continuity correction). The first example: 100 x 0.704 squared is about 49.6 - the association between truth and prediction is far beyond chance, as a matrix that clean should be.

This identity gives MCC a significance test for free and ties it to the contingency-table machinery elsewhere on this site - the chi-square and Fisher pages approach the same tables from the testing side. MCC is the effect size to their p-value: report both, and the reader knows whether the association matters as well as whether it exists.

It also explains MCC's behaviour at zero: a table with no association has chi-square near zero and MCC near zero - the third example's exact 0.000 - and a perfectly inverted classifier, MCC -1, is one relabelling away from perfection, which the sign usefully announces.

Edge cases: empty margins

If any row or column of the matrix sums to zero - the classifier never predicts positive, or the sample contains no positives - the denominator vanishes and MCC is undefined as a formula. Convention assigns 0 when the classifier is constant (it carries no information) and the question itself dissolves when a class is absent from the sample.

Software differs here, and silently: some libraries return 0, others NaN. When a pipeline reports an MCC of exactly 0.000 on a new dataset, check for a degenerate margin before concluding the model is at chance - the third example's honest 0.000 (all cells 25, denominator 2,500.00) and a degenerate 0 look identical in a summary table.

Small samples add their own caution: with few cases, a single flipped cell moves MCC by tenths. The statistic is exact arithmetic on the matrix; the matrix is the sample, and its uncertainty is the study's, not the formula's.

Using MCC in model selection

As a threshold-selection criterion, MCC usually peaks at a different operating point than accuracy - nearer the balance of the two error types - which is often the clinically or commercially right point. Sweeping the threshold and taking the MCC maximum is a defensible default when error costs are roughly symmetric.

For model comparison across datasets with different prevalences, MCC's stability is its virtue: the same classifier keeps roughly its MCC as prevalence shifts, while its accuracy and F1 wander. Benchmarks that pool datasets lean on it for exactly this reason.

Report the matrix. Every scalar summary - MCC included - discards something, and the four counts let any reader recompute every alternative. The calculator's inputs are the report's minimum honest contents.

MCC in genomics and machine-learning practice

The statistic began in biochemistry - Brian Matthews introduced it in 1975 to compare predicted and observed protein secondary structure - and genomics kept it alive through decades when accuracy ruled elsewhere. Its modern revival in machine learning tracks the spread of imbalanced benchmarks: fraud, intrusion, rare disease, defect detection, all domains where the second example's 95.0 % accuracy mirage is the daily trap.

Benchmark suites now report MCC beside F1 by default in several of those fields, and the pair is informative together: F1 grades the positive class's handling, MCC grades the whole matrix. A model strong on both has no corner to hide in.

For multi-class problems the generalisation (Gorodkin's Rk statistic) extends the correlation to the full confusion matrix; the binary case here is its foundation and the form most reports actually need.

Choosing the headline metric

A practical decision order: if the negative class is mere background and positives are the product, F1 headlines. If both classes carry consequences and prevalences vary between deployments, MCC headlines. If a regulator or a legacy literature fixes accuracy, report it - beside MCC, so the prevalence flattery is visible to any reader who knows the trick.

The first example is the teaching case: accuracy 85.0 % and MCC 0.704 from the same four counts, each true, each answering a different question. Metric choice is question choice, and the counts let every reader re-ask their own.

Whatever headlines, the confusion matrix itself belongs in the report. Four counts are a small price for letting every reader recompute every metric - including the ones the authors chose not to feature.

Worked check: the determinant by hand

The numerator rewards a hand check on the first example: TP x TN = 40 x 45 = 1,800; FP x FN = 5 x 10 = 50; the determinant is 1,750. The denominator's four margin products are 45, 50, 50 and 55, whose product is 6,187,500 and whose square root is 2,487.47 - and 1,750 / 2,487.47 = 0.704. Any implementation that cannot reproduce this chain on this matrix has a bug, whatever its documentation says.

The same check exposes the sign logic: swap the classifier's outputs and the determinant becomes -1,750 while the margins stand, so MCC flips to -0.704 - an inverted classifier is detected, not merely failed. Accuracy under the same swap reports 15.0 %, which detects failure but not its curable cause.

Keep the example as a regression test: it is small enough to verify on paper and rich enough to exercise every term of the formula.

FAQs

What is the MCC for TP 40, TN 45, FP 5, FN 10?

0.704.

What is the accuracy on that table?

85.0 %.

A classifier with 95.0 % accuracy - what is its MCC?

Only 0.641 when TN is just 5 of 100 cases.

What does a random classifier score?

0.000, however the cells are arranged at 25 each.

What is the numerator of the first example?

1,750 = 40 x 45 - 5 x 10.

Why prefer MCC for screening tests?

It punishes the 3 false positives against only 5 true negatives in the second example.

Sources

Related calculators

Chi-Square Test Calculator (2x2)
The chi-square test of independence for a 2x2 contingency table: statistic, p-value at 1 degree of freedom, and the phi effect size.
Cramer's V Calculator
Cramer's V effect size for a contingency table from the chi-square statistic, the sample size and the table dimensions, with Cohen's degrees-of-freedom-adjusted benchmarks for the strength of association.
Odds Ratio Calculator
Odds ratio and relative risk from a 2x2 table (exposed/unexposed × outcome/no outcome), with the 95% confidence interval for the odds ratio by the log method.