In alternating least squares (ALS) for matrix factorisation, a user has rated two items, with item vectors q1=(1,0) and q2=(1,1) fixed and ratings 3 and 5. (a) Derive the update that minimises ∑i(ri−p⊤qi)2+λ∥p∥2 for the user vector p. (b) Compute p for λ=1, and for λ=0. (c) Why is ALS attractive for large recommenders?

Unsupervised learning, Matrix factorisation
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can derive the ridge-regression update behind ALS and use it numerically.

Key idea

With item vectors fixed, the user vector solves a ridge regression: p=(Q⊤Q+λI)−1Q⊤r, where the rows of Q are the rated items' vectors and r holds the ratings.

Steps

  1. Stack the rated items' vectors as the rows of Q and the ratings in a vector r. The objective is ∥r−Qp∥2+λ∥p∥2.
  2. Set the gradient to zero: −2Q⊤(r−Qp)+2λp=0, so (Q⊤Q+λI)p=Q⊤r and p=(Q⊤Q+λI)−1Q⊤r.
  3. Here Q=[1011], so Q⊤Q=[2111] and Q⊤r=(3+5, 5)=(8,5).
  4. For λ=1: Q⊤Q+I=[3112] with determinant 5, and inverse 15[2−1−13]. So p=15(16−5, −8+15)=(2.2, 1.4). The predictions are 2.2 and 3.6, shrunk below the ratings 3 and 5.
  5. For λ=0: p solves p1=3 and p1+p2=5, so p=(3,2) and both ratings are fitted exactly. With few ratings this overfits, which is why the penalty is needed.
  6. Then the same step is applied to every item vector with the user vectors fixed, and the two sweeps alternate. Each sweep decouples across users (or items), so it parallelises well and handles implicit-feedback data, and each subproblem is convex even though the joint problem is not.

Common mistakes

How long your answer should be

Half a page to a page; 6 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: An isolation forest uses sub-samples of size ψ=256 and scores a point with s(x,ψ)=2−E[h(x)]/c(ψ), where c(ψ)=2(ln⁡(ψ−1)+0.5772)−2(ψ−1)ψ. (a) Compute c(256). (b) Find s for average path lengths E[h]=4, 10.24 and 12 and say what each means. (c) Why is c(ψ) in the formula?
Next in Unsupervised learning: Probabilistic PCA models x=Wz+μ+ϵ with z∼N(0,Iq) and ϵ∼N(0,σ2Id). The maximum-likelihood solution is WML=Uq(Λq−σ2I)1/2R and σML2=1d−q∑j>qλj. (a) For d=4 and sample covariance eigenvalues 6,3,0.6,0.4, find σML2 and the scale of each column of WML for q=2. (b) Why does the covariance of the model match the data in the top q directions? (c) How does PPCA relate to ordinary PCA as σ2→0?