SafeZone AI Learn
Learn/ Machine Learning/ Unsupervised Learning · lesson 6 of 7

Recommender systems

Collaborative filtering as matrix factorization — the SVD lesson's low-rank machinery earning billions — with ALS running live, the implicit-feedback trick, ranking losses, and the feedback loops that make deployed recommenders eat their own tail.

Every lesson in this module found structure nobody labeled. This one closes the module on the version of that idea with the largest commercial footprint in machine-learning history: given a matrix of users × items where almost every entry is missing — most people have rated, watched, or bought almost nothing — predict the missing entries well enough to decide what to show next. The tool is one you already own: the dimensionality-reduction lesson’s low-rank factorization, pointed at a matrix that is 99% holes. The twist that makes it an engineering discipline rather than a linear-algebra exercise is what happens after deployment, when the model starts generating the very data it trains on.

The model: tastes are low-rank

The collaborative-filtering bet: the ratings matrix RRm×nR \in \mathbb{R}^{m \times n} is approximately rank kk with km,nk \ll m, n — user uu‘s tastes compress to a vector uuRk\mathbf{u}_u \in \mathbb{R}^k, item ii‘s character to viRk\mathbf{v}_i \in \mathbb{R}^k, and a rating is their alignment:

r^ui=uuvi.\hat{r}_{ui} = \mathbf{u}_u^\top \mathbf{v}_i .

The latent axes are learned, not named — but they come out interpretable often enough (serious↔escapist, mainstream↔niche) to justify the story: each user is a point in taste-space, each item a point in the same space, and recommendation is geometry. This is exactly the SVD lesson’s claim that meaning concentrates in a few directions — with one fatal complication. You cannot just run SVD: the matrix isn’t sparse-with-zeros, it is sparse-with-unknowns, and treating a missing rating as 0 teaches the model that everyone mildly dislikes everything they haven’t met. So the objective sums over observed entries only,

minU,V(u,i)Ω(ruiuuvi)2  +  λ(uuu2+ivi2),\min_{U, V} \sum_{(u,i) \in \Omega} \big( r_{ui} - \mathbf{u}_u^\top \mathbf{v}_i \big)^2 \;+\; \lambda \Big( \textstyle\sum_u \lVert \mathbf{u}_u \rVert^2 + \sum_i \lVert \mathbf{v}_i \rVert^2 \Big),

which loses the SVD’s closed form (the sum over Ω\Omega breaks orthogonality) and its convexity — like every factorization in this curriculum, the problem is biconvex: convex in UU with VV fixed and vice versa. That structure is the algorithm. Alternating least squares fixes VV and solves for each user’s uu\mathbf{u}_u — which is nothing but a ridge regression of that user’s observed ratings onto the factors of the items they rated (the regularization lesson, verbatim) — then swaps roles. Each half-step solves its subproblem exactly, so the loss monotonically decreases; and because each user’s solve is independent, ALS parallelizes embarrassingly, which is why it scaled to industry first. (SGD on the same objective — Koren’s Netflix-era recipe — trades the clean solves for cheaper updates plus bias terms μ+bu+bi\mu + b_u + b_i that soak up “this user grades harshly” and “this item is broadly loved” before the factors spend rank on them.)

Left: the true matrix, dots marking the ratings your model may see. Right: the reconstruction UVᵀ. Sweep k with λ small: at k = 1 both RMSEs are mediocre (one axis can’t span two tastes); at k = 2 — the true rank — test RMSE bottoms out around 0.4, within reach of the 0.25 noise floor; push to k = 4, 5, 6 and watch the split this whole curriculum keeps rediscovering: train RMSE marches toward zero while test RMSE climbs, because surplus rank memorizes noise in the observed cells and extrapolates it into the hidden ones. Now drop the observed fraction toward 15%: k = 2 holds its ground but k = 3’s test error more than doubles — with fewer observations per parameter the U steepens, and regularization stops being optional. That is exactly the regime real recommenders live in, where the median user has rated almost nothing; the heatmap shows WHERE the failure lands — users with the fewest dots get the blurriest rows. Cold start, drawn.

Implicit feedback: learning from what nobody said

