Matthews Correlation Coefficient

Statistics
Introduced by
Brian W. Matthews
Year
1975
Type
Evaluation metric
Family
Classification Metric

What does it do?

The Matthews Correlation Coefficient (MCC) measures the association between predicted and actual binary labels on a scale from -1 to 1.

It uses all four cells of the confusion matrix, so it summarises both classes in a single score, which is useful when class frequencies are uneven. It was introduced by Brian W. Matthews in 1975.

The intuition behind the method

MCC is the Pearson correlation computed on a two-by-two table that cross-tabulates predicted labels against actual labels, which is why it is also known as the phi coefficient. Because it uses true positives, true negatives, false positives and false negatives together, a high value requires the classifier to get both classes right rather than only the majority class. An MCC of 1 means perfect prediction, 0 means no association between predictions and labels (random-like behaviour), and -1 means predictions are perfectly inverted. This makes the score informative in cases where a classifier could otherwise look good by favouring the larger class.

History

Matthews introduced the coefficient in 1975 to compare predicted and observed secondary structure of T4 phage lysozyme.

When to use it

Choose MCC when you have a binary classifier that outputs hard labels, the classes are imbalanced, and both classes matter, so that a single summary score should not reward predicting the larger class. It suits comparing classifiers on the same test set when the confusion matrix is available. Do not rely on MCC alone when only the positive class matters, as in some fraud or screening settings, where F1-score may be more appropriate. It is not a direct fit for multi-class problems without an explicit extension, and it does not evaluate the quality of predicted scores or probabilities, only the thresholded labels.

Limitations and considerations

  • Its value still shifts with class prevalence, because all four cells enter the formula; a classifier with the same per-class error rates can obtain a different MCC on a test set with a different class ratio.
  • It is undefined when a marginal total is zero (for example, no positive predictions at all). Under the zero-denominator convention given in the calculation step, MCC is set to 0, which can make a degenerate classifier look like random chance instead of flagging the problem.
  • It is not a probability and summarises hard labels only, so it says nothing about the calibration of predicted scores.
  • Values reported in other studies may use different conventions or decision thresholds, so recalculating MCC from the confusion matrix may be needed before comparing results across studies.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Uses all four confusion-matrix cells, so a high value requires good performance on both the positive and the negative class rather than on the majority class alone.
  • Invariant to which class is labelled positive: exchanging TP with TN and FP with FN leaves both the numerator and the denominator unchanged, so the score does not depend on the labelling convention.
  • Gives a fixed reference point: a value of 0 corresponds to no association between predictions and labels, which makes results easier to interpret than raw counts.

Applications

  • Medical diagnosis of rare conditions, where reporting MCC alongside sensitivity and specificity shows performance on both diseased and healthy cases.
  • Classification of proteins with uneven class frequencies, where a single score covering both classes is needed.
  • Detection of rare events such as security attacks, where a score that is not inflated by correct predictions of the abundant normal class can complement accuracy.
  • Benchmark comparisons across datasets with different class ratios, noting that the value still depends on prevalence.

How it works

How it works

1

Count true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) from the confusion matrix.

2

Compute MCC = (TP*TN - FP*FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN)). If any denominator term is zero, define MCC = 0.

3

MCC ranges from -1 to 1. Values near 1 indicate strong agreement between predictions and actual labels. Values near 0 indicate little or no association, as expected from random prediction. Negative values indicate that predictions are systematically opposed to the actual labels, which is worse than random.

Common pitfalls

  • Reporting MCC without the confusion matrix or per-class counts hides which kind of error is driving a low value.
  • The decision threshold changes the four counts and therefore the MCC; the threshold should be stated alongside the score.
  • Applying a multi-class extension without naming it. The FAQ describes per-class one-vs-rest values, and different extensions should not be treated as equivalent.

Frequently asked questions

How does MCC compare to F1-score for imbalanced datasets?

Both are more informative than raw accuracy on imbalanced data, but they weight the classes differently. MCC is symmetric and uses true negatives, so it reflects performance on both classes. F1-score ignores true negatives and focuses on the positive class, so it may be preferable when the positive class is the only concern, as in fraud detection.

What does negative MCC mean?

A negative MCC means predictions tend to run opposite to the actual labels: positives are often predicted for negative cases and vice versa. A value of -1 corresponds to perfectly inverted predictions. Values below zero are worse than the value of 0 for random-like prediction, and a strongly negative result can indicate a coding error such as swapped class labels.

Can MCC be computed for multi-class problems?

The original formula is defined for two classes. For more than two classes, one option is a per-class value that treats each class as positive against all others. Several multi-class generalisations exist, so the variant used should be stated when results are reported.

Related methods

Sources

  1. Matthews, B. W. (1975). Comparison of predicted and observed secondary structure of T4 phage lysozyme. Biochimica et Biophysica Acta (BBA)-Protein Structure, 405(2), 442-451.

    Open DOI reference
  2. Powers, D. M. (2011). Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness and Correlation. Journal of Machine Learning Technologies, 2(1), 37-63.

    Open publication reference