Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-138

Top-1 Error Rate

Problem

Compute the top-1 error rate of a list of predicted class indices.

Return 1 - (correct / total) rounded to 4 decimal places, comparing preds and labels position by position. An empty list returns 0.0.

Test cases

case 1
in: [[0,1,2,3],[0,1,1,3]]
expected: 0.25
case 2
in: [[0,1],[0,1]]
expected: 0
case 3
in: [[1],[0]]
expected: 1
case 4
in: [[],[]]
expected: 0
Starter codePython
def top1_error(preds, labels):
    # Your code here
    pass

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