Premium problem126. Top-k Accuracy

Easy Locked

scores is (n, c) of class scores and labels is (n,) of true class indices. Return the fraction of rows whose true label is among the k highest-scoring classes of that row.

Input

scores =
[[0.1 0.9 0.3]
 [0.5 0.2 0.4]]
labels = [2 0]
k = 2

Output

1.0

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)