Foundations to Frontier
Tests
D. Classical Machine Learning › D13 Recommender Systems

Matrix Factorization: SVD and Funk SVD

Matrix factorisation explains a ratings matrix with a few hidden dimensions of taste: each user u gets a vector p_u, each item i a vector q_i, and a rating is predicted as μ + b_u + b_i + p_u·q_i, the global mean plus user and item biases plus the dot product of the two vectors. Classical SVD gives the best low-rank approximation of a full matrix, but ratings matrices are mostly missing, and imputing the gaps distorts it. Simon Funk's approach for the Netflix Prize (2006) instead fits the factors only to the observed ratings by stochastic gradient descent with L2 regularisation; Koren, Bell and Volinsky made biased MF the standard model. It captures global structure that neighbourhood methods miss, needs (m + n)(k + 1) parameters instead of m·n, and produces embeddings that cluster similar users and items. Its choices, the number of factors k and the regularisation λ, trade underfitting against overfitting. This page covers the low-rank model, Eckart–Young and why plain SVD struggles with missing data, the regularised objective, SGD updates, biases, choosing k and λ, and the embeddings' meaning. In the exercises you implement Funk SVD and compare it with imputed SVD and baselines; then you map how k and λ affect training and held-out error.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Hidden dimensions of taste

Suppose every film could be scored on a few hidden scales, such as how much action it has or how cerebral it is, and every viewer had a matching set of preferences. Then a viewer’s rating of a film would be roughly how well their preferences line up with the film’s scores. Matrix factorisation discovers such scales automatically from the ratings alone, giving every user and every item a short list of numbers, and predicts any missing rating by combining the two lists.

Matrix factorisation: learn hidden taste dimensions from ratings
epoch 0/60
film factors q (dims 1, 2)RMSE: training (blue), held-out (orange)
training…
The data have one real taste dimension (which genre you prefer). With k = 1–2 the film vectors split by genre, a structure learned only from ratings. With many factors and little weight decay, training error keeps falling while held-out error turns up: the extra factors fit noise. Raising λ shrinks unneeded factors toward zero and closes the gap; too much λ underfits.
Why engineers care

Low-rank factorisation is one of the most reused ideas in data science: recommenders, completing sparse sensor or test matrices, embedding users, parts and documents, and compressing large tables. The same “learn embeddings so that their dot products match observations” principle underlies word embeddings and two-tower retrieval models.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Matrix factorisation gives each user and item…
  2. 2. A predicted rating combines…
  3. 3. The hidden factors are learned from…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The model and one SGD step by hand

Model. r̂ᵤᵢ = μ + bᵤ + bᵢ + pᵤ·qᵢ. With μ = 3.5, bᵤ = 0.2, bᵢ = −0.3, pᵤ = (1, 0.5) and qᵢ = (0.4, 0.2): 3.4 + 0.5 = 3.9.

Objective. Minimise over observed (u, i) only:

Σ (rᵤᵢ − r̂ᵤᵢ)² + λ(Σbᵤ² + Σbᵢ² + Σ‖pᵤ‖² + Σ‖qᵢ‖²).

SGD update for one rating, with error e = rᵤᵢ − r̂ᵤᵢ and learning rate η:

  • bᵤ ← bᵤ + η(e − λbᵤ), and bᵢ likewise;
  • pᵤ ← pᵤ + η(e qᵢ − λpᵤ);
  • qᵢ ← qᵢ + η(e pᵤ − λqᵢ).

Starting from μ = 3.5, zero biases and pᵤ = qᵢ = (0.1, 0.1), a rating of 5 gives e = 5 − 3.52 = 1.48, so with η = 0.1 and λ = 0 the bias bᵤ becomes 0.148.

Parameter count. (m + n)(k + 1) + 1 = 8801 for 600 users, 200 items and k = 10, against 120 000 matrix entries.

The steps in plain English:

  1. Centre on μ, and initialise the biases at 0 and the factors with small random values.
  2. Loop over observed ratings in random order, applying the SGD updates, for a few dozen epochs.
  3. Choose k and λ, and the number of epochs, by validation RMSE.
  4. Predict any rating as μ + bᵤ + bᵢ + pᵤ·qᵢ; use the factors as embeddings for similarity and search.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Funk SVD fits the factors to…
  2. 2. λ in the objective controls…
  3. 3. The factor update for pᵤ moves along…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why not plain SVD?

Eckart–Young. For a fully observed matrix A, truncating its SVD to k components gives the best rank-k approximation in Frobenius norm. Ratings matrices are 90–99% missing: to use SVD you must fill the gaps first, with zeros or baseline predictions, and then the decomposition fits those invented values as if they were data.

Funk SVD. It fits only the observed entries. The objective is non-convex in (P, Q) but convex in each one with the other fixed, and SGD finds good solutions in practice. Regularisation is essential: with k factors per user and just a few ratings, an unregularised model can fit every training rating.

Biases matter. Most of the predictable variance is user and item bias. Including bᵤ and bᵢ explicitly lets the factors focus on interactions, which is taste.

