induwara.lk
induwara.lkAI · Model evaluation

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.

By Induwara AshinsanaUpdated Jul 12, 2026
Matthews Correlation Coefficientbinary 2×2
scikit-learn formula · verified
Examples
Your confusion matrix

predicted +, actually +

predicted −, actually +

predicted +, actually −

predicted −, actually −

Matthews Correlation Coefficient (MCC)
0.7035Strong positive

Predictions and truth are strongly correlated across both classes — a genuinely good classifier, not just an accurate-looking one.

Cross-check (correlation form): 0.7035

Accuracy
0.850
85%
Precision (PPV)
0.818
90 / 110 predicted +
Recall (TPR)
0.900
90 / 100 actual +
Specificity (TNR)
0.800
80 / 100 actual −
F1 score
0.857
harmonic mean of precision & recall
Total samples
200
TP + TN + FP + FN

Formula breakdown

N = TP·TN − FP·FN = 90·80 20·10 = 7,000
D = √((TP+FP)(TP+FN)(TN+FP)(TN+FN)) = √(110·100·100·90) = 9,949.87
MCC = N / D = 0.7035

Reconstructed 2×2 matrix

Predicted +Predicted −Total
Actual +90 TP10 FN100
Actual −20 FP80 TN100
Total11090200
Computed in your browser — nothing is uploaded.

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:

  1. Numerator: N = (TP·TN) − (FP·FN). This is positive when the correct predictions on the diagonal outweigh the errors.
  2. 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).
  3. 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

Balanced classifier (MCC = 0.7035)

  1. TP=90, TN=80, FP=20, FN=10 (n=200)
  2. N = 90·80 − 20·10 = 7200 − 200 = 7000
  3. D = √(110·100·100·90) = √99,000,000 ≈ 9949.874
  4. MCC = 7000 / 9949.874 ≈ 0.7035
  5. Accuracy = 170/200 = 0.85 — MCC sits below it, the honest signal

Imbalanced 'always negative' trap (Accuracy 0.95, MCC = 0)

  1. 1000 samples: 50 positive, 950 negative; model predicts all negative
  2. TP=0, FN=50, TN=950, FP=0
  3. Accuracy = 950/1000 = 0.95 (looks great)
  4. Marginal (TP+FP) = 0 → denominator 0 → zero-marginal rule
  5. MCC = 0 — the model has learned nothing

Flipped labels (MCC = −1)

  1. TP=0, TN=0, FP=50, FN=50
  2. N = 0·0 − 50·50 = −2500
  3. D = √(50·50·50·50) = 2500
  4. MCC = −2500 / 2500 = −1.0
  5. A total-disagreement result — almost always swapped class labels

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

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.