Machine LearningClassification Evaluation

What is Matthews correlation coefficient (MCC) in classification?

Matthews correlation coefficient (MCC) summarizes how well predicted and actual class labels agree, taking all four confusion-matrix counts into account. For binary classification it is also called the *phi coefficient*. It is often informative when one class is much rarer than the other.

Binary MCC formula

MCC = (TP × TN − FP × FN) / √[(TP + FP)(TP + FN)(TN + FP)(TN + FN)].

Beginner-friendly numerical example

A model classifies 20 transactions as Fraud or Not Fraud:

  • TP = 6: fraudulent transactions correctly flagged.
  • TN = 8: legitimate transactions correctly cleared.
  • FP = 2: legitimate transactions wrongly flagged.
  • FN = 4: fraudulent transactions missed.

Step 1 — Numerator: (6 × 8) − (2 × 4) = 48 − 8 = 40.

Step 2 — Denominator: √[(6 + 2)(6 + 4)(8 + 2)(8 + 4)] = √(8 × 10 × 10 × 12) = √9600 ≈ 97.98.

Step 3 — MCC: 40 / 97.98 ≈ 0.408.

This indicates positive but imperfect association between predicted and actual labels.

Interpreting the score

  • +1: perfect binary classification.
  • 0: no correlation between predictions and true labels; it does not prove a model makes random predictions.
  • −1: completely inverted binary predictions.
  • Between: stronger positive scores generally indicate better overall label association, but consider class frequencies and operational consequences.

Why MCC rather than only accuracy or F1?

  • Here accuracy = (6 + 8)/20 = 70% and F1 = 2×6/(2×6 + 2 + 4) ≈ 66.7%, while MCC ≈ 0.408.
  • Accuracy counts correct cases, but a model predicting only the majority class can look good when classes are imbalanced.
  • Positive-class F1 combines TP, FP, and FN but ignores TN; binary MCC includes all four counts.
  • MCC is useful as an additional summary, not a replacement for per-class recall, precision, and the cost of missing important cases.

Python example

PYTHON
from sklearn.metrics import matthews_corrcoef, accuracy_score, f1_score # TP=6, FN=4, FP=2, TN=8 y_true = [1]*10 + [0]*10 y_pred = [1]*6 + [0]*4 + [1]*2 + [0]*8 print(round(matthews_corrcoef(y_true, y_pred), 3)) # 0.408 print(accuracy_score(y_true, y_pred)) # 0.7 print(round(f1_score(y_true, y_pred), 3)) # 0.667

Multiclass extension

  • The same scikit-learn function supports single-label multiclass classification, using the complete K-class confusion matrix rather than independently averaging several binary MCC scores.
  • The multiclass result still has maximum +1; the most negative attainable value can depend on the number of classes and their distributions. Do not assume −1 is attainable in every multiclass problem.
  • Use separate per-class diagnostics to identify which categories are confused.

Limitations and practical use

  • Degenerate predictions: the binary denominator can be zero if a class is absent from actual or predicted labels. The formula is then undefined; scikit-learn's implementation returns 0 in this situation. Interpret that output carefully.
  • Rare positives: small test sets make any single metric unstable. Report class support and uncertainty alongside MCC.
  • No business-cost weighting: MCC does not know that missing a fraud may be more costly than a false alert. Consider cost-sensitive metrics separately.
  • Use cases: fraud detection, quality inspection, clinical classifiers, and other binary or multiclass tasks where class frequencies may be unequal.

Key takeaway: MCC assesses the association between predictions and ground truth using the whole confusion matrix, making it a valuable complement to accuracy and F1, particularly on imbalanced data.

References

#Matthews correlation coefficient#MCC classification#MCC example#MCC formula#MCC imbalanced dataset#classification#evaluation#MCC#class imbalance

Learning Sequence

Machine Learning Curriculum

85% Completed
Up NextMachine Learning

What is weighted Cohen's kappa, and when should you use it?

Explore Related Questions

Deepen your understanding across related Machine Learning topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.