Catalog Coverage: Share of Items Ever Shown

Recommender SystemsEasy+10 XP+10

Catalog Coverage: Share of Items Ever Shown

A recommender can score beautifully on accuracy while only ever recommending the same two hundred items. Everything else in the catalogue is invisible — never shown, so never clicked, so never learned about. Catalog coverage measures that directly.

coverage=∣distinct items recommended∩catalog∣∣catalog∣coverage = \frac{|\text{distinct items recommended} \cap \text{catalog}|}{|\text{catalog}|}coverage=∣catalog∣∣distinct items recommended∩catalog∣​

Task: write coverage(recommendations, catalog) returning that fraction, rounded to 4 decimal places.

  • recommendations is a list of lists — one recommendation list per user.
  • Count each item once, however many users were shown it. That's the whole point: a thousand users all shown the same item is coverage of one item.
  • Only count recommended items that are in the catalogue. Anything else is a bug upstream and shouldn't flatter the number.
  • The denominator is the size of the whole catalogue, including items nobody was shown.

What makes this worth measuring is that it's in genuine tension with accuracy. The safest way to be accurate is to recommend popular things, and the safest way to get coverage is to spread recommendations thin — so optimising either alone gives you a system that's bad at the other. Coverage is also a business number, not just a model one: a marketplace whose recommender ignores 95% of its sellers has a seller-retention problem, whatever the click-through rate says.

Examples

recommendations = [['a', 'b'], ['b', 'c']]
catalog = ['a', 'b', 'c', 'd']
returns 0.75
recommendations = [['z']]
catalog = ['a', 'b']
returns 0.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run