Binary Confusion Matrix

MediumMachine LearningArraySortingMatrix

Description

Given equal-length binary arrays yTrue and yPred (1 = positive), return the counts [TP, FP, FN, TN] in that exact order.

Examples

Input:yTrue = [1,0,1,1], yPred = [1,1,1,0]
Output:[2,1,1,0]
Explanation:

Counting true/false positives and negatives gives [TP, FP, FN, TN] = [2,1,1,0].

Input:yTrue = [1,1,1], yPred = [1,1,1]
Output:[3,0,0,0]
Explanation:

Counting true/false positives and negatives gives [TP, FP, FN, TN] = [3,0,0,0].

Input:yTrue = [0,0], yPred = [1,0]
Output:[0,1,0,1]
Explanation:

Counting true/false positives and negatives gives [TP, FP, FN, TN] = [0,1,0,1].

Constraints

  • 1 ≤ yTrue.length ≤ 10⁴
  • values are 0 or 1

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.