Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-067

Balanced Accuracy

Problem

Compute balanced accuracy: the unweighted mean of recall over the classes present in y_true.

For each class, recall = TP / (TP + FN) counting that class as positive against all others. Empty input returns 0.0.

Hint

It is macro recall: average the per-class recalls equally, regardless of support.

Test cases

case 1
in: [[1,1,0,0],[1,0,0,0]]
expected: 0.75
case 2
in: [[1,0,1,0],[1,0,1,0]]
expected: 1
case 3
in: [[0,1,2,2],[0,1,1,2]]
expected: 0.8333333333333334
case 4
in: [[],[]]
expected: 0
Starter codePython
def balanced_accuracy(y_true, y_pred):
    # Your code here
    pass

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