All problems
Matthews Correlation Coefficient
Problem
Compute the Matthews correlation coefficient for binary labels with positive class 1: (TP*TN - FP*FN) / sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN)).
Return 0.0 when the denominator is zero. Empty input returns 0.0.
Hint
The numerator compares correct and incorrect counts; +1 means perfect agreement and -1 total disagreement.
Test cases
case 1
in: [[1,1,0,0],[1,1,0,0]]
expected: 1
case 2
in: [[1,1,0,0],[0,0,1,1]]
expected: -1
case 3
in: [[1,1,1],[1,1,1]]
expected: 0
case 4
in: [[1,0,1,0,1],[1,1,0,1,0]]
expected: -0.6666666666666666
Starter codePython
import math
def matthews_corrcoef(y_true, y_pred):
# Your code here
pass4 test cases · run your code against them in the editor