0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RRFを図解で学ぼう! - Reciprocal Rank Fusionを、小学3年生でもわかるように説明するよ

0
Posted at

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

from collections import defaultdict


def reciprocal_rank_fusion(rankings, k=60):

    scores = defaultdict(float)


    for ranking in rankings:

        for rank, item in enumerate(ranking, start=1):

            scores[item] += 1 / (k + rank)


    return sorted(

        scores.items(),

        key=lambda x: x[1],

        reverse=True

    )


teacher = ["恐竜ずかん", "宇宙のひみつ", "海の生き物"]

friends = ["宇宙のひみつ", "昆虫大百科", "恐竜ずかん"]

ai = ["恐竜ずかん", "海の生き物", "宇宙のひみつ"]


rankings = [teacher, friends, ai]

result = reciprocal_rank_fusion(rankings, k=10)


for title, score in result:

    print(title, round(score, 3))

出力例

恐竜ずかん 0.259

宇宙のひみつ 0.251

海の生き物 0.160

昆虫大百科 0.083

image.png

image.png

image.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?