Skip to content
DeepForgeby svx
All problems
HardStatisticsst-407

Matthews Correlation from Counts

Problem

The Matthews correlation coefficient is (TP TN - FP FN) / sqrt((TP + FP)(TP + FN)(TN + FP)(TN + FN)). Return 0.0 when any factor is zero.

Given the four counts, return the coefficient.

Hint

It stays high only when both classes are predicted well.

Test cases

case 1
in: [8,9,1,2]
expected: 0.7035264706814485
case 2
in: [5,5,5,5]
expected: 0
case 3
in: [1,1,1,1]
expected: 0
Starter codePython
def matthews_correlation_coefficient(tp, tn, fp, fn):
    # Your code here
    pass

3 test cases · run your code against them in the editor