Matrix Factorization & ALS
Decomposing high-dimensional sparse user-item interaction matrices into low-rank dense embedding vectors.
Low-Rank Matrix Decomposition
Given sparse interaction matrix where most entries are un-observed:
- : Dense User Latent Matrix (row ).
- : Dense Item Latent Matrix (row ).
- : Latent dimension size (e.g., ).
Sparse Rating Matrix R (U × I) User Embeddings P (U × k) Item Embeddings Q^T (k × I)
┌───┬───┬───┬───┐ ┌───┬───┐ ┌───┬───┬───┬───┐
│ 5 │ ? │ 1 │ ? │ │.1 │.8 │ │.4 │.2 │.9 │.1 │
├───┼───┼───┼───┤ ≈ ├───┼───┤ × ├───┼───┼───┼───┤
│ ? │ 4 │ ? │ 2 │ │.9 │.3 │ │.7 │.6 │.1 │.8 │
└───┴───┴───┴───┘ └───┴───┘ └───┴───┴───┴───┘
Predicted Rating with Biases:
- : Global average rating across all users and items.
- : User bias (some users systematically rate higher or lower).
- : Item bias (popular movies receive higher average scores).
Alternating Least Squares (ALS) vs SGD
Objective Loss with L2 Regularization :
Because multiplies two unknown matrices, the loss is non-convex jointly.
ALS Optimization Loop:
- Fix : Loss becomes strictly quadratic in . Solve for each user in parallel via closed-form linear algebra:
- Fix : Loss becomes strictly quadratic in . Solve for each item in parallel:
- Repeat until convergence!
Say this out loud
"Matrix Factorization decomposes sparse user-item interaction matrices R into dense low-rank user embeddings P and item embeddings Q. Preference predictions are computed via dot product R̂_ui = μ + b_u + b_i + p_u^T q_i. Alternating Least Squares (ALS) optimizes MF efficiently on distributed Spark clusters by alternating between solving P and Q in closed-form."
Follow-ups to expect
- How does iALS handle Implicit Feedback (Hu, Koren, Volinsky)? Replaces binary ratings with preference and confidence weight , solving .
- How does Matrix Factorization handle Cold-Start Users? Pure MF fails on new users with zero interaction history (). Cold-start requires hybrid models incorporating user demographics and item content features (Two-Tower networks).
Check yourself
How does Matrix Factorization predict user u's preference rating for an un-observed item i?