WRITE · TRACE · UNDERSTAND
Evaluate graded ranking with a normalized ideal order
Return NDCG at positive integer k.
Read lesson: Evaluate graded ranking with a normalized ideal order →
Your experiment
Return NDCG at positive integer k. Deduplicate ranked IDs in first-occurrence order before applying k. Missing IDs have relevance zero. Use gain 2**grade-1 and discount log2(rank+1), with rank starting at one. The ideal order uses all grades sorted descending. Return None when ideal gain is zero. Grades must be integers in 0..10.
Python runs in your browser. Your draft stays on this device.
What to look for
Inspect judgments, deduplication and the undefined all-zero case. A perfect NDCG on a tiny fixture says nothing about an unmeasured query population.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.
