File size: 435 Bytes
6ced533
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
"""Reciprocal Rank Fusion for combining multiple ranked-id lists."""


def reciprocal_rank_fusion(rankings, k=60):
    """rankings: list of ranked-id lists (best first). Returns a single fused ranking."""
    scores = {}
    for ranking in rankings:
        for rank, doc_id in enumerate(ranking, start=1):
            scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)