The bias + dot-product model we will study is the starting point for this influential family. How can it learn to match users with films?
A shared space for users and films
To picture \(K=2\), imagine two possible tastes. Both user and film profiles use the same axes.
factor 1 · action-like factor 2 · romance-like
USER PROFILES\(p_u\): how much each taste matters to this user
User 0 action fan
1.00.2
User 1 romance fan
0.21.0
FILM PROFILES\(q_i\): positive or negative signals on the same axes
Item 0 action-heavy
1.5−1.5
Item 1 romance-heavy
−1.51.5
We chose these profile numbers for the picture. How could a real model find its own numbers from ratings?
Where do the profiles come from?
The previous slide used hand-picked profiles. In a real dataset we observe ratings, not profile coordinates; fitting must infer those coordinates.
WHAT WE OBSERVERating rows
userfilmrating
005
011
115
These are three known entries from the ratings matrix. There are no “action taste” columns.
FIT MF →
AFTER FITTINGProfiles inferred from ratings
User \(u\)\(p_u\in\mathbb R^K\)
Item \(i\)\(q_i\in\mathbb R^K\)
Fit also computes the global mean and learns user/item bias terms.
WE CHOOSE \(K\) BEFORE FITTINGFit the profile values to explain the ratings we have.
Latent means the factors are hidden from the input table, not unknowable. The model estimates them from ratings; “action / romance” are only teaching labels.
Baseline + dot product predicts a rating
For this calculation, reuse the hand-picked, not fitted profiles from “A shared space”: \(p_0=(1.0,0.2)\), \(q_0=(1.5,-1.5)\), and \(q_1=(-1.5,1.5)\).
BASELINE IN THIS TOY EXAMPLE\(\mu=3,\;a_u=b_i=0\)
FULL PREDICTION RULE\(\widehat r_{ui}=\mu+a_u+b_i+p_u^\top q_i\)
ITEM 0 · ACTION-HEAVY
1.0 × 1.5= 1.5
0.2 × (−1.5)= −0.3
3 + MATCH 1.2\(\widehat r_{0,0}=4.2\)
ITEM 1 · ROMANCE-HEAVY
1.0 × (−1.5)= −1.5
0.2 × 1.5= 0.3
3 + MATCH (−1.2)\(\widehat r_{0,1}=1.8\)
The baseline is 3 for both pairs; the interaction raises one prediction to 4.2 and lowers the other to 1.8. Fitting would adjust these example coordinates using the ratings.
Same rule, a different user
Keep the two item profiles and baseline \(3\). Change only to User 1’s illustrative profile: \(p_1=(0.2,1.0)\).
USER 1 × ITEM 0
\(p_1^\top q_0=0.2(1.5)+1.0(-1.5)=-1.2\)
\(\widehat r_{1,0}=3-1.2=\mathbf{1.8}\)
USER 1 × ITEM 1
\(p_1^\top q_1=0.2(-1.5)+1.0(1.5)=+1.2\)
\(\widehat r_{1,1}=3+1.2=\mathbf{4.2}\)
The baseline remains 3 for every pair. Changing the user changes the interaction: User 1 prefers Item 1, while User 0 preferred Item 0.
Four questions before writing the estimator
01
Model → hyperparameters → fitting criterion → learned parameters
1 · What is the model?
\[f_{\theta}(u,i)=\mu+a_u+b_i+p_u^\top q_i\]
PARAMETERS\(\theta=(\mu,a,b,P,Q)\)
BASELINE PARAMETERS\(\mu,\ a,\ b\)
\(\mu\) is one global value; \(a\in\mathbb R^n\) and \(b\in\mathbb R^m\) hold user and item biases.
INTERACTION PARAMETERS\(P,\ Q\)
\(P\in\mathbb R^{n\times K}\) and \(Q\in\mathbb R^{m\times K}\) hold the user and item profiles.
For input \((u,i)\), the rule uses \(a_u,b_i,p_u,q_i\) to predict one rating. Q4 will show their fitted values.
Which parameters does \((u,i)\) select?
Input: user ID 1, item ID 0. Each ID selects one position in a bias vector and one row in a factor matrix. We show \(K=2\) columns.
USER ID 1select row 1 in both
\(a\)parameter vector \(n\times1\)
User
Bias
0
\(a_0\)
1
\(a_1\)
2
\(a_2\)
\(P\)parameter matrix \(n\times K\)
User
factor 1
factor 2
0
\(p_{0,1}\)
\(p_{0,2}\)
1
\(p_{1,1}\)
\(p_{1,2}\)
2
\(p_{2,1}\)
\(p_{2,2}\)
ITEM ID 0select row 0 in both
\(b\)parameter vector \(m\times1\)
Item
Bias
0
\(b_0\)
1
\(b_1\)
2
\(b_2\)
\(Q\)parameter matrix \(m\times K\)
Item
factor 1
factor 2
0
\(q_{0,1}\)
\(q_{0,2}\)
1
\(q_{1,1}\)
\(q_{1,2}\)
2
\(q_{2,1}\)
\(q_{2,2}\)
LOOK UP FOUR VALUES, THEN PREDICT\(\widehat r_{1,0}=\mu+a_1+b_0+p_1^\top q_0\)
\(a,b,P,Q\) are learned during fit. At prediction time, the input contains only the two IDs.
How does \((u,i)\) become a prediction?
Use the hand-picked values from “A shared space” to see how stored parameters produce one prediction.
INPUT\((u,i)=(0,0)\)No rating is supplied
BASELINE TERMS
\(\mu=3,\quad a_0=0,\quad b_0=0\)
\(\mu+a_0+b_0=3\)
INTERACTION TERMS
\(p_0=(1.0,0.2)\) \(q_0=(1.5,-1.5)\)
\(p_0^\top q_0=1.2\)
PREDICTED RATING\(\widehat r_{0,0}=3+1.2=4.2\)
The model uses the two IDs and its stored parameters. The observed rating is not supplied to predict.
2 · Which choices are hyperparameters?
NUMBER OF FACTORS\(K\in\{1,2,\ldots\}\)
Controls how much user–item structure the model can express.
REGULARIZATION STRENGTH\(\lambda\geq 0\)
Controls how strongly fitting discourages large factor values.
Choose \((K,\lambda)\)before each fit; compare candidate choices with held-out ratings.
3 · What criterion do we minimize?
First set \(\mu\) to the mean of the fitting ratings. Then learn the biases and factors:
Same Ridge operation, with the roles of users and items reversed. The user bias is the intercept.
One complete ALS iteration
STARTInitialize \(\mu,a,b,P\)
Compute \(\mu\) from fitting ratings; set biases to zero and use small random factors.
ITEM UPDATEFit each \((b_i,q_i)\)
Ridge on the users who rated item \(i\).
USER UPDATEFit each \((a_u,p_u)\)
Ridge on the items rated by user \(u\).
REPEATCheck objective
Stop when improvement is small or the iteration limit is reached.
Each item or user update is a small independent Ridge problem within its block.
The Ridge call inside an item update
from sklearn.linear_model import Ridge# User-side a and P are fixed; fit item bias and factorsuser_ids = user_ids_for_item_iX_item = P[user_ids]y_item = ratings_for_item_i - mu - a[user_ids]ridge = Ridge(alpha=lambda_, fit_intercept=True)ridge.fit(X_item, y_item)b[i] = ridge.intercept_Q[i] = ridge.coef_
The Ridge intercept gives the item bias; its coefficients give the item factors. User updates work the same way.
Monitor the objective, not just the loop counter
AFTER ITEM UPDATES\(J_{\mathrm{item\ step}}\)
≥
AFTER USER UPDATES\(J_{\mathrm{user\ step}}\)
With exact block minimization, the training objective should not increase after either block update.
If it increases: check the user/item indexing, the Ridge penalty scale, and whether the objective uses the same ratings as the updates.
A new ID has no learned bias or factor
WARM STARTKnown user + known item
Use \(\widehat\mu+\widehat a_u+\widehat b_i+\widehat p_u^\top\widehat q_i\).
COLD STARTSome terms are unavailable
New user: use \(\widehat\mu+\widehat b_i\). New item: use \(\widehat\mu+\widehat a_u\). Both new: use \(\widehat\mu\).
When reporting RMSE, separate warm-start and cold-start cases if the split contains both. An MF dot product alone does not solve cold start.
Put the whole workflow together
MODELbiases + \(p_u^\top q_i\)
→
FITALS via Ridge
→
SELECTCV over \(K,\lambda\)
→
PREDICTtest pairs once
CHECK YOUR UNDERSTANDING
In MF, which quantities are chosen before fitting, which are learned by fit, and which ratings may be used to choose the final model?