Binary Classification & Machine Learning Diagnostics

Matthews Correlation Coefficient Calculator

Calculate the Matthews Correlation Coefficient (MCC / Phi Coefficient) from a 2x2 confusion matrix. Provides an unskewed, balanced evaluation of binary machine learning models on imbalanced datasets.

2x2 Confusion Matrix Grid
Actual (+) & Pred (+)
Type I Error
Type II Error
Actual (-) & Pred (-)

Enter non-negative integers for all four quadrants. The total sample size (N = TP + TN + FP + FN) is updated in real time.

Matthews Correlation Coefficient (MCC)
+0.651
Moderate Positive Correlation (0.40 ≤ MCC < 0.70)
N = 200 evaluations
Raw Accuracy 82.5% (TP+TN)/N
Balanced Accuracy 82.6% (TPR+TNR)/2
F1-Score 0.829 Harmonic Mean
Precision (PPV) 85.0% TP / (TP+FP)
Recall (Sensitivity) 81.0% TP / (TP+FN)
Specificity (TNR) 84.2% TN / (TN+FP)
Machine Learning Evaluation & Class Imbalance

Critical Problems This Matthews Correlation Coefficient Calculator Solves

Standard classification metrics like Accuracy and F1-Score produce severely misleading conclusions on imbalanced datasets. Our matthews correlation coefficient calculator provides mathematical clarity:

Exposing the 99% Accuracy Trap on Imbalanced Data

If 99 out of 100 cases are negative (e.g. credit card fraud or rare tumors), a dummy classifier predicting 'Negative' for every transaction achieves 99% accuracy while detecting 0 frauds. MCC scores this dummy model at 0.00, instantly revealing its complete failure.

Fixing F1-Score Blindness to True Negatives

The F1-Score formula ignores True Negatives (\(TN\)) entirely. As a result, F1 cannot distinguish whether a classifier is correctly rejecting negative instances. MCC incorporates all four confusion matrix quadrants with equal mathematical dignity.

Symmetric Class Invariance

In F1-score, swapping which class is defined as 'positive' drastically alters the score. MCC is completely invariant to class assignment: labeling benign as positive yields the exact same MCC as labeling malignant as positive.

Bioinformatics & Genomics Verification

In DNA motif detection and protein folding prediction, non-binding background sites outnumber target binding sites by 1,000-to-1. Computational biologists mandate MCC as the golden benchmark for peer-reviewed algorithmic validity.

Features Available in the MCC Calculator

Normalized -1 to +1 Range

Standard correlation scale: +1 is perfect, 0 is random guessing, -1 is total inverse disagreement.

6-Metric Diagnostic Suite

Simultaneously evaluates Accuracy, Balanced Accuracy, F1-Score, Precision, Recall, and Specificity.

Preset Imbalance Scenarios

One-click presets for fraud detection, rare disease screening, balanced tests, and random coin tosses.

Audit Export

Copy complete confusion matrix statistics formatted for peer-reviewed journal submission.

How to Use the Matthews Correlation Coefficient Calculator

1

Input True Positives (TP)

Enter actual positive instances correctly classified as positive.

2

Input False Positives (FP)

Enter negative cases falsely labeled as positive (Type I errors).

3

Input False Negatives (FN)

Enter positive cases falsely labeled as negative (Type II errors).

4

Input True Negatives (TN)

Enter actual negative instances correctly identified as negative.

5

Evaluate MCC Score

Review the calculated correlation score and qualitative strength badge.

6

Review Diagnostic Ratios

Check Balanced Accuracy, F1-Score, Sensitivity, and Specificity.

Mathematical & Algebraic Formulations

Given a binary 2x2 confusion matrix, the Matthews Correlation Coefficient (MCC) is defined as:

$$\text{MCC} = \frac{(TP \times TN) - (FP \times FN)}{\sqrt{(TP + FP)(TP + FN)(TN + FP)(TN + FN)}}$$

If any sum term in the denominator equals zero, the denominator is set to 1 by convention, resulting in \(\text{MCC} = 0\).

Complementary classification equations:

$$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} \quad,\quad \text{Balanced Accuracy} = \frac{1}{2}\left(\frac{TP}{TP + FN} + \frac{TN}{TN + FP}\right)$$
$$\text{F1-Score} = \frac{2 \times TP}{2 \times TP + FP + FN}$$

Worked Case Study: Rare Disease Screening Test (\(N = 1{,}000\))

Scenario: A clinical screening diagnostic evaluates 1,000 patients for a rare disease (5% prevalence, 50 positive cases, 950 negative cases). The test produces:

  • Confusion Matrix: \(TP = 45\), \(TN = 940\), \(FP = 10\), \(FN = 5\).
  • Numerator Calculation: \((45 \times 940) - (10 \times 5) = 42{,}300 - 50 = \mathbf{42{,}250}\).
  • Denominator Calculation: $$\sqrt{(45 + 10)(45 + 5)(940 + 10)(940 + 5)} = \sqrt{(55)(50)(950)(945)} = \sqrt{2{,}468{,}812{,}500} \approx \mathbf{49{,}687.15}$$
  • Matthews Correlation Coefficient (MCC): \(\text{MCC} = \frac{42{,}250}{49{,}687.15} = \mathbf{+0.850}\).
  • Comparative Diagnostics: Raw Accuracy = \((45 + 940)/1000 = 98.5\%\), Recall = \(45/50 = 90.0\%\), Specificity = \(940/950 = 98.9\%\), F1-Score = \(0.857\).
  • Conclusion: An MCC of +0.850 proves the model is exceptionally robust and reliably predicts both positive and negative cases despite the severe 19:1 class imbalance.

