CSC413 Information Retrieval

Information RetrievalUnit 49 min read

Ranking & Evaluation Metrics: Precision, Recall, F1, MAP, NDCG

Unit 4 of Information Retrieval explores how search engines rank results and evaluate their effectiveness using metrics like precision, recall, F1-score, Mean Average Precision (MAP), and Normalized Discounted Cumulative Gain (NDCG), with real-world applications in eSewa, Daraz, and NEPSE.

TAKEAWAYS:

  • Precision and recall are fundamental metrics that trade off between relevance and coverage in ranked retrieval.
  • The precision-recall curve and F1-score balance these metrics for optimal retrieval performance.
  • MAP (Mean Average Precision) evaluates ranked lists by averaging precision at each relevant document.
  • NDCG (Normalized Discounted Cumulative Gain) accounts for graded relevance in modern search engines.
  • Real-world systems like eSewa’s transaction ranking and Daraz’s product recommendations use these metrics to optimize user experience.
  • NEPSE’s stock ranking relies on relevance metrics to prioritize financial news and alerts.


Core Concepts: Precision and Recall

Information retrieval systems return documents in a ranked order. Precision and recall are the two most fundamental metrics used to evaluate how well a system retrieves relevant documents.

Definitions

  • Precision (P): The ratio of relevant documents retrieved to the total documents retrieved. High precision means fewer irrelevant results.

  • Recall (R): The ratio of relevant documents retrieved to the total relevant documents available in the collection. High recall means most relevant documents are found, but may include irrelevant ones.

Trade-off Between Precision and Recall

There is an inverse relationship between precision and recall:

  • High precision, low recall: Fewer documents retrieved, but most are relevant (e.g., strict filtering).
  • Low precision, high recall: Many documents retrieved, but some are irrelevant (e.g., broad search).
High Precision, Low Recall (Strict Filtering) (30%)Balanced (Optimal Trade-off) (40%)Low Precision, High Recall (Broad Search) (30%)
Precision-Recall Trade-off Distribution (Hypothetical Search Results)

Suppose a user searches for "wireless earbuds" on Daraz. The system retrieves 50 products, but only 30 are truly relevant (wireless earbuds). The remaining 20 are related but irrelevant (e.g., wired earphones, headphones).

  • Precision (P) = (60%)
  • Recall (R) depends on how many wireless earbuds exist in Daraz’s entire catalog. If there are 100 wireless earbuds in total: R = \frac{30}{100} = 0.3 \text{ (30%)}

Visualization of Precision and Recall:



F1-Score: Balancing Precision and Recall

Since precision and recall often conflict, the F1-score combines them into a single metric:

  • F1 = 1: Perfect balance (high precision and recall).
  • F1 = 0: No relevant documents retrieved.
00.190.380.560.75Precision0.75Recall0.6F1-Score0.67
Example F1 Calculation (Precision=0.75, Recall=0.6) → F1=2*(0.75*0.6)/(0.75+0.6)

Example: eSewa Transaction Ranking

eSewa ranks transactions based on relevance. Suppose:

  • Precision (P) = 0.7 (70% of retrieved transactions are relevant).
  • Recall (R) = 0.6 (60% of all relevant transactions are retrieved).

Then: F1 = 2 \times \frac{0.7 \times 0.6}{0.7 + 0.6} = 0.636 \text{ (63.6%)}


Mean Average Precision (MAP)

MAP evaluates ranked retrieval by computing the average precision (AP) for each query and then taking the mean over all queries.

Query 1Relevant Docs: 3/5retrievedQuery 2Relevant Docs: 2/4retrievedAverage Precision(0.6 + 0.5)/2 =0.55
MAP Calculation Across Multiple Queries

How MAP Works

  1. For each query, compute precision at each relevant document (P@k).
  2. Calculate the average precision (AP) for the query: where:
    • = total relevant documents.
    • = 1 if the -th document is relevant, else 0.
  3. MAP is the mean of AP across all queries.

Example: NEPSE Stock News Ranking

