When a model or test sorts cases into “positive” and “negative”, its results fill a 2×2 confusion matrix. Accuracy alone can be badly misleading: if only 5% of e-mails are spam, a filter that never flags anything is 95% accurate and completely useless. The Matthews correlation coefficient (MCC) avoids this trap because it uses all four cells and only gets high when the classifier does well on both classes.
MCC is simply Pearson’s correlation between the true labels and the predicted labels coded as 0 and 1, and statisticians call it the phi coefficient. It runs from −1 (every prediction wrong) through 0 (no better than guessing) to +1 (perfect). Because it is symmetric, swapping which class you call positive does not change it, which is not true of precision, recall or the F1 score.
The calculator also lists the familiar rates that come from the same table, so you can explain where a classifier fails: sensitivity (recall) for missed positives, specificity for false alarms, and precision and negative predictive value for how trustworthy each kind of prediction is.
How to use the Matthews Correlation Coefficient Calculator
- True positives (TP)
- False positives (FP)
- True negatives (TN)
- False negatives (FN)
Results update as you type, and everything is calculated in your browser.
How it works
Type the four counts from your confusion matrix. The numerator TP·TN − FP·FN compares correct with wrong decisions; the denominator scales it by the row and column totals so the result lies between −1 and +1. If any row or column total is zero, MCC is undefined.
Worked example
A spam filter is tested on 100 e-mails: it flags 45 real spam messages (TP) and 5 good messages (FP), passes 40 good messages (TN) and misses 10 spam messages (FN). MCC = (45 × 40 − 5 × 10) ÷ √(50 × 55 × 45 × 50) = 1,750 ÷ 2,487.5 = 0.7035. Sensitivity is 45 ÷ 55 = 81.8%, specificity 40 ÷ 45 = 88.9%, precision 90%, accuracy 85% and F1 = 90 ÷ 105 = 0.857. χ² = 100 × 0.7035² = 49.5, so the agreement between prediction and truth is far from chance.
Reading the confusion matrix
| Actually positive | Actually negative | |
|---|---|---|
| Predicted positive | TP: correct alarm | FP: false alarm (type I error) |
| Predicted negative | FN: missed case (type II error) | TN: correct rejection |
Inputs explained
| Field | What to enter |
|---|---|
| True positives (TP) | A number |
| False positives (FP) | A number |
| True negatives (TN) | A number |
| False negatives (FN) | A number |
What each result means
- Matthews correlation coefficient (MCC) = ([True positives (TP)]×[True negatives (TN)] – [False positives (FP)]×[False negatives (FN)])÷sqrt(([True positives (TP)] + [False positives (FP)])×([True positives (TP)] + [False negatives (FN)])×([True negatives (TN)] + [False positives (FP)])×([True negatives (TN)] + [False negatives (FN)]))
- Total cases = [True positives (TP)] + [False positives (FP)] + [True negatives (TN)] + [False negatives (FN)]
- Sensitivity / recall (TP rate) = ([True positives (TP)]÷([True positives (TP)] + [False negatives (FN)]))×100
- Specificity (TN rate) = ([True negatives (TN)]÷([True negatives (TN)] + [False positives (FP)]))×100
- Precision (positive predictive value) = ([True positives (TP)]÷([True positives (TP)] + [False positives (FP)]))×100
- Negative predictive value = ([True negatives (TN)]÷([True negatives (TN)] + [False negatives (FN)]))×100
- Accuracy = (([True positives (TP)] + [True negatives (TN)])÷[Total cases])×100
- Balanced accuracy = (([Sensitivity ÷ recall (TP rate)] + [Specificity (TN rate)])÷200)×100
- F1 score = 2×[True positives (TP)]÷(2×[True positives (TP)] + [False positives (FP)] + [False negatives (FN)])
- Informedness (sensitivity + specificity − 1) = [Sensitivity ÷ recall (TP rate)]÷100 + [Specificity (TN rate)]÷100 – 1
- Markedness (precision + NPV − 1) = [Precision (positive predictive value)]÷100 + [Negative predictive value]÷100 – 1
- χ² statistic (n·MCC²) = [Total cases]×[Matthews correlation coefficient (MCC)]^2
- p-value of the χ² test = 1 – chicdf([χ² statistic (n·MCC²)], 1)
Formula
MCC = (TP·TN − FP·FN) ÷ √((TP + FP)(TP + FN)(TN + FP)(TN + FN)) · MCC² = χ² ÷ n · MCC = ±√(informedness × markedness)
Worked example
Inputs: True positives (TP): 45; False positives (FP): 5; True negatives (TN): 40; False negatives (FN): 10.
Results: Matthews correlation coefficient (MCC) = 0.7035; Interpretation = Strong agreement; Total cases = 100; Sensitivity / recall (TP rate) = 81.82 %; Specificity (TN rate) = 88.89 %; Precision (positive predictive value) = 90 %; Negative predictive value = 80 %; Accuracy = 85 %; Balanced accuracy = 85.35 %; F1 score = 0.8571; Informedness (sensitivity + specificity − 1) = 0.7071; Markedness (precision + NPV − 1) = 0.7; χ² statistic (n·MCC²) = 49.4949; p-value of the χ² test = 1.9889e-12.
Key terms
- Confusion matrix
- A 2×2 table of true and false positives and negatives.
- Sensitivity (recall)
- The share of actual positives the classifier catches: TP ÷ (TP + FN).
- Specificity
- The share of actual negatives correctly rejected: TN ÷ (TN + FP).
- Informedness
- Sensitivity + specificity − 1, also called Youden's J.
Frequently asked questions
What is a good MCC value?
Above 0.5 is generally decent and above 0.7 good, but compare models on the same data. MCC = 0 means no better than random guessing, and negative values mean predictions are systematically inverted.
Why use MCC instead of accuracy or F1?
MCC only rises when both classes are predicted well. With 95 negatives and 5 positives, predicting "negative" every time scores 95% accuracy but MCC = 0 (undefined, treated as 0).
Is MCC the same as the phi coefficient?
Yes. MCC is phi, Pearson's r computed on two 0/1 variables, applied to classification.
What happens if a row or column of the matrix is empty?
The denominator becomes 0 and MCC is undefined, for example if the model never predicts a positive. By convention it is often reported as 0.
How is MCC related to χ²?
χ² = n × MCC². With 100 cases and MCC = 0.70, χ² = 49, far beyond the 5% critical value of 3.84.
Can MCC be used for more than two classes?
Yes, there is a multiclass generalisation (also called Rk), but this calculator handles the common binary case.
Does it matter which class I call positive?
Not for MCC. Swapping the labels swaps TP with TN and FP with FN and leaves MCC unchanged. Precision, recall and F1 do change.