induwara.lk
induwara.lkMachine Learning · Metrics

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.

By Induwara AshinsanaUpdated Jun 14, 2026
Matthews Correlation Coefficient
Confusion matrix counts

Actual positive, predicted positive.

Actual negative, predicted positive.

Actual positive, predicted negative.

Actual negative, predicted negative.

Try a preset
MCC
0.7035
Strong positiveverified 2 ways
Accuracy
85%
170 of 200 correct
F1 score
0.8571
Precision 0.9000 · Recall 0.8182
Verdict

Predictions track the ground truth closely — a dependable classifier.

Where it sits on the scale

−1 · inverse0 · random+1 · perfect

Confusion matrix used

Predicted +
Predicted −
Actual +
TP
90
FN
20
Actual −
FP
10
TN
80

Formula with your numbers

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

= (90·8010·20) / √[100·110·90·100]

= 7,000 / 9,949.87

= 0.7035

Sources cited: scikit-learn matthews_corrcoef, Chicco & Jurman (2020). Full references below.

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:

  1. Numerator = (TP · TN) − (FP · FN). This rewards correct predictions on both classes and penalises both error types.
  2. Denominator = √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]. The four factors are the row and column totals of the matrix.
  3. MCC = numerator ÷ denominator, which always lands in the range −1 to +1.
  4. 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

Typical classifier

TP = 90, FP = 10, FN = 20, TN = 80

  1. Numerator: (90·80) − (10·20) = 7200 − 200 = 7000
  2. Denominator: √[(90+10)(90+20)(80+10)(80+20)] = √[100·110·90·100]
  3. = √99,000,000 = 9949.874
  4. MCC = 7000 / 9949.874 = 0.7035
  5. Contrast: accuracy = 170/200 = 0.85, F1 = 180/210 = 0.857 — both rosier than MCC.

Perfect classifier (upper bound)

TP = 50, FP = 0, FN = 0, TN = 50

  1. Numerator: (50·50) − (0·0) = 2500
  2. Denominator: √[(50)(50)(50)(50)] = √6,250,000 = 2500
  3. MCC = 2500 / 2500 = 1.0
  4. Confirms the +1 upper bound for flawless predictions.

Lazy classifier on imbalanced data

TP = 0, FP = 0, FN = 5, TN = 95 (predicts 'negative' for everything)

  1. Accuracy: (0 + 95) / 100 = 0.95 — looks excellent.
  2. F1: 2·0 / (2·0 + 0 + 5) = 0 — already a warning.
  3. Numerator: (0·95) − (0·5) = 0
  4. Denominator factor (TP+FP) = 0 → denominator = 0 → MCC = 0.
  5. MCC correctly reports the model learned nothing despite 95% accuracy.

Frequently asked questions

Sources & references

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

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.