Class: EvalRuby::Metrics::MRR

Inherits:
Base
  • Object
show all
Defined in:
lib/eval_ruby/metrics/mrr.rb

Overview

Computes Mean Reciprocal Rank: 1/(position of first relevant document).

Examples:

MRR.new.call(retrieved: ["a", "b", "c"], relevant: ["b"])
# => 0.5

Instance Attribute Summary

Attributes inherited from Base

#judge

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from EvalRuby::Metrics::Base

Instance Method Details

#call(retrieved:, relevant:, **_kwargs) ⇒ Float

Returns reciprocal rank (0.0-1.0).

Parameters:

  • retrieved (Array<String>)

    retrieved document IDs in ranked order

  • relevant (Array<String>)

    ground-truth relevant document IDs

Returns:

  • (Float)

    reciprocal rank (0.0-1.0)



14
15
16
17
18
19
# File 'lib/eval_ruby/metrics/mrr.rb', line 14

def call(retrieved:, relevant:, **_kwargs)
  retrieved.each_with_index do |doc, i|
    return 1.0 / (i + 1) if relevant.include?(doc)
  end
  0.0
end