Machine Learning
Topic 24 ยท Applied ML ยท โฑ about 4 h

Recommender Systems

Popularity baselines, content-based and collaborative filtering, matrix factorisation, implicit feedback, cold start and ranking metrics.

Show:
In this topic
Beginner

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.

Beginner

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

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.

Beginner

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.

Try it

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.

Intermediate ยท Maths

Matrix factorisation

Approximate the rating matrix RR (users ร— items) by Rโ‰ˆUVโŠคR\approx UV^{\top}, where row ui\mathbf u_i of UU and row vj\mathbf v_j of VV are kk-dimensional vectors (kk โ‰ˆ 20โ€“200). Learn them by minimising squared error over the observed entries ฮฉ\Omega, with L2 regularisation:

minโกU,Vโˆ‘(i,j)โˆˆฮฉ(rijโˆ’uiโŠคvj)2+ฮป(โˆฅUโˆฅF2+โˆฅVโˆฅF2).\min_{U,V}\sum_{(i,j)\in\Omega}\big(r_{ij}-\mathbf u_i^{\top}\mathbf v_j\big)^2+\lambda\big(\lVert U\rVert_F^2+\lVert V\rVert_F^2\big).

Solve it by stochastic gradient descent or alternating least squares (fix VV, 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.

Check yourself

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?

Go deeper

๐Ÿ“š 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.

Ready