Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

IR evaluation metrics

Clear, exam-focused notes on common information-retrieval evaluation metrics (precision, recall, F-measure, AP/MAP, DCG/NDCG, MRR, R-precision, bpref) with definitions, formulas, derivations and worked examples.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Search systems and ranking components are judged by how well they return relevant documents. An engineer uses IR evaluation metrics to compare ranking algorithms, tune parameters (for BM25, learning-to-rank, or relevance feedback), and report progress using standard test collections (TREC-style). Good choice and correct calculation of metrics decide which system design is kept.

Key ideas

  • Precision: the fraction of retrieved documents that are relevant. Precision answers: "Of the documents I showed, how many are relevant?" Precise, high when system returns few false positives.

  • Recall: the fraction of relevant documents that are retrieved. Recall answers: "Of all truly relevant documents in the collection, how many did I find?" High recall means few false negatives.

  • Precision@k (P@k): precision computed on the top-k retrieved documents. Important for web search where users inspect only top results.

  • Recall@k: fraction of relevant documents found in the top-k results (useful when gold-set size known).

  • F-measure (F1): the harmonic mean of precision and recall. It balances precision and recall; F1 = 2·(P·R)/(P+R). Explainable as harmonic mean: it punishes systems that have very low value in either P or R. More generally, Fβ = (1+β^2)·P·R / (β^2·P + R) to emphasize recall (β>1) or precision (β<1).

  • Average Precision (AP): for a single query with binary relevance, AP is the average of precision values at ranks where a relevant document occurs, normalized by number of relevant documents in the collection. AP rewards retrieving relevant documents early in the list.

  • Mean Average Precision (MAP): the mean of AP values over a set of queries. MAP summarizes system performance across queries.

  • Reciprocal Rank (RR) and Mean Reciprocal Rank (MRR): RR for a query is 1/(rank of first relevant document). MRR is mean of RR over queries. Useful when only the first relevant result matters.

  • Discounted Cumulative Gain (DCG) and Normalized DCG (NDCG): metrics for graded relevance. DCG discounts gain by position (documents lower in the ranking contribute less). Use the standard DCG variant with 2^{rel}-1 gain:

    • DCG_k = sum_{i=1..k} (2^{rel_i} - 1) / log2(i+1).
    • NDCG_k = DCG_k / IDCG_k where IDCG_k is the DCG_k of the ideal ranking (docs sorted by relevance). NDCG ranges 0..1 and handles graded relevance. When IDCG_k = 0 (no relevant documents), define NDCG_k = 0 or exclude that query—state policy.
  • R-precision: precision at R where R is the total number of relevant documents for that query (useful when R is known). R-precision = Precision@R.

  • bpref: a metric designed for incomplete judgments. It computes preference-based scores comparing judged relevant vs judged non-relevant docs and is robust when not all documents are judged.

  • Precision-Recall curve and interpolated precision: plot precision vs recall by varying cutoff; interpolated precision at recall r is the maximum precision obtained for any recall >= r. This is used to present summarized PR curves. Classic IR reports 11-point interpolated precision at recall levels {0.0, 0.1, ..., 1.0} (or 101-point at {0.00, 0.01, ..., 1.00}).

Assumptions behind formulas: relevance judgments are correct, the gold-set size R is known for AP and R-precision, and ranking is deterministic. For graded metrics assume integer relevance levels where higher = more relevant.

Diagrams to draw for exam answers:

  • Precision-Recall curve: x-axis recall [0..1], y-axis precision [0..1]; plot points of (recall_k, precision_k) for each cutoff k and draw interpolated precision as a step curve (max over higher recalls).
  • DCG example: two ranked lists side-by-side, show rel scores and compute discounted contributions per position, label denominators log2(i+1).

Formulas

Precision = |Retrieved ∩ Relevant| / |Retrieved| — Precision is unitless (fraction). Applies to any retrieval list; if ranked, can compute at cutoffs.

Recall = |Retrieved ∩ Relevant| / |Relevant| — Recall is unitless (fraction). Requires number of relevant docs in collection.

P@k = (number of relevant documents among top k) / k — Unitless. Use when users examine top k results.

Recall@k = (number of relevant documents among top k) / |Relevant| — Unitless. Requires |Relevant|.

F1 = 2 · Precision · Recall / (Precision + Recall) — Unitless. Harmonic mean; applies for balance between P and R.

AP = (1 / |Relevant|) · sum_{k=1..n} P(k) · rel_k — Unitless. Here P(k) is precision at cutoff k, rel_k is 1 if document at rank k is relevant else 0, and |Relevant| is number of relevant docs for that query in the collection. n is number of retrieved docs considered (often full list).

MAP = (1 / Q) · sum_{q=1..Q} AP(q) — Unitless. Average AP over Q queries.

RR = 1 / rank_first_relevant — Unitless.

MRR = (1 / Q) · sum_{q=1..Q} RR(q) — Unitless.

DCG_k = sum_{i=1..k} (2^{rel_i} - 1) / log2(i + 1) — Unitless; rel_i is graded relevance at rank i; log2 is binary logarithm.

IDCG_k = DCG_k computed on ideal order (relevance sorted descending).

NDCG_k = DCG_k / IDCG_k — Unitless between 0 and 1 when IDCG_k > 0 (define 0 or drop the query when IDCG_k = 0).

R-precision = Precision@R where R = |Relevant| for that query. — Unitless.

bpref = (1 / R) · sum_{r in relevant} (1 - min(number of judged nonrelevant ranked above r, R) / R) where R is the number of judged relevant docs (only judged nonrelevant are counted; equivalently divide by min(R, N) where N is the number of judged nonrelevant). — Unitless; applies with incomplete judgments.

