Matrix Factorization for Recommender Systems
The problem collaborative filtering runs into
Plain collaborative filtering computes similarity directly on the raw, sparse user-item ratings matrix. At Netflix scale — hundreds of millions of users, tens of thousands of titles, and each user rating a tiny sliver of the catalog — this becomes both computationally expensive and statistically shaky. Two users who happen to share three ratings out of thousands of possible titles produce a noisy similarity score.
Matrix factorization takes a different approach entirely: instead of comparing rows or columns of the raw matrix, it learns a compressed numerical representation — a set of latent factors — for every user and every item, such that the dot product of a user's and item's factor vectors approximates that user's rating for that item.
The core idea: decomposing the ratings matrix
Imagine the full user-item ratings matrix R, of shape (num_users × num_items), mostly empty because most users haven't rated most items. Matrix factorization approximates R as the product of two much smaller, dense matrices:
R ≈ U × V^T
where U has shape (num_users × k) and V has shape (num_items × k), and k is a small number of latent dimensions — typically somewhere between 20 and 200, far smaller than the number of users or items. Each row of U is a user's latent factor vector; each row of V is an item's latent factor vector. The predicted rating for user i on item j is simply the dot product of their two vectors: U_i · V_j.
These latent dimensions aren't hand-designed — they're learned automatically from the data, and they often end up correlating with interpretable concepts (one dimension might capture "how much blockbuster action vs. arthouse drama," another might capture "serious vs. comedic tone") even though nobody told the model to look for those axes.
Note
How the factors are learned
Training minimizes the squared error between predicted and actual ratings, over only the observed entries, with regularization terms to keep the factor vectors from growing unboundedly (which would just memorize the training ratings and generalize poorly):
minimize: Σ (r_ij − U_i · V_j)² + λ(||U_i||² + ||V_j||²)
Two common optimization strategies:
Stochastic gradient descent (SGD) — iterate through observed ratings one at a time, nudging the relevant user and item vectors slightly closer to predicting that rating correctly.
Alternating Least Squares (ALS) — fix U, solve exactly for the optimal V via least squares; then fix V, solve exactly for U; repeat. ALS parallelizes beautifully across distributed systems (it's the backbone of Spark's recommendation module) because each user's or item's row can be solved independently given the other matrix is held fixed.
Neighborhood collaborative filtering vs. matrix factorization
| Dimension | Neighborhood CF (user/item-based) | Matrix factorization |
|---|---|---|
| What's compared | Raw rating vectors directly | Learned latent factor vectors |
| Handles sparsity | Poorly — similarity is noisy with few overlaps | Well — factors are fit globally across all data |
| Scalability to millions of users | Expensive similarity computations | Compact fixed-size vectors, fast dot products |
| New rating integration | Recompute similarity matrix | Incremental updates to a user's vector |
| Interpretability | High — directly traceable to similar users/items | Lower — latent dimensions are not labeled |
Note
Beyond the basics: biases and implicit feedback
Production-grade factorization models rarely use the bare dot product. A common refinement adds bias terms: predicted rating = global average + user bias + item bias + U_i · V_j, which captures the fact that some users are harsh raters and some items are universally beloved, independent of personalized taste.
For implicit feedback (clicks, watches, purchases — no explicit 1-5 rating), a related technique called Alternating Least Squares for implicit feedback reframes the problem: treat the signal strength as a confidence weight rather than a target to regress against directly, since the absence of an interaction is ambiguous (did the user dislike it, or just never see it?).
What's next
Matrix factorization and collaborative filtering both rely entirely on interaction data — they have nothing to offer a brand-new item with zero ratings. Content-Based Recommender Systems solve that gap by recommending based on item features and similarity instead, and are often combined with collaborative methods in a hybrid system.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.