Ratings are rare; behaviour is torrential — clicks, watches, purchases, dwell. But implicit data has no negatives: a click means interest, an un-click means interest-or-never-seen, and now the missing entries carry information you can’t ignore the way the explicit objective did. The standard move (Hu, Koren & Volinsky, 2008) reframes: predict a binary preference pui=1[rui>0]p_{ui} = \mathbb{1}[r_{ui} > 0] over all cells, but weight each term by a confidence cui=1+αruic_{ui} = 1 + \alpha\, r_{ui} that grows with observed engagement — unclicked cells participate as low-confidence zeros rather than trusted ones, and a clever bit of algebra keeps ALS tractable despite the sum now running over all m×nm \times n cells. The deeper reframe is that recommendation is a ranking problem, not a rating-regression problem: BPR-style losses optimize Pr(clicked item scores above unclicked item)\Pr(\text{clicked item scores above unclicked item}) — pairwise logistic regression on score differences, the same Bradley–Terry structure the RL track’s preference-tuning lesson derives — which targets what the product actually does with the scores: sort.

The tail-eating: deployed recommenders make their own data

Everything above treats the data as given. In production the model chooses the data: users can only click what was shown, and what was shown is what the previous model scored highly. Three pathologies follow, and the causal inference lesson names them all. Position and exposure bias: an un-clicked item at rank 40 is not disliked, it is unseen — logged clicks confound relevance with exposure, so naive retraining learns the old model’s rankings back. The feedback loop: popular items get shown, get clicked, get more popular in the next training set — a rich-get-richer dynamic that narrows catalogs and, on content platforms, narrows users. Selection as a collider: the log conditions on “was recommended”, a variable caused by every signal the old model used, manufacturing spurious correlations exactly as Berkson’s paradox promises. The honest mitigations are causal moves, not better factorizations: inject randomized exploration (show some items by lottery, and weight those log entries as the near-experimental gold they are), model exposure explicitly with inverse-propensity weights 1/Pr(shown)1/\Pr(\text{shown}), and hold out truly random slates for evaluation. A recommender team without an exploration budget is training on the confounded exhaust of its own past decisions.

Evaluation, and the metric that lied for a decade

Offline, the field graded itself on rating RMSE for years — the Netflix Prize paid a million dollars for a 10% improvement in it (0.9514 → 0.8567) — before conceding that RMSE on held-out ratings barely correlates with what users do when shown a slate. What the product needs is top-of-list quality: precision@k (how much of the slate lands), NDCG (rank the hits high, discounted by position), coverage and diversity (is the model just replaying popularity?). And the offline/online gap never fully closes, because the log’s biases infect the test split too — which is why the last word belongs to the previous module’s territory: the A/B test, with engagement, retention, and guardrail metrics, on real slates. Offline metrics select candidates; experiments decide.

The modern architecture, in one paragraph, so the throughline is visible: industrial systems (YouTube’s two-stage design is the canonical write-up) split into a retrieval stage — a two-tower model where user and item towers each output an embedding and candidates are the item vectors nearest the user vector, which is precisely uv\mathbf{u}^\top \mathbf{v} with the factorization replaced by learned networks over features, killing cold-start by construction — and a ranking stage, a gradient-boosted or neural model over rich features that orders the few hundred survivors. Matrix factorization didn’t die; it became the retrieval geometry, and its embedding-dot-product core is the same operation the LLM track’s embedding lesson builds search on.

Exercises

Work these before the next track

  1. Show that with VV fixed, the ALS subproblem for one user is exactly ridge regression: derive uu=(VuVu+λI)1Vuru\mathbf{u}_u = (V_u^\top V_u + \lambda I)^{-1} V_u^\top \mathbf{r}_u, where VuV_u stacks the factors of the items user uu rated. What is the per-user cost, and why does this parallelize better than SGD?
    Solution

    Worked solutions are part of Premiumunlock all of them for £5/month →

  2. 5 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →

References

  • Y. Koren, R. Bell & C. Volinsky, “Matrix Factorization Techniques for Recommender Systems”, IEEE Computer 2009 — the Netflix-era canon.
  • Y. Hu, Y. Koren & C. Volinsky, “Collaborative Filtering for Implicit Feedback Datasets”, ICDM 2008 — confidence-weighted ALS.
  • S. Rendle et al., “BPR: Bayesian Personalized Ranking from Implicit Feedback”, UAI 2009 — recommendation as pairwise ranking.
  • P. Covington, J. Adams & E. Sargin, “Deep Neural Networks for YouTube Recommendations”, RecSys 2016 — the retrieval/ranking two-stage blueprint.
  • T. Schnabel et al., “Recommendations as Treatments: Debiasing Learning and Evaluation”, ICML 2016 — propensity weighting for logged feedback.