Matthews Correlation Coefficient Calculator - MCC from a Confusion Matrix

Use this Matthews correlation coefficient calculator to turn TP, TN, FP, and FN counts into MCC, accuracy, precision, recall, and F1 in one step.

Updated: July 8, 2026 • Free Tool

Matthews Correlation Coefficient Calculator

Actual positive cases the model predicted as positive.

Actual positives the model missed (predicted as negative).

Actual negatives the model wrongly predicted as positive.

Actual negatives the model predicted as negative.

Results

Total Samples
0samples
Matthews Correlation Coefficient (MCC) 0
Accuracy 0%
Precision (PPV) 0%
Recall (Sensitivity) 0%
Specificity (TNR) 0%
F1 Score 0%
False Positive Rate 0%
False Negative Rate 0%
Prevalence 0%

What Is the Matthews Correlation Coefficient Calculator?

The Matthews correlation coefficient calculator converts the four cell counts of a binary confusion matrix into a single, comparable correlation score plus the usual classification metrics. You enter true positives, false negatives, false positives, and true negatives, and the tool returns the MCC score, also known as the phi coefficient, alongside accuracy, precision, recall, specificity, and F1. In machine learning and statistics courses this number is the go-to summary when you need one value that reflects both classes honestly.

  • Grading a student classifier: Compare a logistic regression homework model against a target matrix without retyping the formula by hand.
  • Evaluating a rare-disease screen: Report MCC where false negatives are dangerous and the positive class is a small fraction of patients.
  • Comparing two model thresholds: Read off the four cells at each candidate cutoff and watch how MCC trades off against raw accuracy.
  • Writing a research methods section: Quote a single defensible summary statistic instead of cherry-picking the metric that flatters the model.

Most evaluation reports print a 2x2 matrix of TP, FN, FP, and TN, but the derived metrics live on different dashboards. A single page that takes the four counts and turns them into one correlation score makes reading a model quicker and keeps the comparison fair.

The top row covers actual positive cases (TP and missed FN), and the bottom row covers actual negative cases (FP and correct TN). MCC respects all four of these cells at once, so it does not reward a model that simply predicts the majority class.

If you need the full set of classification metrics, the Confusion Matrix Calculator builds accuracy, precision, recall, F1, specificity, and MCC from the same four counts.

How the Matthews Correlation Coefficient Calculator Works

The calculator reads the four cell counts, sums them into a total, and combines them with one formula. Denominators of zero are treated as undefined so the page never silently reports a metric that has no meaning for your matrix.

MCC = (TP x TN - FP x FN) / sqrt( (TP+FP) x (TP+FN) x (TN+FP) x (TN+FN) )
  • TP: True positives: actual positives the model predicted positive.
  • FN: False negatives: actual positives the model predicted negative.
  • FP: False positives: actual negatives the model predicted positive.
  • TN: True negatives: actual negatives the model predicted negative.
  • N: Total samples: TP + FN + FP + TN.

The numerator is TP times TN minus FP times FN, the signed agreement between predictions and reality. The denominator is the square root of the product of the four marginal sums, which normalizes the score so it always lands between minus one and one.

For binary classification this is mathematically the same as Pearson's phi coefficient, the correlation between two binary variables. That equivalence is why MCC behaves like a correlation: it can be negative when predictions and labels disagree systematically.

Worked example: balanced spam detector

TP = 50, FN = 10, FP = 5, TN = 100 (165 messages, 60 truly positive).

Numerator = 50 x 100 - 5 x 10 = 5000 - 50 = 4950. Denominator = sqrt(55 x 60 x 105 x 110) = sqrt(38,115,000) = 6173.5. MCC = 4950 / 6173.5 = 0.8018.

MCC = 0.8018, accuracy = 0.9091, precision = 0.9091, recall = 0.8333, F1 = 0.8696.

A strong classifier; the single number agrees with the high accuracy and balanced precision-recall.

Worked example: imbalanced medical screen

TP = 5, FN = 1, FP = 4, TN = 90 (100 patients, 6 truly positive).

Numerator = 5 x 90 - 4 x 1 = 450 - 4 = 446. Denominator = sqrt(9 x 6 x 94 x 91) = sqrt(462,036) = 679.7. MCC = 446 / 679.7 = 0.6562.

