Top-k Accuracy

easy
Unit 8 · Attention0/3 to milestone

ImageNet results are reported as top-1 and top-5 accuracy: a prediction counts if the true class is among the k highest-scoring classes.

Implement topk_accuracy(logits, targets, ks=(1, 5)) returning a dict {k: accuracy}. Break ties in scores by lower class index (so results are deterministic).

#metrics#classification2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Top-k Accuracy · TechGradify