Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-092

Specificity

Problem

Compute specificity (true negative rate) for binary labels with positive class 1: TN / (TN + FP).

Return 0.0 when the denominator is zero or the input is empty.

Hint

Specificity is recall for the negative class.

Test cases

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

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