MCC = 0.6562, accuracy = 0.95, precision = 0.5556, recall = 0.8333.

Accuracy looks excellent because 90 of 100 are healthy, but MCC drops to 0.66, exposing the weak precision on the rare class.

According to Wikipedia: Matthews correlation coefficient, the MCC is a correlation between observed and predicted binary classifications ranging from -1 to +1.

After you have the MCC, the Statistics Calculator reports mean, median, variance, and standard deviation on the raw score list.

Key Concepts Explained

Four ideas explain why the Matthews correlation coefficient behaves the way it does. Read the names first, then return to them once you have a score to interpret.

Matthews correlation coefficient range

MCC spans from minus one to plus one. Plus one is a perfect classifier, zero is no better than a coin flip, and minus one means every prediction is inverted. The bounded range makes scores from different datasets directly comparable.

Phi coefficient equivalence

For a 2x2 table the MCC formula is identical to Pearson's phi coefficient. Both measure association between two binary variables, so MCC inherits the familiar correlation interpretation rather than being an arbitrary machine-learning metric.

Use of all four cells

Unlike accuracy, which only counts the diagonal, MCC multiplies and divides every cell. This is the reason it stays informative when one class dwarfs the other and why a high accuracy can coexist with a near-zero MCC.

Threshold dependence

MCC is calculated from a fixed confusion matrix, so it changes with the decision threshold that produced the four counts. Comparing MCC across thresholds shows the precision-recall trade-off as a single curve-friendly number.

Once these four ideas click, the rest of the classifier vocabulary - balanced accuracy, Cohen's kappa, F-beta - reads as a small rearrangement of the same four cells.

Because MCC is a correlation, it is symmetric: swapping which class you call positive flips the sign of the numerator but squares cancel in the denominator, so the magnitude is unchanged. That symmetry is handy when the 'positive' label is a matter of convention.

To test whether the association behind the MCC is significant, the Chi-Square Calculator turns the same 2x2 table into a chi-square statistic and p-value.

How to Use This Calculator

Four steps cover the typical workflow: pull the four counts from your report, type them in, read the MCC and companion metrics, then screen for undefined values.

  1. 1 Locate the four counts: Open the classification report or library output that shows TP, FN, FP, and TN. If you only have rates, multiply them back by the sample size to recover the counts.
  2. 2 Enter the four counts: Type each integer into the matching input. Decimals are truncated to whole numbers so the matrix always matches a real count.
  3. 3 Read the result panel: Watch the MCC update alongside accuracy, precision, recall, specificity, and F1. The score is the headline number; the companions tell you which cells drove it.
  4. 4 Check for undefined metrics: If MCC shows nothing, at least one marginal sum is zero, meaning a whole row or column of the matrix is empty. Inspect the denominator before quoting the score.
  5. 5 Save and compare to a baseline: Copy the row of metrics into your notebook or pull request and run the same matrix from a baseline model. The side-by-side makes it easy to argue a new threshold actually moved the metric you care about.

Example: read TP = 50, FN = 10, FP = 5, TN = 100 from a confusion matrix image, type them in, and the panel reports MCC 0.8018, accuracy 0.9091, precision 0.9091, recall 0.8333, F1 0.8696 - the same numbers you would get by hand.

When comparing MCC from two models, the T-Test Calculator checks whether the difference is larger than chance.

Benefits of Using This Calculator

These are the concrete benefits students, instructors, and machine learning practitioners get from one focused page.

  • One honest number for imbalanced data: MCC summarizes the full matrix, so a model that scores 99 percent accuracy on a rare-event dataset cannot hide behind that number.
  • Fewer formula mistakes: Typing the four cells once beats hand-computing a four-term square root in a spreadsheet, the most common source of sign and order errors.
  • Faster model reviews: A teammate pastes a confusion matrix in a pull request and you confirm the MCC within seconds instead of reconstructing it from partial metrics.
  • Comparable across datasets: Because MCC is always bounded from minus one to one, scores from unrelated projects can be ranked on the same axis.
  • Reinforces the matrix layout: Entering counts by hand forces you to remember which cell is TP and which is FN, the bug that most often corrupts student code.

The biggest payoff is the first time you build a model that looks 95 percent accurate on a rare-disease screen and then watch the MCC fall to 0.66, revealing that precision on the rare class is weak.