Worked examples

Example 1 — single query, binary relevance. Retrieved list (rank 1..10) with relevance vector: [1,0,1,1,0,0,1,0,0,1]. Total relevant in collection |Relevant| = 8. Steps:

  1. Count retrieved relevant = 5 (positions 1,3,4,7,10). Precision = 5/10 = 0.5. Final: Precision = 0.5.
  2. Recall = retrieved relevant / |Relevant| = 5/8 = 0.625. Final: Recall = 0.625.
  3. F1 = 2·P·R/(P+R) = 2·0.5·0.625/(0.5+0.625) = 0.555555... → F1 ≈ 0.556.
  4. Precision@5: top 5 relevance [1,0,1,1,0] => 3 relevant among 5 => P@5 = 3/5 = 0.6. Final: P@5 = 0.6.
  5. Average Precision (AP): compute precision at ranks of relevant docs and divide by |Relevant| = 8.
    • P@1 = 1/1 = 1.000
    • P@3 = 2/3 ≈ 0.6666667
    • P@4 = 3/4 = 0.75
    • P@7 = 4/7 ≈ 0.5714286
    • P@10 = 5/10 = 0.5 Sum = 1 + 0.6666667 + 0.75 + 0.5714286 + 0.5 = 3.4880953 AP = 3.4880953 / 8 = 0.4360119 → AP ≈ 0.4360.

Example 2 — two queries: compute MAP.

  • Query A: same as Example 1 => AP_A = 0.4360119.
  • Query B: retrieved 5 docs with relevance vector [0,1,1,0,1]; assume total |Relevant| for Query B = 4 (one relevant is not retrieved).
    • Relevant ranks: 2,3,5 => P@2 = 1/2 = 0.5; P@3 = 2/3 ≈ 0.6666667; P@5 = 3/5 = 0.6; Sum = 1.7666667; AP_B = 1.7666667 / 4 = 0.4416667.
  • MAP = (AP_A + AP_B) / 2 = (0.4360119 + 0.4416667) / 2 = 0.4388393 → MAP ≈ 0.4388.

Example 3 — NDCG with graded relevance. Retrieved top-5 graded relevance: [3, 2, 3, 0, 1]. Use DCG formula with gain = 2^{rel}-1. Steps: Gains: 3→7, 2→3, 3→7, 0→0, 1→1. DCG_5 = 7/ log2(1+1) + 3/ log2(2+1) + 7/ log2(3+1) + 0/ log2(4+1) + 1/ log2(5+1) = 7/1 + 3/1.5849625 + 7/2 + 0 + 1/2.5849625 = 7 + 1.892789 + 3.5 + 0 + 0.3868528 = 12.779642 approx. Ideal order (desc): [3,3,2,1,0] => gains [7,7,3,1,0] IDCG_5 = 7/1 + 7/1.5849625 + 3/2 + 1/2.3219281 = 7 + 4.417578 + 1.5 + 0.430677 = 13.348255 approx. NDCG_5 = DCG_5 / IDCG_5 = 12.779642 / 13.348255 = 0.9571 → NDCG@5 ≈ 0.957.

All numeric steps above use common logarithms base 2 values: log2(3)=1.5849625, log2(5)=2.3219281, log2(6)=2.5849625. Verify arithmetic when copying into the answer.

Common mistakes

  • Forgetting that DCG uses log2(i+1) (denominator starts at i+1), and different DCG variants exist — state which you use.
  • Computing MAP over queries with missing AP values (e.g., a query with zero relevant docs); handle such queries explicitly (many evaluations drop queries without any relevant docs or define AP=0 for them—state policy). Also state conventions for undefined cases: Precision when no docs are retrieved (often set to 0), F1 when P=R=0 (set to 0), RR when no relevant result exists (set to 0), and NDCG when IDCG=0 (set to 0 or drop the query).
  • Mixing up graded relevance arithmetic and binary formulas (e.g., using AP for graded relevance without binarization).
  • Rounding intermediate values too early when calculating NDCG or AP — keep sufficient precision until final answer.
  • Using top-k cutoffs inconsistently across queries when reporting MAP.

For your exam

Kinds of questions:

  • Definitions: define precision, recall, AP, MAP, NDCG, MRR, R-precision, bpref.
  • Short notes: compare MAP vs NDCG and when to use graded relevance.
  • Derivations: show that F1 is harmonic mean of P and R, derive AP formula or show relationship between precision-recall curve and AP.
  • Numericals: compute P, R, F1, P@k, AP, MAP, DCG/NDCG from small given lists (show full steps and final numeric precision to 3 decimals).
  • Diagrams: draw and interpret a precision-recall curve or show ideal vs actual ranking for DCG.

What a full-marks answer includes:

  • Clear definitions with bolded term names and assumptions (binary vs graded relevance, known |Relevant|).
  • Correct formula(s) written and symbols explained.
  • For numeric problems: show counts, per-rank precisions, intermediate sums, and final answers with correct rounding policy and units (unitless).
  • For DCG/NDCG: state DCG variant, compute gains, show denominator logs, compute IDCG, and produce NDCG.

Quick check

  1. If you retrieve 4 documents and 3 of them are relevant, what is precision? 2) If there are 10 relevant documents in collection and you retrieved 3 of them, what is recall? 3) What does MAP average across queries? Answers: 1) 0.75; 2) 0.3; 3) Mean of Average Precision (AP) across the query set (average per-query AP).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?