Matthews Correlation Coefficient Calculator
Calculate the Matthews Correlation Coefficient from a confusion matrix or binary label arrays, with a full suite of classification metrics.
🧮 What is the Matthews Correlation Coefficient?
The Matthews Correlation Coefficient (MCC) is a measure of the quality of binary classification models. It was introduced by biochemist Brian Matthews in 1975 to evaluate predictions of protein secondary structure and has since been adopted as a gold-standard metric in machine learning, medical diagnostics, bioinformatics, and any domain where binary classification quality needs to be measured rigorously. The MCC ranges from -1 to +1: a value of +1 represents a perfect classifier, 0 represents a classifier no better than random guessing, and -1 represents a perfectly inverted classifier that always predicts the wrong class.
MCC is used across a wide range of real-world applications. In machine learning, it evaluates models for spam detection, fraud detection, disease diagnosis, and churn prediction. In medicine, it measures the quality of diagnostic tests against ground truth labels (positive/negative for a condition). In bioinformatics, it benchmarks gene expression classifiers and protein structure predictions. In software testing, it assesses defect prediction models. Unlike simpler metrics, MCC is especially valuable when class distributions are highly imbalanced, because it incorporates all four cells of the confusion matrix rather than focusing only on one class or one type of error.
A common misconception is that accuracy is sufficient to evaluate a binary classifier. On a dataset with 99% negative samples, a model that always predicts negative achieves 99% accuracy despite zero predictive ability. Its MCC, however, equals 0, correctly signalling no predictive correlation. Another misconception is that the F1 score is equivalent to MCC. F1 ignores True Negatives entirely, which makes it blind to the model's performance on the negative class. MCC penalises poor performance on either class symmetrically, making it strictly more informative than both accuracy and F1 for imbalanced problems.
This calculator accepts two input formats: a confusion matrix (TP, FP, FN, TN counts) for when you already have aggregated results, and raw binary label arrays for when you have lists of actual and predicted values. Both formats compute the same 10-metric output: MCC, accuracy, balanced accuracy, precision (PPV), recall (sensitivity), specificity (TNR), negative predictive value (NPV), F1 score, and Cohen's kappa.
📐 MCC Formula
The numerator TP x TN - FP x FN measures the difference between correct and incorrect predictions in a balanced way across both classes. The denominator normalises this difference by the geometric mean of the four marginal totals of the confusion matrix, ensuring the result lies in [-1, +1] regardless of class balance or total sample count. The formula is equivalent to the Pearson product-moment correlation coefficient applied to two binary variables (actual and predicted labels coded as 0 and 1).
📖 How to Use This Calculator
Using Confusion Matrix Mode and Raw Labels Mode
💡 Example Calculations
Example 1 -- Balanced Dataset, Good Classifier
TP=90, FP=10, FN=5, TN=95 (200 total samples, balanced classes)
Example 2 -- Imbalanced Dataset, Degenerate Classifier
TP=0, FP=0, FN=50, TN=950 (model always predicts negative; 95% class imbalance)
Example 3 -- Medical Diagnostic Test
Disease screening: TP=80, FP=20, FN=15, TN=385 (500 patients)
Example 4 -- Negative MCC (Inverted Classifier)
TP=5, FP=90, FN=95, TN=10 (classifier is systematically wrong)
❓ Frequently Asked Questions
🔗 Related Calculators
What is the Matthews Correlation Coefficient?
The Matthews Correlation Coefficient (MCC) is a measure of the quality of a binary classification model. It was introduced by biochemist Brian Matthews in 1975 for evaluating protein structure predictions. MCC ranges from -1 to +1, where +1 is a perfect classifier, 0 is no better than random guessing, and -1 is a perfectly inverse classifier. It is derived from all four cells of the confusion matrix (TP, TN, FP, FN) and is considered the most informative single metric for imbalanced classification problems.
How is MCC calculated from a confusion matrix?
MCC = (TP x TN - FP x FN) divided by the square root of (TP + FP)(TP + FN)(TN + FP)(TN + FN). If any denominator factor equals zero, MCC is defined as 0 by convention. TP = true positives, TN = true negatives, FP = false positives, FN = false negatives.
What is a good MCC value?
MCC values above 0.7 indicate strong predictive performance. Values in the 0.5 to 0.7 range indicate moderate performance. Values between 0.3 and 0.5 indicate weak but statistically meaningful association. Values below 0.3 or near 0 suggest the model has little predictive ability beyond chance. Negative MCC values indicate the model consistently predicts the wrong class, which is worse than random.
Why is MCC better than accuracy for imbalanced datasets?
Accuracy counts all correct predictions equally, so a model that always predicts the majority class scores high accuracy even with zero predictive ability. For example, with 95% negative samples, a model that always predicts negative achieves 95% accuracy but MCC of 0. MCC accounts for all four confusion matrix cells and produces a meaningful score near 0 for such degenerate classifiers, making it far more reliable when class distribution is skewed.
What is the difference between MCC and F1 score?
F1 score is the harmonic mean of Precision and Recall and ignores True Negatives entirely. This means F1 can be high even when the model performs poorly on the negative class. MCC includes TN in its formula, so it penalises poor performance on either class. For balanced datasets, F1 and MCC tend to agree. For imbalanced datasets, MCC is the more conservative and arguably more honest metric.
Is the Matthews Correlation Coefficient the same as the Phi Coefficient?
Yes. The MCC and the Phi Coefficient are mathematically identical. Both use the same formula applied to a 2x2 contingency table. The Phi Coefficient is the standard term in statistics for measuring association between two binary categorical variables. MCC is the term used in machine learning and bioinformatics. They produce exactly the same numerical result from the same TP, TN, FP, FN counts.
What does it mean when MCC is 0?
An MCC of exactly 0 means the model's predictions are uncorrelated with the true labels. The model performs no better than random class assignment. This can happen either because the model genuinely has no predictive power, or because the denominator of the MCC formula equals zero (which occurs when the model always predicts one class, producing either zero TP, zero TN, or both). By convention, MCC is defined as 0 in the degenerate denominator case.
Can MCC be negative?
Yes. MCC ranges from -1 to +1. A negative MCC means the model is systematically predicting the wrong class more often than it should by chance. An MCC of -1 is a perfect negative classifier: every positive is predicted negative and every negative is predicted positive. In practice, a strongly negative MCC usually indicates that the class labels were accidentally inverted or the model was trained incorrectly.