Suppose NEPSE ranks stock-related news articles. For a query like "NEPSE share price update", the system retrieves:

  1. "NEPSE closes at 1800 points" (Relevant)
  2. "Banking sector analysis" (Irrelevant)
  3. "NEPSE dividend announcement" (Relevant)
  4. "Global market trends" (Irrelevant)
  • Precision at 1 (P@1) =
  • Precision at 2 (P@2) =
  • Precision at 3 (P@3) =

If there are 2 relevant documents, the AP is:

If this is the only query, MAP = 0.835.


Normalized Discounted Cumulative Gain (NDCG)

NDCG accounts for graded relevance (e.g., some documents are more relevant than others). It discounts irrelevant documents and rewards highly relevant ones early in the ranking.

How NDCG Works

  1. Assign relevance scores (e.g., 3 = highly relevant, 2 = relevant, 1 = somewhat relevant, 0 = irrelevant).
  2. Compute Discounted Cumulative Gain (DCG):
  3. Compute Ideal DCG (IDCG) (the best possible DCG for the query).
  4. NDCG =

Example: Pathao Ride Ranking

Suppose Pathao ranks ride options based on user preferences (e.g., price, distance, driver rating). For a query like "cheap ride to Thapathali", the system returns:

  1. Driver A: (cheap, good rating)
  2. Driver B: (moderate price, average rating)
  3. Driver C: (expensive, poor rating)
  • DCG at position 3:
  • IDCG (if the best order were [3, 2, 1]):
  • NDCG = (perfect ranking).

Comparison of Evaluation Metrics

Metric Focus Use Case Strengths Weaknesses
Precision Relevance in retrieved results High-stakes searches (e.g., medical) Simple, intuitive Ignores recall, favors few results
Recall Coverage of relevant documents Broad searches (e.g., research) Captures all relevant docs May include many irrelevant docs
F1-Score Balance of precision and recall General-purpose ranking Single metric for trade-off Assumes equal importance to P and R
MAP Ranked retrieval quality Web search, recommendation systems Considers ranking order Assumes binary relevance
NDCG Graded relevance in rankings Personalized search (e.g., YouTube) Accounts for relevance degrees Complex to compute

## In the Real World

  1. eSewa Transaction Ranking

    • Idea Used: Precision and Recall
    • How? eSewa ranks transactions to show the most relevant ones first (high precision). However, if a user searches for a specific transaction, eSewa must ensure it retrieves all possible matches (high recall). The system uses F1-score to balance these metrics when optimizing search results.
  2. Daraz Product Recommendations

    • Idea Used: Mean Average Precision (MAP)
    • How? Daraz’s recommendation engine ranks products based on user history and preferences. MAP helps evaluate how well the system ranks relevant products early in the list, improving user satisfaction.
  3. NEPSE Stock Alerts

    • Idea Used: NDCG
    • How? NEPSE’s alert system assigns graded relevance to news (e.g., a dividend announcement is more relevant than a general market update). NDCG ensures highly relevant alerts appear first, improving investor decision-making.

## Exam Tip

  1. Understand the Definitions:

    • Memorize the formulas for precision, recall, F1-score, MAP, and NDCG.
    • Know when to use each metric (e.g., MAP for ranked retrieval, NDCG for graded relevance).
  2. Practice with Examples:

    • Given a set of documents and queries, compute precision, recall, and F1-score.
    • For MAP and NDCG, practice calculating step-by-step (e.g., precision at each rank, DCG computation).
  3. Real-World Applications:

    • Relate metrics to e-commerce (Daraz), fintech (eSewa), and stock markets (NEPSE).
    • Explain how trade-offs between precision and recall affect user experience.
  4. Common Pitfalls:

    • Binary vs. Graded Relevance: NDCG is for graded relevance; MAP assumes binary.
    • Order Matters: In ranked retrieval, the position of relevant documents affects MAP and NDCG.

Final Note: Always visualize rankings (e.g., precision-recall curves, DCG calculations) in exams to clarify your reasoning. Good luck!

Based on the TU BSc CSIT syllabus for Information Retrieval (CSC413), unit 4.

Discussion

Loading…