Compute NDCG for a Ranked List of Product Search Results
Last updated: November 29, 2026
Quick Overview
Given graded relevance labels for the products a search ranker returned for a query, compute NDCG@k by hand and in code, and explain why it is preferred over precision@k for Amazon search.
Amazon
November 29, 20260
0
0 solved
Given graded relevance labels for the products a search ranker returned for a query, compute NDCG@k by hand and in code, and explain why it is preferred over precision@k for Amazon search.
Search relevance teams at Amazon evaluate rankers with human-judged or behavior-derived graded labels, so a phone screen often checks that you can compute and interpret NDCG. The interviewer wants the formula, a clean implementation, and awareness of edge cases like queries with no relevant results.
What the Interviewer Expects
- State the DCG formula with the gain and position discount
- Normalize by the ideal ordering
- Compute an example correctly by hand
- Handle the zero-relevance query case
- Explain when NDCG is and is not the right metric
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- How would you derive graded labels from clicks, add-to-carts and purchases?
- How do you average NDCG across queries with very different traffic?
- Why might NDCG improve offline while revenue does not move?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Labels are graded, for example 3 = exact match, 2 = substitute, 1 = complement, 0 = irrelevant. Confirm k (the first page shows about 16 to 48 results, but mobile users mostly see the top 4 to 8) and ...
Approach
. The ideal DCG sorts the same labels descending. , giving a score in that is comparable acr...