Measure catalog coverage of recommendations

Why it matters Feed teams track coverage to catch a model that collapses onto a few viral posts.

A recommender that shows everyone the same 10 items has low coverage.

Write coverage(rec_lists, n_items). rec_lists is a list of recommended item lists. Return the fraction of the n_items catalog that appears in at least one list.

Signaturedef coverage(rec_lists, n_items)

Example

coverage([[1, 2], [2, 3]], 10) is 0.3.

Understand the idea

Accuracy alone can hide a lazy recommender that shows everyone the same few hits. Catalog coverage asks what share of all items ever gets recommended to anyone. Worked example: three users get lists [0, 1, 2], [1, 2, 4] and [2, 4, 5], and the catalog has 20 items. The distinct recommended items are {0, 1, 2, 4, 5}, which is 5 items, so coverage = 5 / 20 = 0.25. Notice that item 2 appears three times but still counts once. Rule: take the union of every item in every list (all positions, not just the first), count how many distinct items there are, and divide by n_items. An empty set of lists gives 0. Used in: checking that a recommender gives the long tail of a catalog a chance, comparing diversity between models, and spotting popularity bias in feeds and shopping recommendations.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 3.

  • Sample 1: examplecoverage([[1, 2], [2, 3]], 10)
  • Sample 2: same listcoverage([[4, 5], [4, 5], [4, 5]], 4)
  • Test 3: fullcoverage([[0, 1], [2], [3]], 4)