Free Matthews Correlation Coefficient Calculator

Enter TP, FP, TN, and FN to calculate MCC

Understanding the Matthews Correlation Coefficient

Evaluating the performance of a binary classification model demands a metric that captures both types of correct predictions and both types of errors. The Matthews correlation coefficient (MCC) does exactly that by combining true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN) into a single figure. This tool applies the MCC formula automatically, giving you an immediate, balanced view of classification quality—no matter whether you work in machine learning, medical diagnostics, or quality assurance.

What the MCC Quantifies

The correlation coefficient Matthews proposed ranges from −1-1 to +1+1, which is the same scale used by Pearson and other correlation measures. On this scale:

  • +1+1 represents a perfect agreement between prediction and ground truth.
  • 00 indicates that the classifier performs no better than a random guess.
  • −1-1 signifies complete disagreement—every positive is predicted negative and vice versa.

Because the MCC is symmetric and accounts for all four cells of the confusion matrix, it remains informative even when the classes are highly imbalanced—a situation where metrics like accuracy can be misleading.

The Confusion Matrix and the Matthews Correlation Formula

Before applying the Matthews correlation formula, you need to organize your results in a confusion matrix:

Actual \ PredictionPredicted PositivePredicted Negative
Actually PositiveTPFN
Actually NegativeFPTN

The formula that turns these four numbers into a single coefficient is:

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

If any of the sums in the denominator is zero, the coefficient becomes undefined because the denominator equals zero. This happens when, for example, the model never predicted a certain class.

Complementary Metrics for a Full Picture

Many researchers pair the MCC binary classification score with additional metrics, all derived from the same confusion matrix:

  • Sensitivity (Recall / True Positive Rate) – the fraction of actual positives that were correctly identified.
    Sensitivity=TPTP+FN\text{Sensitivity} = \dfrac{TP}{TP + FN}

  • Specificity (True Negative Rate) – the fraction of actual negatives that were correctly identified.
    Specificity=TNTN+FP\text{Specificity} = \dfrac{TN}{TN + FP}

  • Precision (Positive Predictive Value) – the proportion of predicted positives that are true positives.
    Precision=TPTP+FP\text{Precision} = \dfrac{TP}{TP + FP}

  • Accuracy – the overall proportion of correct predictions.
    Accuracy=TP+TNTP+TN+FP+FN\text{Accuracy} = \dfrac{TP + TN}{TP + TN + FP + FN}

  • F1 Score – the harmonic mean of precision and recall.
    F1=2×TP2×TP+FN+FPF1 = \dfrac{2 \times TP}{2 \times TP + FN + FP}

Choosing the “best” metric depends on your specific problem. For example, in a medical screening you want high sensitivity to avoid missing sick patients, while in spam detection high precision is crucial to avoid blocking legitimate emails. The MCC, however, is often regarded as the most informative single metric because it uses all four entries of the confusion matrix and works well with imbalanced datasets.

Worked Example: Ceramic Plate Inspection

Consider a quality‑control scenario where you check ceramic plates for defects. Out of 100 plates, your inspection labels 15 as defective, but the true inspection shows 25 defective plates. The confusion matrix becomes:

Predicted DefectivePredicted Not Defective
Actually Defective10 (TP)15 (FN)
Actually Not Defective5 (FP)70 (TN)

Enter these values into the MCC calculator:

MCC=(10×70)−(5×15)(10+5)(10+15)(70+5)(70+15)=6252,390,625≈0.4042\text{MCC} = \frac{(10 \times 70) - (5 \times 15)}{\sqrt{(10 + 5)(10 + 15)(70 + 5)(70 + 15)}} = \frac{625}{\sqrt{2,390,625}} \approx 0.4042

An MCC of roughly 0.40 indicates a moderate correlation. Looking at sensitivity:

Sensitivity=1010+15=0.40\text{Sensitivity} = \frac{10}{10 + 15} = 0.40

This reveals that only 40 % of the actual defects were caught—a performance that would likely require improvement in a real factory setting.

Using the Calculator

To obtain your own result, simply enter the four confusion‑matrix counts (TP, FP, TN, FN) into the MCC calculator. The tool immediately displays the MCC value, and by opening the advanced section you also get the complementary metrics (sensitivity, specificity, precision, accuracy, F1 score). This side‑by‑side comparison helps you determine which aspects of your binary classifier are strong and where adjustments might be needed.

Whether you are training a machine‑learning model, validating a diagnostic test, or running a quality‑control check, this binary classification metric calculator gives you a trustworthy, all‑in‑one performance summary.

FAQ

1. What is the Matthews correlation coefficient used for?

The MCC is used to evaluate binary classification models by combining true positives, false positives, true negatives, and false negatives into a single balanced coefficient between -1 and +1. It is especially useful in machine learning, medical diagnostics, and quality control.

2. How is MCC different from accuracy or F1 score?

Accuracy and F1 score can be misleading when classes are imbalanced because they ignore one or two cells of the confusion matrix. The MCC uses all four cells, making it a more reliable measure even when the dataset has unequal numbers of positive and negative samples.

3. What does an MCC of 0 signify?

An MCC of 0 indicates that the prediction has no correlation with the actual outcomes—it performs no better than random chance.

4. Can I also calculate sensitivity and specificity using this calculator?

Yes. The advanced section of the calculator provides sensitivity (TP/(TP+FN)), specificity (TN/(TN+FP)), precision, accuracy, and F1 score, all derived from the same confusion matrix you enter.

5. What does it mean if the MCC formula produces an undefined result?

The denominator of the MCC formula is sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN)). If any of those sums is zero, the denominator becomes zero and the coefficient is undefined. This typically occurs when a row or column of the confusion matrix contains only zeros.

How to Use

  1. Enter the number of True Positives (TP) - correctly predicted positive cases.
  2. Fill in the False Positives (FP), True Negatives (TN), and False Negatives (FN) values.
  3. View the Matthews Correlation Coefficient instantly, or enable advanced metrics for additional classification statistics.