Matrix factorisation and recommenders
Low-rank models of user–item matrices: SVD, latent factors, ALS and collaborative filtering.
Animated explanation
The idea
Netflix knows a few of your ratings and a few of millions of other people's. How can it guess how you'd rate a film you haven't seen? Assume tastes are driven by a handful of hidden factors: how much you like action, romance, documentaries… Each film has the same kind of profile. Your predicted rating is how well your taste vector matches the film's profile: a dot product.
Learning those vectors from the known ratings is matrix factorisation: approximate the huge, mostly empty rating matrix by with only columns each. It is unsupervised structure discovery (the factors are never labelled) put to work for prediction. The same low-rank idea appears in topic models (NMF), image compression (truncated SVD) and word embeddings.
SVD and the missing-data problem
For a complete matrix, the truncated SVD gives the best rank- approximation (Eckart–Young). Rating matrices are mostly missing, and treating gaps as zeros would teach the model that unseen means disliked. So we fit the factors only on observed entries, with L2 regularisation to avoid overfitting the few ratings each user has, using SGD or alternating least squares.
Practical recommender details
Add user and item biases (some users rate everything high; some films are universally loved). Handle implicit feedback (clicks, plays) with weighted ALS. Cold start: new users or items have no ratings, so blend in content features. Evaluate with RMSE on held-out ratings, but for products also with ranking metrics (precision@k, NDCG).
The algorithm, step by step
- 1Collect observed triples ; hold some out for validation.
- 2Initialise user factors and item factors with small random values.
- 3ALS: alternately solve a ridge regression for each user's (Q fixed) and each item's (P fixed). Or SGD over shuffled ratings.
- 4Stop when validation RMSE stops improving; recommend the unseen items with the highest .
The maths
Model
Regularised objective
ALS update for one user
Truncated SVD
Strengths and weaknesses
Strengths
- Captures hidden structure from sparse data
- Scales to millions of users and items (ALS parallelises)
- Factors double as user and item embeddings
Weaknesses
- Cold start for new users and items
- Factors are not directly interpretable
- Needs regularisation and tuning of k and λ
Reach for it when…
Check your understanding
Lambdian Lab
ALS for a rating matrix
Ratings come as a dense matrix R with a boolean mask M of observed cells.
- rank_k(A, k): the best rank-k approximation of a complete matrix via SVD.
- als(R, M, k, lam, iters, seed): alternating least squares on observed cells; return (P, Q) with predictions P @ Q.T.
- rmse(R, M, P, Q): root mean squared error on the cells where M is True.