Recommender Systems
Popularity baselines, content-based and collaborative filtering, matrix factorisation, implicit feedback, cold start and ranking metrics.
What recommenders do
Recommenders choose which few items to show each person out of many: videos, products, articles, jobs, health-education materials. They drive a large share of activity on streaming services and online shops, and appear in junior ML roles at many companies.
The data is a big, mostly empty user ร item matrix. Feedback can be explicit (star ratings) or, far more often, implicit (clicks, watches, purchases): we see what people chose, but not what they disliked, and missing does not mean negative.
Always start with a popularity baseline (recommend the most popular items the user hasn't seen). It is hard to beat for new users and keeps you honest about how much personalisation adds.
Content-based and collaborative filtering
Content-based methods recommend items similar in their features to what the user liked: same topic, same author, similar text embedding. They work for brand-new items but tend to recommend more of the same.
Collaborative filtering uses behaviour only: "people who liked this also liked that". Item-based CF computes similarity between items from the users who rated both (often cosine similarity between item columns), then scores a new item by how similar it is to the items the user liked. Matrix factorisation learns a short vector for every user and every item so that their dot product predicts the interaction; it generalises better on sparse data, and the two-tower neural networks used at large companies are its descendants.
The cold-start problem: a new user or item has no history, so CF has nothing to go on. Fall back to popularity, ask a few onboarding questions, or use content features until history accumulates.
Try it: item-based recommendations
Click cells to change ratings (0 = not watched). Pick a user to see their recommendations and which of their liked items each one comes from.
Interactive: this part runs in your browser.
Evaluating recommenders
Recommenders are judged on ranking: did the items the user actually engaged with appear near the top? Common offline metrics, computed on held-out later interactions (split by time!): precision@k (fraction of the top k that were relevant), recall@k (fraction of relevant items that made the top k), MAP and NDCG (which reward relevant items higher up). Also track coverage (how much of the catalogue ever gets recommended) and diversity.
Offline metrics only approximate the real goal, so successful systems are confirmed with A/B tests on engagement, and watched for feedback loops: a recommender trained on its own recommendations keeps promoting what it already promoted.
Code example: item-based collaborative filtering
A worked example: read it step by step (every part is explained), then run it and experiment.
Interactive: this part runs in your browser.
Matrix factorisation
Approximate the rating matrix (users ร items) by , where row of and row of are -dimensional vectors ( โ 20โ200). Learn them by minimising squared error over the observed entries , with L2 regularisation:
Solve it by stochastic gradient descent or alternating least squares (fix , solve a ridge regression for each user; then swap). For implicit feedback, every unobserved entry is treated as a weak negative with low confidence weight.
Quiz
1. Implicit feedback meansโฆ
2. A brand-new item has no interactions. Which approach can still recommend it?
3. Item-based CF scores an unseen item highly whenโฆ
4. Precision@5 = 0.4 meansโฆ
5. Why start with a popularity baseline?
๐ Further reading
Trusted, mostly free sources: official documentation, well-known textbooks and courses. When you want to confirm or go deeper on anything here, start with these.
- Google: Recommendation systems course โ Free short course