Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-091

Micro Precision

Problem

Compute micro-averaged precision over the labels present in y_true or y_pred. Micro precision pools all decisions: the total number of true positives divided by the total number of positive predictions.

Return 0.0 if nothing is predicted positive or the input is empty.

Hint

Pool every class's TP and FP counts instead of averaging per-class precisions.

Test cases

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

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