Machine Learning Evaluation Best Practices

Never Rely on Accuracy Alone

Accuracy is dangerous on imbalanced data because majority class dominance masks total failure on the minority class. Always compute MCC or Balanced Accuracy.

Use MCC for Hyperparameter Tuning

When using GridSearchCV in scikit-learn, set `scoring='matthews_corrcoef'`. Optimizing models against MCC ensures balanced trade-offs between precision and recall.

Evaluate Decision Threshold Sweeps

Default classification thresholds of 0.50 are often suboptimal for rare events. Graph MCC across thresholds from 0.05 to 0.95 to pinpoint maximum correlation.

Check for Zero Denominators

If a classifier predicts only one class, the denominator becomes zero. Treat undefined MCC as 0.00 to properly penalize degenerate, uninformative models.

Matthews Correlation Coefficient Interpretation Matrix

MCC Range Model Quality Tier Predictive Utility Practical Translation
+1.000 Perfect Prediction Flawless Accuracy FP = FN = 0; 100% correct in both classes
+0.70 to +0.99 Strong / Excellent High Production Grade Reliable medical & financial deployment
+0.40 to +0.69 Moderate Positive Acceptable Baseline Useful heuristic; needs further feature engineering
+0.20 to +0.39 Weak Correlation Low Predictive Power Marginal improvement over chance
-0.19 to +0.19 Random / Chance No Practical Utility Equivalent to flipping an unbiased coin
-1.000 Total Inversion Complete Disagreement Inverting all predictions yields a perfect model

Classification Metrology Glossary

Phi Coefficient (\(\phi\))

A measure of the degree of association between two binary variables in a 2x2 contingency table, mathematically identical to MCC.

Balanced Accuracy

The unweighted average of Sensitivity (True Positive Rate) and Specificity (True Negative Rate), preventing majority class bias.

Harmonic Mean

The reciprocal of the arithmetic mean of the reciprocals, used in F1-score to penalize extreme imbalances between Precision and Recall.

Breakdown Point

The proportion of corrupt or distorted observations an estimator can handle before producing an arbitrarily incorrect result.

Frequently Asked Questions

What is the Matthews Correlation Coefficient (MCC)?
The Matthews Correlation Coefficient (MCC), also known as the Phi coefficient in 2x2 contingency tables, is a metric used in machine learning and bioinformatics to measure the quality of binary classifications. Unlike Accuracy or F1-Score, MCC takes into account all four confusion matrix quadrants (TP, TN, FP, FN) and produces a balanced score between -1 and +1.
Why is MCC superior to Accuracy and F1-Score on imbalanced data?
On an imbalanced dataset where 99% of samples are negative (e.g. rare disease diagnosis or fraud detection), a trivial classifier predicting 'negative' for every case achieves 99% accuracy but has zero predictive utility. F1-score ignores true negatives completely. MCC evaluates all four quadrants equally, penalizing trivial models with an MCC near 0.00.
What is the mathematical formula for MCC?
The formula is: MCC = (TP * TN - FP * FN) / sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)). If any of the four sum terms in the denominator is zero, the denominator is set to 1 by convention, yielding MCC = 0.
What do the different values of MCC mean?
An MCC of +1.0 represents a perfect prediction where FP = FN = 0. An MCC of 0.0 indicates a prediction no better than a random coin toss. An MCC of -1.0 indicates total disagreement or complete inverse prediction.
What is considered a good MCC score in machine learning?
In practical machine learning, an MCC above 0.70 is considered strong to excellent; between 0.40 and 0.70 is moderate; between 0.20 and 0.40 is fair; and below 0.20 indicates poor or negligible predictive capacity.
How is MCC related to Pearson's correlation coefficient?
When binary classes are encoded as 0 and 1, the Matthews Correlation Coefficient is mathematically identical to the Pearson product-moment correlation coefficient between the actual binary labels and the predicted binary labels.
How does MCC handle multiclass classification?
While this calculator focuses on binary 2x2 classifications, Gorodkin generalized MCC to K x K multi-class confusion matrices using covariance matrix formulations across all classes.
Can MCC be calculated if one category has zero predictions?
If a model never predicts the positive class (TP = 0 and FP = 0), the denominator contains a zero term. Mathematically, the correlation is undefined, but by international convention, it is assigned 0.00 to reflect a model with no discriminatory power.
What is Balanced Accuracy and how does it compare to MCC?
Balanced Accuracy is the arithmetic mean of Sensitivity and Specificity: (TPR + TNR) / 2. While Balanced Accuracy is also robust against class imbalance, MCC provides a tighter, stricter correlation metric that accounts for class proportions.
Why is MCC heavily utilized in bioinformatics and genomics?
In bioinformatics (e.g. protein secondary structure prediction or disease mutation mapping), non-functional sites vastly outnumber functional sites. MCC prevents models from appearing successful simply by over-predicting the majority negative background class.
How does swapping positive and negative class labels affect MCC?
MCC is entirely symmetric: swapping what you define as 'positive' and 'negative' yields the exact same MCC value. In contrast, F1-score changes drastically when positive and negative definitions are swapped.
Can MCC be used to optimize classification decision thresholds?
Yes. Data scientists plot MCC across different probability decision thresholds (from 0.01 to 0.99) to locate the threshold that maximizes correlation, providing an optimal operating point for unbalanced production models.