Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Fix one side, solve the other
Finding user tastes and item properties at the same time is hard. But if you already knew every item’s properties, working out each user’s taste would be a simple fitting problem, the kind with an exact formula, and the same holds the other way round. Alternating least squares exploits this: guess the item properties, solve exactly for all user tastes, then solve exactly for all item properties given those tastes, and repeat. Each round can only improve the fit, and every user (or item) can be solved on a different computer at the same time.
ALS is the factorisation engine behind Spark MLlib’s recommender and many production systems, because it scales across clusters and handles implicit signals (views, clicks, downloads) that most real systems have instead of star ratings. The alternating-exact-solve idea also appears in tensor decompositions, dictionary learning and the expectation–maximisation family.
- 1. ALS alternates between…
- 2. Does ALS need a learning rate?
- 3. ALS parallelises well because…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The half-step solutions by hand
User step. With item factors Q fixed, user u’s objective Σᵢ (rᵤᵢ − pᵤ·qᵢ)² + λ‖pᵤ‖² over the items they rated is ridge regression with design matrix Q_Ω (the rated items’ rows):
pᵤ = (Q_Ωᵀ Q_Ω + λI)⁻¹ Q_Ωᵀ rᵤ.
The item step is symmetric. Each half-step solves one small k × k system per user (or item): 800 solves per sweep for 600 users and 200 items.
Monotone descent. Each half-step finds the exact minimum over one block of variables with the other fixed, so the objective cannot increase. It converges to a stationary point, not necessarily the global optimum.
Implicit feedback (Hu, Koren and Volinsky, 2008). From counts cᵤᵢ (plays, clicks):
- preference pᵤᵢ = 1 if cᵤᵢ > 0, else 0;
- confidence wᵤᵢ = 1 + α cᵤᵢ.
Counts 0, 1, 5 with α = 40 give confidences 1, 41, 201. All cells count, including unobserved ones as weak negatives:
min Σ_(all u, i) wᵤᵢ (pᵤᵢ − xᵤ·yᵢ)² + λ(Σ‖xᵤ‖² + Σ‖yᵢ‖²).
The YᵀY trick. xᵤ = (YᵀWᵤY + λI)⁻¹ YᵀWᵤ pᵤ, and YᵀWᵤY = YᵀY + Yᵀ(Wᵤ − I)Y. YᵀY is shared by all users and computed once per sweep; the correction involves only the user’s non-zero items.
The steps in plain English:
- Initialise the factors randomly (small values).
- Repeat: compute YᵀY; solve every user’s k × k system; compute XᵀX; solve every item’s system.
- Stop when the validation metric stops improving (typically 10–20 sweeps).
- Score items for a user by xᵤ·yᵢ, excluding items already consumed; evaluate with ranking metrics such as recall@k.
- 1. With items fixed, each user's factors come from…
- 2. In implicit ALS, an unobserved cell has preference…
- 3. The YᵀY trick makes each user solve cost scale with…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.ALS or SGD?
Explicit ratings. SGD and ALS optimise the same objective. SGD is simpler, uses less memory per step and handles extensions (time, implicit terms) flexibly; ALS needs no learning rate, converges in fewer sweeps and distributes easily.
Implicit feedback. The objective covers every cell of the matrix, all m·n of them, so SGD over all cells is impractical, while ALS with the YᵀY trick costs about O((m + n)k³ + nnz·k²) per sweep. That is why ALS dominates for implicit data.
α and λ. α sets how much more an observed interaction counts than an unobserved one. Larger α trusts the positives more but scales the loss, so it needs larger λ to avoid overfitting. They must be tuned together.
Exercise 1 (explicit ALS, k = 5, λ = 5, on the 600 × 200 ratings):
- the objective fell monotonically from 9532 to 7469 over 15 sweeps;
- held-out RMSE was 0.841. This version has no explicit bias terms, which Funk SVD included.
from pyspark.ml.recommendation import ALS
als = ALS(rank=10, regParam=0.1, implicitPrefs=True, alpha=40.0, userCol="user", itemCol="item", ratingCol="count")
# Python: implicit.als.AlternatingLeastSquares(factors=10, regularization=0.1, alpha=40)- 1. Why is SGD impractical for implicit ALS's objective?
- 2. Increasing α typically requires…
- 3. ALS converges to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Block coordinate descent. ALS is exact block coordinate descent on a biconvex objective: convex in P for fixed Q and in Q for fixed P. With strictly convex blocks (λ > 0), every limit point is a stationary point. Its convergence can stall in “swamps” where the factors rotate slowly, but in practice a few sweeps suffice.
Implicit ALS as weighted MF. The confidence-weighted squared loss treats every unobserved cell as a negative with weight 1. That is a strong assumption, since “not seen” is not “disliked”. Alternatives include sampling negatives (BPR, Rendle et al., 2009, which optimises pairwise rankings), down-weighting unobserved cells by popularity (eALS), and treating exposure explicitly.
Complexity. Per sweep the cost is O(nnz·k² + (m + n)k³) with the trick. Conjugate-gradient inner solves reduce the k³ term, which matters for large k. Distributed versions partition users and items into blocks and broadcast the small k × k Gram matrices.
Interview questions.
- How do you evaluate an implicit recommender? With ranking metrics on held-out interactions (recall@k, NDCG@k, MAP) against popularity and item-similarity baselines, ideally with a time-based split. RMSE on implicit “ratings” is meaningless.
- Why can’t you just use explicit MF on implicit data? Explicit MF fits only observed cells, which are all positives, so it learns that everyone likes everything. The negatives, the unobserved cells, must be in the objective, as in implicit ALS or BPR.
- 1. ALS is an instance of…
- 2. BPR optimises…
- 3. Explicit MF fitted to implicit positives only tends to…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Tuning implicit ALS
History.
- Y. Hu, Y. Koren and C. Volinsky (2008) introduced implicit-feedback ALS.
- Y. Zhou, D. Wilkinson, R. Schreiber and R. Pan (2008) introduced large-scale parallel ALS for the Netflix Prize.
- S. Rendle et al. (2009) introduced BPR.
- X. He et al. (2016) introduced eALS with popularity-aware weights.
- ALS became the Spark MLlib recommender.
Exercise 2. Play counts from a latent Poisson model, 500 users × 300 items with 6.3% non-zero. 20% of positive cells were held out; recommendations exclude items already played. The table gives recall@10.
Baselines: popularity 0.208; item-cosine neighbourhood 0.266.
| implicit ALS (k = 8) | λ = 1 | λ = 10 | λ = 50 |
|---|---|---|---|
| α = 1 | 0.259 | 0.271 | 0.200 |
| α = 10 | 0.263 | 0.268 | 0.292 |
| α = 40 | 0.177 | 0.196 | 0.264 |
- Tuned implicit ALS was best (0.292), 40% better than popularity and 10% better than item cosine.
- α and λ interact. α = 40 with small λ was the worst setting, below popularity (0.177): it overfitted the confidently observed cells. The same α with λ = 50 recovered to 0.264.
- Large λ with small α underfitted (α = 1, λ = 50: 0.200).
- The popular default α = 40 is not universal: here α = 10 worked better. Tune α, λ and k jointly on a time-held-out validation set.
ALS in AI, robotics and aerospace
- Usage-based recommendation at scale: documents, dashboards or datasets recommended from access logs with Spark ALS.
- Implicit signals in operations: which procedures, tools or data products are used together, from logs rather than ratings.
- Tensor and matrix completion: alternating exact solves for sensor-network completion and multi-way telemetry decompositions.
References
- Y. Hu, Y. Koren, C. Volinsky (2008). “Collaborative filtering for implicit feedback datasets.” Proc. IEEE ICDM.
- Y. Zhou, D. Wilkinson, R. Schreiber, R. Pan (2008). “Large-scale parallel collaborative filtering for the Netflix Prize.” Proc. AAIM.
- S. Rendle, C. Freudenthaler, Z. Gantner, L. Schmidt-Thieme (2009). “BPR: Bayesian personalized ranking from implicit feedback.” Proc. UAI.
- X. He, H. Zhang, M.-Y. Kan, T.-S. Chua (2016). “Fast matrix factorization for online recommendation with implicit feedback.” Proc. ACM SIGIR.