All problems
Per-Class Accuracy
Problem
Compute accuracy for each class in a label map.
For class c divide the number of pixels whose prediction equals the target by the number of target pixels of class c. Classes with no target pixels score 0.0; round each value to 4 decimal places.
Test cases
case 1
in: [[[0,1],[2,1]],[[0,1],[2,0]],3]
expected: [0.5,1,1]
case 2
in: [[[0,0]],[[1,1]],2]
expected: [0,0]
case 3
in: [[[1]],[[1]],2]
expected: [0,1]
Starter codePython
def per_class_accuracy(pred, target, num_classes):
# Your code here
pass3 test cases · run your code against them in the editor