#323Matthews Correlation Coefficient (MCC)EasyEvaluation MetricsAsked atMeta · Google · Amazon
Matthews Correlation Coefficient (MCC)
Background
MCC is a single balanced scalar for binary classification quality. Unlike accuracy or F1, it works for any class ratio and gives a clean interpretation (1 perfect, 0 random, -1 anti-correlated). Production-grade for imbalanced fraud / medical screening.
Problem statement
Implement mcc(y_true, y_pred):
Input
y_true,y_pred- sequences of , same length.
Output
floatin . Returns if any factor in the denominator is (a degenerate case).
Examples
Input: y_true=[1,1,0,0], y_pred=[1,1,0,0]
Output: 1.0
Constraints
- Same length, ValueError otherwise.
- Both inputs binary in .
Notes
- vs F1. F1 weights precision and recall, but ignores TN. MCC uses all four cells of the confusion matrix and is therefore symmetric under label flip.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference perfect classifier example
- •Worked example on a balanced mix
- •Sample eight-item confusion