Blend personal and popular scores for cold-start users

Why it matters Shrinkage toward popularity is a standard fix for cold-start users in feeds, shops and streaming apps.

A user with two interactions has a noisy personal profile. Recommenders shrink such users toward the global popularity scores, trusting the personal model more as history grows.

Write blend_scores(personal, popular, n, shrink, k). personal and popular are length I score lists (personal may be None for a brand-new user). The trust weight is w = n / (n + shrink), or 0 if personal is None. Score = w * personal + (1 - w) * popular. Return (scores as a numpy array, list of the top k item indices by score with ties to the smaller index).

Signaturedef blend_scores(personal, popular, n, shrink, k)

Example

blend_scores([1, 0, 0], [0, 1, 0.5], 1, 3, 2) gives (array([0.25, 0.75, 0.375]), [1, 2]).

Understand the idea

A new user's personal model is built on very little data, so it is mostly noise. Popular items are a safe guess for anyone. The fix is to blend the two, and to move the blend toward personal scores as evidence piles up, the same way you would trust a friend's restaurant advice more after they have eaten out a lot.

Example: shrink 3, user with n = 1 interaction. w = 1 / (1 + 3) = 0.25. An item the personal model loves (1.0) but nobody else watches (0) gets 0.25. A popular item (1.0) the personal model ignores gets 0.75. With n = 97, w = 0.97 and the personal model takes over.

Rule: w = n / (n + shrink); score = w * personal + (1 - w) * popular.

The shrink constant is tuned offline; it equals the number of interactions at which both sources get equal weight.

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

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

  • Sample 1: exampleblend_scores([1, 0, 0], [0, 1, 0.5], 1, 3, 2)
  • Sample 2: heavy userblend_scores([0.9, 0.1, 0.2, 0.0], [0.1, 0.8, 0.5, 0.3], 97, 3, 2)
  • Test 3: new userblend_scores(None, [0.2, 0.9, 0.9], 0, 5, 3)
  • Test 4: tiesblend_scores([0.5, 0.5], [0.5, 0.5], 4, 4, 1)