$$MCC = \frac{TP \cdot TN - FP \cdot FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}$$
Details
The coefficient stays informative under class imbalance, where accuracy does not: it uses all four cells of the confusion matrix rather than only the diagonal. It ranges over [-1, 1], with 0 meaning no better than chance and negative values meaning the predictions run opposite to the truth.
If any of the four marginal sums is zero the denominator vanishes.
The coefficient is then undefined, and the convention followed here
is to report 0 and warn, rather than return NaN.
Mirrors morie.fn.mcc on the Python side. See
morie_matthews_corrcoef for the label-vector form.
