Matthews correlation coefficient
For binary classification, the Matthews correlation coefficient is the Pearson correlation between predicted class labels and observed outcomes, calculated from all four confusion-matrix counts.
MCC = (TP*TN - FP*FN) / sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN)), where TP, FP, FN and TN count true positives, false positives, false negatives and true negatives in the same evaluation population. When defined, it ranges from -1 for complete disagreement to +1 for complete agreement; zero means zero binary correlation, not proof of a particular guessing mechanism. [1]
If either labels or predictions are constant, the denominator is zero and the correlation is undefined. scikit-learn 1.7.2 returns 0.0 in this case; Hesela's accompanying calculation returns null to keep that distinction visible. [2]
Relations
- related
- F1 score, Precision, Recall, False positive rate, Class prevalence, Probability calibration, Grouped cross-validation, Temporal validation, Average precision, Spearman rank correlation
Limitations
- MCC is not a failure probability or the fraction of correct alerts; report the positive event, horizon, threshold, counts and population alongside it. [1]
Citations
- scikit-learn: Matthews correlation coefficient and binary confusion-matrix formula.
- scikit-learn 1.7.2: matthews_corrcoef, zero-denominator convention.