Sub topic 13
The cold start problem
This chapter assumes you know the user-item matrix, item-based neighborhood prediction, and matrix factorization from earlier chapters. You should also be comfortable with NumPy.
What cold start means
Collaborative filtering predicts from recorded behavior. A new user or a new item has no recorded behavior, so the method has nothing to work with. This is the cold start problem. It comes in three forms:
- New user: the user's row in the matrix is empty.
- New item: the item's column is empty.
- New system: the whole matrix is nearly empty, so no user or item has enough data.
Why each method fails
Each model breaks in its own way. The table shows where.
| Method | New user | New item |
|---|---|---|
| User-based | No neighbors can be found, because similarity needs shared ratings. | The item has no raters, so no neighbor has rated it. |
| Item-based | The user has no rated items to average over. | The item's similarity to every other item is 0. |
| Matrix factorization | The user vector stays near its random start. | The item vector stays near its random start. |
You can see this in the item-based code from earlier. Add a user with no ratings to the matrix and call predict. The len(rated) == 0 branch returns the global mean rating. That fallback keeps the code from crashing, but every cold user receives the same score for every item.
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],
[0, 0, 0, 0], # a brand-new user
], dtype=float)
def item_cosine(R):
norms = np.linalg.norm(R, axis=0)
norms[norms == 0] = 1.0
return (R.T @ R) / np.outer(norms, norms)
def predict(R, S, user, item, k=2):
rated = np.where(R[user] > 0)[0]
rated = rated[rated != item]
if len(rated) == 0:
return float(R[R > 0].mean())
top = rated[np.argsort(S[item, rated])[::-1][:k]]
w = S[item, top]
if w.sum() == 0:
return float(R[R > 0].mean())
return float(w @ R[user, top] / w.sum())
S = item_cosine(R)
print([round(predict(R, S, 5, i), 2) for i in range(4)])Every prediction prints as the same number, so the ranking carries no information.
Common mitigations
- Popularity fallback. Show the most-rated or highest-rated items to a new user. It is simple and gives a baseline.
- Ask for preferences. An onboarding screen asks the user to pick a few genres or rate a few items. Choose items that are both well known and divisive, so each answer tells you something.
- Use side information. For new items, use metadata such as genre, text, or price. For new users, use context such as device, country, or sign-up source.
- Explore. Show new items to a small share of users and collect feedback fast. This is the idea behind bandit methods.
- Hybrid models. Combine collaborative and content signals, so the content part works before behavior exists. A later chapter covers this.
Common errors
- Evaluating only on warm users. Your offline metrics then miss the case that hurts most in production. Report results separately for cold and warm users.
- Setting a cutoff, such as "at least 5 ratings", without checking it. Test several thresholds on held-out data.
- Switching abruptly from fallback to collaborative filtering. Blend the two, giving the collaborative score more weight as the interaction count grows.
Exercise
A new item has no ratings, and you use item-based cosine similarity. What is the item's similarity to every other item, and why does a content-based feature help?
Show answer
The similarity is 0, because its column is all zeros and the dot product with any other column is 0 (the code sets the zero norm to 1 to avoid dividing by zero). Content features such as genre exist before any interaction, so you can compare the new item to existing items and recommend it anyway.
Exercise
Why is it misleading to report one RMSE over all users when a system gets many new users every day?
Show answer
Warm users dominate the average, so the high error on cold users is hidden. Report metrics separately for cold and warm groups.