All problems
Recall at k
Problem
Return recall at k: the fraction of relevant ids that appear among the first k retrieved.
Return 0.0 when k <= 0 or there are no relevant ids.
Hint
The denominator is the number of relevant ids, not the retrieval depth.
Test cases
case 1
in: [["a","b","c"],["a","c","d"],2]
expected: 0.3333333333333333
case 2
in: [["a","b"],["a"],1]
expected: 1
case 3
in: [[],["a"],2]
expected: 0
case 4
in: [["a"],["a"],0]
expected: 0
case 5
in: [["a","b"],[],1]
expected: 0
Starter codePython
def recall_at_k(retrieved, relevant, k):
# Your code here
pass5 test cases · run your code against them in the editor