In matrix factorisation for recommendation, a rating r=4 is modelled as r^=p⊤q with user vector p=(1,0.5) and item vector q=(2,1). With squared loss plus L2 penalty 12λ(∥p∥2+∥q∥2), learning rate η=0.1 and λ=0.1, perform one stochastic gradient step on this rating. What are the new p, q and prediction?

Unsupervised learning, Matrix factorisation
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can derive and apply the SGD update for latent-factor models, remembering that both factors are updated from the old values.

Key idea

For loss 12(r−p⊤q)2+12λ(∥p∥2+∥q∥2), with error e=r−p⊤q: p←p+η(e q−λp) and q←q+η(e p−λq).

Steps

  1. Prediction: r^=1⋅2+0.5⋅1=2.5, so the error is e=4−2.5=1.5.
  2. The gradient of the loss with respect to p is −e q+λp, and with respect to q it is −e p+λq. A step against the gradient gives the update rules in the key idea.
  3. Update p using the old q: p1=1+0.1(1.5⋅2−0.1⋅1)=1+0.1(2.9)=1.29 and p2=0.5+0.1(1.5⋅1−0.1⋅0.5)=0.5+0.145=0.645.
  4. Update q using the old p (not the new one): q1=2+0.1(1.5⋅1−0.1⋅2)=2.13 and q2=1+0.1(1.5⋅0.5−0.1⋅1)=1.065.
  5. New prediction: 1.29⋅2.13+0.645⋅1.065=2.7477+0.6869≈3.435, closer to the target 4 than 2.5 was.

Common mistakes

How long your answer should be

Half a page; 4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: Four 2-D points are (1,2), (2,1), (3,4) and (4,3). What are the sample covariance matrix, the first principal component, the fraction of variance it explains, and the coordinate of the first point along it?
Next in Unsupervised learning: A Gaussian kernel density estimate with bandwidth h is built from the three 1-D points 1, 2 and 4. (a) Write p^(x) and compute p^(2) for h=1. (b) What does p^(2) become for h=0.2, and what does the change in h do to the estimate in general?