Exercise 1 (600 users × 200 items, 10.8% observed). Held-out RMSE:

  • bias baseline 0.948;
  • SVD of the baseline-imputed matrix (rank 5) 0.890;
  • Funk SVD (k = 10, λ = 0.05) 0.808, with training RMSE 0.539.

On this same split, the item-based k-NN of the previous topic scored 0.852.

from surprise import SVD
algo = SVD(n_factors=10, reg_all=0.05, lr_all=0.01, n_epochs=40, biased=True)   # Funk-style biased MF
🐍 Exercise 1: Funk SVD versus imputed SVD
Implement biased matrix factorisation trained by mini-batch SGD on observed ratings, and SVD of a baseline-imputed matrix; compare held-out RMSE with the bias baseline.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Plain SVD on a ratings matrix first needs…
  2. 2. Funk SVD's objective is…
  3. 3. Explicit biases let the factors focus on…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Low-rank matrix completion. If the true matrix has rank k, satisfies an incoherence condition, and has about k·n·polylog(n) entries observed uniformly at random, nuclear-norm minimisation recovers it exactly (Candès and Recht, 2009). The λ‖P‖² + λ‖Q‖² penalty is a variational form of the nuclear norm: ‖X‖* = min over X = PQᵀ of ½(‖P‖² + ‖Q‖²).

Extensions.

  • SVD++ adds implicit feedback (which items a user rated).
  • timeSVD++ adds time-varying biases.
  • Non-negative MF gives parts-based factors.
  • Probabilistic MF (Salakhutdinov and Mnih, 2008) is the Bayesian reading of the same model: Gaussian priors correspond to L2 penalties.

Identifiability. The factors are determined only up to an invertible transformation: PQᵀ = (PA)(QA⁻ᵀ)ᵀ. With L2 regularisation, rotations remain free, so individual factor dimensions need not be interpretable, even when the clustering of items is.

Interview questions.

  • How do you choose the number of factors? By validation error over a grid of (k, λ), and with early stopping. Larger k needs more regularisation, and performance plateaus or degrades past the data’s effective rank.
  • Matrix factorisation or neighbourhood methods? MF captures global structure and gives compact embeddings; neighbourhoods capture local relations and explain easily. In the Netflix Prize, blends of both won.
📝 Quick check (Level 3)
0/3 answered
  1. 1. The L2 penalty on P and Q relates to…
  2. 2. Probabilistic MF interprets L2 penalties as…
  3. 3. Individual factor dimensions are…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Factors and regularisation

History.

  • S. Funk (2006) described incremental SVD for the Netflix Prize.
  • R. Salakhutdinov and A. Mnih (2008) introduced probabilistic MF.
  • Y. Koren, R. Bell and C. Volinsky (2009) described biased MF in the Netflix Prize.
  • E. Candès and B. Recht (2009) proved matrix-completion guarantees.
  • Koren’s SVD++ (2008) added implicit feedback.

Exercise 2. The same data, generated with 5 latent factors. Each cell gives training RMSE, then held-out RMSE.

k λ = 0 λ = 0.02 λ = 0.1
2 0.711, 0.899 0.720, 0.897 0.787, 0.907
5 0.439, 0.697 0.449, 0.693 0.529, 0.730
10 0.451, 0.843 0.481, 0.812 0.641, 0.836
30 0.270, 0.869 0.330, 0.823 0.559, 0.823
  • The best held-out error came at the true rank, k = 5 (0.693). Too few factors (k = 2) underfit both sets.
  • More factors kept lowering training error but raised held-out error. k = 30 with no regularisation fitted training ratings to 0.270 RMSE, below the noise level of about 0.58, and generalised worse (0.869). That is overfitting.
  • Regularisation reduced overfitting at large k (0.869 → 0.823 at k = 30) but underfit at the right k (λ = 0.1 at k = 5: 0.730). λ must be tuned together with k.
  • Early stopping, small initialisation and the finite number of epochs also act as implicit regularisers: even unregularised k = 10 did not blow up.
🐍 Exercise 2 (research): factors and regularisation
Train Funk SVD with k = 2, 5, 10, 30 and λ = 0, 0.02, 0.1 on ratings generated with 5 true factors, and report training and held-out RMSE.

Matrix factorisation in AI, robotics and aerospace

  • Sparse test-matrix completion: predict untested combinations of configurations and conditions from a partially filled test campaign.
  • Fleet health embeddings: factorise asset × sensor-statistic matrices into low-dimensional health states.
  • Recommendation and retrieval: user and document embeddings for engineering knowledge systems, trained from usage logs.

References

  1. Y. Koren, R. Bell, C. Volinsky (2009). “Matrix factorization techniques for recommender systems.” IEEE Computer 42(8).
  2. S. Funk (2006). “Netflix update: try this at home.” Blog post, sifter.org.
  3. R. Salakhutdinov, A. Mnih (2008). “Probabilistic matrix factorization.” Advances in NeurIPS 20.
  4. E. J. Candès, B. Recht (2009). “Exact matrix completion via convex optimization.” Foundations of Computational Mathematics 9(6).
  5. Y. Koren (2008). “Factorization meets the neighborhood: a multifaceted collaborative filtering model.” Proc. ACM KDD.