Class: EvalRuby::Metrics::RecallAtK
- Defined in:
- lib/eval_ruby/metrics/recall_at_k.rb
Overview
Computes Recall@K: the fraction of relevant documents found in the top-k results.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#call(retrieved:, relevant:, k: nil, **_kwargs) ⇒ Float
Recall score (0.0-1.0).
Methods inherited from Base
Constructor Details
This class inherits a constructor from EvalRuby::Metrics::Base
Instance Method Details
#call(retrieved:, relevant:, k: nil, **_kwargs) ⇒ Float
Returns recall score (0.0-1.0).
15 16 17 18 19 20 21 22 |
# File 'lib/eval_ruby/metrics/recall_at_k.rb', line 15 def call(retrieved:, relevant:, k: nil, **_kwargs) return 0.0 if relevant.empty? k ||= retrieved.length top_k = retrieved.first(k) hits = top_k.count { |doc| relevant.include?(doc) } hits.to_f / relevant.size end |