A ratings matrix is mostly empty, and the factorisation model \(\hat y_{ui}=\mu+b_u+c_i+\mathbf u_u^{\mathsf T}\mathbf v_i\) fills it in by giving every user and every item a short vector. Here 300 simulated users have rated some of 200 simulated items in six genres (12 percent of the entries are observed; 20 percent of those are held out). Each iteration solves a ridge regression for every user with the items fixed, then one for every item with the users fixed. Change the number of factors \(K\) and the penalty \(\lambda\) to see underfitting, a good fit and overfitting.
Data are simulated (a stand-in for the Netflix and MovieLens data of the book): true latent dimension 3, rating noise 0.5, ratings rounded to 1–5, popular items rated more often. RMSE is the root mean squared error of the unrounded prediction on the ratings of that split. The dashed grey line is the error of the true mean rating on the test entries, the best any model could do. The item vectors are only defined up to a rotation, so the right panel shows them on their principal axes.
code/ch22_recommender_systems.py (simulate_ratings, als, sgd_mf, svd_zero_fill).