Sub topic 13
The cold start problem
This chapter assumes you know how a user-item matrix is built, how neighborhood prediction and matrix factorization work, and basic NumPy. Collaborative filtering predicts from past behavior, so it fails when there is little or no behavior to use. That failure is called the cold start problem.
Why collaborative filtering breaks
Both neighborhood methods and matrix factorization learn only from observed entries of the matrix.
- A new user has an all-zero row. Their similarity to every other user is undefined (cosine divides by a zero norm) or meaningless. A factorization model has no trained user vector for them, only the random initialization.
- A new item has an all-zero column. No user can be its neighbor, and its item vector never received a gradient update. It will never be recommended, so it never collects the ratings that would let it be recommended.
- A new system has both problems at once, with a nearly empty matrix.
| Case | What is missing | Typical fallback |
|---|---|---|
| New user | The user's row | Popularity, onboarding questions, demographic or context features |
| New item | The item's column | Content features, metadata similarity, forced exposure |
| New system | Most of the matrix | Content-based or editorial lists, imported data |
A related case is the sparse warm user: someone with two or three ratings. The model technically has data, but the estimates are noisy. Treat this as a gradual version of the same problem, not a separate one.
Fallback 1: popularity for new users
The simplest fallback ignores the user and ranks items by how well liked they are overall. A raw average is unreliable, because an item with one 5-star rating would outrank an item with 200 ratings averaging 4.6. A damped mean fixes this by pulling items with few ratings toward the global mean. The constant m acts like m phantom ratings at the global mean.
import numpy as np
R = np.array([
[5, 3, 0, 1],
[4, 0, 0, 1],
[1, 1, 0, 5],
[1, 0, 0, 4],
[0, 1, 5, 4],
], dtype=float)
def damped_item_means(R, m=2.0):
observed = R > 0
counts = observed.sum(axis=0)
sums = R.sum(axis=0)
global_mean = R[observed].mean()
return (sums + m * global_mean) / (counts + m)
def recommend_for_new_user(R, n=2, m=2.0):
scores = damped_item_means(R, m)
return np.argsort(scores)[::-1][:n].tolist()
print(damped_item_means(R).round(2))
print(recommend_for_new_user(R))Item 2 has a single 5-star rating. Its raw mean is 5.0, but the damped mean is lower, so one rating does not push it to the top. The cost of popularity is that every new user gets the same list. That is why it is a starting point and not a goal.
Fallback 2: onboarding and active learning
Instead of guessing, ask. Many services ask new users to pick favorite genres or rate a handful of items. The choice of which items to ask about matters. Asking about ten blockbusters that everyone has seen tells you little. Good onboarding items are:
- Popular enough that the user probably knows them.
- Informative, meaning opinions on them vary a lot between users (high rating variance).
- Diverse, so the answers cover different regions of the item space.
Choosing which ratings to request is called active learning in recommender research. The answers fill part of the new user's row, and the normal collaborative filtering pipeline can take over.
Fallback 3: content features for new items
If you have item metadata, such as genre, tags, text or price, you can compare a new item to existing items without any ratings of it. This is the content-based side of a hybrid recommender. The function below reuses the weighted-average idea from item-based prediction, but similarity comes from feature vectors instead of from rating columns.
import numpy as np
R = np.array([
[5, 3, 0, 1],
[4, 0, 0, 1],
[1, 1, 0, 5],
[1, 0, 0, 4],
[0, 1, 5, 4],
], dtype=float)
# One row per existing item; columns are [action, romance, scifi].
F = np.array([
[1, 0, 0],
[1, 0, 1],
[0, 1, 1],
[0, 1, 0],
], dtype=float)
def predict_new_item(R, F, f_new, user, k=2):
global_mean = float(R[R > 0].mean())
rated = np.where(R[user] > 0)[0]
if len(rated) == 0:
return global_mean
norms = np.linalg.norm(F[rated], axis=1) * np.linalg.norm(f_new)
norms[norms == 0] = 1.0
sims = (F[rated] @ f_new) / norms
order = np.argsort(sims)[::-1][:k]
w = sims[order]
if w.sum() == 0:
return global_mean
return float(w @ R[user, rated[order]] / w.sum())
f_new = np.array([1.0, 0.0, 1.0]) # an action sci-fi title with no ratings yet
print(round(predict_new_item(R, F, f_new, user=0), 2))User 0 rated items 0, 1 and 3. The new item's features match item 1 exactly and item 0 partly, so the prediction lands near 3.83, between the user's ratings of those two items. Item 3 has zero similarity and drops out of the top 2.
For a factorization model, a common extension is to learn a mapping from item features to the item's latent vector, using the warm items as training data. A new item's vector is then computed from its features alone.
Blending as data arrives
A hard switch between "cold" and "warm" behavior is brittle. A smoother approach weights the collaborative score by how much evidence exists.
def blended_score(cf_score, content_score, n_ratings, c=5.0):
alpha = n_ratings / (n_ratings + c)
return alpha * cf_score + (1.0 - alpha) * content_score
for n in [0, 2, 5, 20, 100]:
print(n, round(blended_score(4.5, 3.0, n), 2))With c = 5, a user or item with 5 ratings gets equal weight on both sources. With 100 ratings the collaborative score dominates. Tune c on validation data, not by intuition.
Exploration for new items
Content similarity can only guess. Real feedback requires showing the item to someone. If the system only recommends items it already scores highly, a new item with no history is never shown, and it never gets the data it needs. Two common remedies:
- Reserved exposure. Insert new items into a small fraction of recommendation slots, for example in one position of every list.
- Bandit methods. Algorithms such as epsilon-greedy or Thompson sampling treat each recommendation as a choice between exploiting known good items and exploring uncertain ones. Items with few observations carry high uncertainty, so they are explored more.
Exploration has a price: some impressions go to items that turn out to be poor. You set the exploration budget deliberately.
Evaluating cold start
A random split of ratings hides the problem, because most test ratings belong to users and items that also appear in training. To measure cold start performance, build the split to match the scenario.
- New-user test. Hold out entire users. For each, reveal only the first 1, 3 or 5 ratings and predict the rest. Report precision@k and recall@k against the number revealed.
- New-item test. Hold out entire items, and train on everything else. Evaluate how well the held-out items rank for users who later interacted with them.
- Time-based split. Train on the past and test on later data. This produces new users and new items at their natural rate.
Report cold start metrics separately from warm metrics. An overall average is dominated by warm interactions and can look healthy while new users have a poor experience.
Common errors
- Returning
NaNfor new users because a cosine similarity divided by a zero norm. Guard the zero norm and route the user to a fallback. - Ranking by raw item mean, so items with one rating dominate the cold start list.
- Never showing new items, then concluding they are unpopular.
- Evaluating on a random split and reporting only the overall metric.
Exercise
A new item has 3 ratings, all 5 stars, so its raw mean is 5.0. The global mean is 3.5 and the damped mean uses m = 2. What is the damped mean, and why is it better for ranking?
Show answer
The damped mean is (15 + 2 * 3.5) / (3 + 2) = 22 / 5 = 4.4. It pulls the estimate toward the global mean in proportion to how little evidence exists, so an item with three ratings does not outrank an item with hundreds of ratings that average slightly lower. As more ratings arrive, the item's own mean takes over.
Exercise
You want to measure how well your recommender serves new users. Why does a random 80/20 split of ratings fail, and what split would you use instead?
Show answer
In a random split almost every test user also has ratings in the training set, so the model never faces an empty row. Instead, hold out whole users, reveal only their first few ratings (for example 1, 3 and 5), and evaluate precision@k and recall@k on their remaining items. A time-based split is also valid, because new users appear naturally in the test period.