For instructors, linking the page in a course site lets students verify homework without handing them the answer key.

For summarizing the distribution of several MCC scores across folds, the Descriptive Statistics Calculator gives the full five-number summary.

Factors That Affect Your Results

Three factors move the MCC you see, and two caveats remind you when the single number should not be quoted alone.

Class imbalance

When the positive class is rare, the true-negative cell dominates accuracy but not MCC. The score falls to reflect the weak performance on the rare class that accuracy hides.

Choice of positive label

Swapping which class you call positive flips TP with TN and FP with FN. MCC is symmetric, so the magnitude is unchanged but the sign can flip; pick the label that matches the cost you care about.

Decision threshold

The same model produces a different confusion matrix at every probability cutoff. Lowering the threshold usually raises recall and lowers precision, and the calculator shows how MCC tracks that trade-off as you type each candidate matrix.

  • This tool is built for binary classification. Multi-class problems must be collapsed into one-versus-rest counts before the four cells make sense.
  • Counts are entered as integers and truncated. If your pipeline reports fractional counts, normalize to the nearest whole number first, because the formula assumes discrete events.

If you need a single number to summarize a binary classifier on an imbalanced dataset, prefer the Matthews correlation coefficient over accuracy. It uses every cell, so it cannot be inflated by a dominant negative class.

The matrix is only as honest as the labels you started with. Noisy ground truth, common in medical imaging or user-tagged datasets, propagates straight into the score.

According to scikit-learn: Model evaluation, MCC is identical to phi and handles imbalanced data better than accuracy, precision, and F1.

If your counts came from a fixed trial count, the Binomial Distribution Calculator shows how unusual the observed false-negative total is under the null.

Matthews correlation coefficient calculator that converts a 2x2 confusion matrix into MCC, phi, accuracy, precision, recall, and F1
Matthews correlation coefficient calculator that converts a 2x2 confusion matrix into MCC, phi, accuracy, precision, recall, and F1

Frequently Asked Questions

Q: What is the Matthews correlation coefficient?

A: The Matthews correlation coefficient (MCC) is a single number that summarizes how well a binary classifier's predictions match the actual labels. It is computed from the four cells of a 2x2 confusion matrix: true positives, false negatives, false positives, and true negatives. Algebraically it is the Pearson correlation coefficient between the predicted and actual classes, which is why it is also called the phi coefficient.

Q: What range does the Matthews correlation coefficient cover?

A: The Matthews correlation coefficient ranges from minus one to plus one. An MCC of plus one means every prediction is correct, an MCC of zero means the classifier performs no better than random guessing, and an MCC of minus one means every prediction is inverted. Most real models land somewhere between zero and one, and values above 0.5 usually indicate a model worth keeping.

Q: How do you interpret a Matthews correlation coefficient of 0?

A: An MCC of zero means the classifier carries no more information about the true labels than a coin flip would. It does not mean the model is useless in every cell; it means that once you account for class sizes and all four kinds of error, the predictions are uncorrelated with reality. Treat it as a red flag to revisit features, data, or the chosen decision threshold.

Q: When should I use the Matthews correlation coefficient instead of accuracy?

A: Reach for the Matthews correlation coefficient whenever the two classes are not balanced, or when a false positive and a false negative carry different costs. Accuracy divides correct predictions by the total and is easily inflated by a dominant negative class. MCC uses all four confusion-matrix cells, so it stays honest on skewed datasets where accuracy looks reassuring but the model is quietly failing the rare class.

Q: Is the Matthews correlation coefficient the same as the phi coefficient?

A: Yes, for binary classification the two are identical. The phi coefficient is the Pearson correlation between two binary variables, which expands exactly to the MCC formula (TP times TN minus FP times FN, divided by the square root of the product of the four marginal sums). They differ only in framing: phi is the general association measure, MCC is its application to predicted versus actual labels.

Q: Why is the Matthews correlation coefficient better for imbalanced datasets?

A: Imbalanced datasets have one very large confusion-matrix cell, usually true negatives, which dominates accuracy, precision, and recall individually. MCC multiplies TP by TN and subtracts FP by FN, then normalizes by all four marginal sums, so no single cell can hide a poor prediction on the rare class. That is why a model can score 95 percent accuracy yet return an MCC near zero when it simply predicts the majority class for everything.