Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-408

Mean Reciprocal Rank from Ranks

Problem

For each query, the reciprocal rank is 1 / rank of the first relevant result, or 0 when nothing relevant was found. The mean reciprocal rank averages these values.

Given the per-query ranks (0 meaning none), return the mean reciprocal rank.

Hint

Only the first hit per query contributes.

Test cases

case 1
in: [[1,2,0]]
expected: 0.5
case 2
in: [[2,4]]
expected: 0.375
case 3
in: [[1,1,1]]
expected: 1
Starter codePython
def mean_reciprocal_rank_from_ranks(ranks):
    # Your code here
    pass

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