Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-016

Confusion Matrix Counts

Problem

Compute the four counts of a binary confusion matrix for positive label 1.

Return [TP, FP, FN, TN], where TP has true=1 and pred=1, FP has true=0 and pred=1, FN has true=1 and pred=0, and TN has true=0 and pred=0.

Hint

Walk through the pairs once and bucket each into one of the four quadrants.

Test cases

case 1
in: [[1,0,1,1,0],[1,0,1,0,0]]
expected: [2,0,1,2]
case 2
in: [[1,1,1],[1,1,1]]
expected: [3,0,0,0]
case 3
in: [[1,1,1],[0,0,0]]
expected: [0,0,3,0]
case 4
in: [[0,0,0,1],[1,0,1,1]]
expected: [1,2,0,1]
Starter codePython
def confusion_matrix_counts(y_true, y_pred):
    # Returns [TP, FP, FN, TN]
    # Your code here
    pass

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