Calculate the Matthews Correlation Coefficient for binary classification quality.
The Matthews Correlation Coefficient (MCC) is a single-number summary of binary classification quality that uses all four confusion matrix values: MCC = (TP×TN − FP×FN) / √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]. It ranges from -1 (total disagreement) through 0 (no better than random) to +1 (perfect prediction). Unlike accuracy or F1, MCC accounts for true negatives directly and remains informative even on severely imbalanced datasets, which is why it's often recommended as the preferred single-metric summary for binary classifiers.
MCC = (TP * TN - FP * FN) / sqrt((TP + FP)(TP + FN)(TN + FP)(TN + FN))
MCC incorporates all four confusion matrix cells (TP, TN, FP, FN) in a balanced way, so a model that only performs well on the majority class will not score highly, unlike accuracy which can be dominated by the majority class.
An MCC of 0 indicates the classifier's predictions are no better than random guessing given the class distribution — it carries no useful correlation between predictions and actual labels.
Yes — if the denominator is zero (which happens when the model predicts only one class, or the confusion matrix has an entire row or column of zeros), MCC is undefined; this calculator returns 0 in that case as a safe fallback.