Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Ask people with the same taste
When choosing a film, you might ask a friend whose taste matches yours: if they loved it, you probably will too. User-based collaborative filtering automates this. It finds the users whose past ratings agree most with yours, then predicts your rating for a new item from how those look-alikes rated it. It never needs to know what the item is about, only who liked what.
Collaborative signals appear wherever many people interact with many items: technicians choosing procedures, analysts opening dashboards, pilots selecting routes, engineers reusing test cases. User-based CF is the clearest way to understand how “people like you” recommendations work, and why they struggle when data are sparse.
- 1. User-based CF predicts from…
- 2. Does it need item features?
- 3. A typical ratings matrix is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Similarity and prediction by hand
Mean-centring. Users use the scale differently: one gives 4s and 5s, another 2s and 3s. Subtract each user’s mean rating: r̃ᵤᵢ = rᵤᵢ − r̄ᵤ.
Pearson similarity over the co-rated items Iᵤᵥ:
s(u, v) = Σᵢ r̃ᵤᵢ r̃ᵥᵢ / (√Σᵢ r̃ᵤᵢ² · √Σᵢ r̃ᵥᵢ²).
User u rates a, b, c as 5, 3, 4 (mean 4), and v rates a, b, c, d as 4, 2, 3, 5 (mean 3.5). The deviations on a, b, c are (1, −1, 0) and (0.5, −1.5, −0.5), so s = 2/(√2 · √2.75) = 0.853.
Prediction. With the k most similar users v who rated item i:
r̂ᵤᵢ = r̄ᵤ + Σᵥ s(u, v)(rᵥᵢ − r̄ᵥ) / Σᵥ |s(u, v)|.
With r̄ᵤ = 3, neighbours of similarity 0.8 and 0.4 who rated 5 and 2 against their means 4 and 3: 3 + (0.8 · 1 + 0.4 · (−1))/1.2 = 3.33.
Significance weighting. A similarity computed from 2 co-rated items is unreliable. Multiply it by min(n, β)/β: with β = 25 and n = 2, a similarity of 1 becomes 0.08.
Evaluation. Hold out ratings and compute RMSE = √mean(error²) and MAE = mean|error|. Predictions 3, 4, 5 for true 3, 5, 3 give RMSE √(5/3) = 1.29 and MAE 1. Always compare with baselines: the global mean, the user mean, and μ + bᵤ + bᵢ.
- 1. Mean-centring removes…
- 2. Pearson similarity is computed over…
- 3. Significance weighting shrinks similarities based on…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Sparsity, baselines and neighbourhoods
Sparsity. If each user rates 5% of items independently, two users share only about 0.05² of the catalogue: 1 item in 400. Popular items concentrate ratings and create overlap, which is why real data work at all. Similarities based on 1–3 items are mostly noise.
Baselines first. A large part of rating variance is user and item bias: harsh users, good films. The baseline r̂ = μ + bᵤ + bᵢ, with shrunken biases, often beats naive neighbourhood methods. A fair test of CF is whether it improves on that baseline.
Neighbourhood size.
- Small k uses only the closest users, but is noisy.
- Large k includes weakly similar users and drifts toward the user mean.
- Typical good values are 20–50.
- Requiring a minimum overlap or a minimum similarity helps.
Exercise 1 (300 users × 400 items, 10.3% observed, with popular items rated more often; 2547 held-out ratings). RMSE:
- global mean 1.069;
- user mean 1.031;
- baseline μ + bᵤ + bᵢ 0.950;
- user-based k-NN (k = 20, Pearson, significance weighting) 0.847.
from surprise import KNNWithMeans, Dataset, accuracy # scikit-surprise
algo = KNNWithMeans(k=20, sim_options={"name": "pearson", "user_based": True, "min_support": 3})- 1. With 5% independent density, two users share about … of the items.
- 2. A fair test of collaborative filtering is improvement over…
- 3. Very large k makes predictions drift toward…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why Pearson and not raw cosine? Cosine similarity on raw ratings, all positive, treats any two users who rate the same items as similar, mostly measuring overlap. Mean-centring (Pearson, or “adjusted cosine”) measures agreement in deviations, that is, taste.
Scalability. All user–user similarities cost O(m² n) with dense operations, or about O(Σᵢ nᵢ²) with sparse ones, where nᵢ is the number of ratings of item i. That grows badly with users, and user neighbourhoods change as users rate more. Item-based CF (the next topic) precomputes item–item similarities, which are more stable.
Cold start and bias. New users have no neighbours. Popular items are over-recommended, since they dominate overlaps. Ratings are missing not at random: users rate what they chose to consume, which biases offline evaluation.
Interview questions.
- Why might user-based CF fail on your data? Too sparse: few co-rated items per pair, so noisy similarities. Too many users to compute neighbourhoods. Many new users. Use item-based CF, matrix factorisation or hybrids.
- How do you evaluate a recommender offline? Hold out ratings, preferably by time, and report RMSE or ranking metrics against bias baselines. Beware missing-not-at-random effects; validate online with A/B tests when possible.
- 1. Raw cosine on ratings mostly measures…
- 2. Ratings are typically missing…
- 3. User–user similarity computation scales roughly with…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.When do neighbours help?
History.
- D. Goldberg et al. (1992) introduced collaborative filtering (Tapestry).
- P. Resnick et al. (1994) introduced GroupLens and the Pearson-based prediction formula.
- J. Herlocker, J. Konstan, A. Borchers and J. Riedl (1999) introduced significance weighting and neighbourhood design.
- Y. Koren (2008, 2010) integrated baselines and neighbourhood models for the Netflix Prize.
Exercise 2. The same simulation at two densities, 6% and 15%. Each cell gives the held-out RMSE without, then with, significance weighting (β = 25).
| density | similarity | k = 5 | k = 20 | k = 100 |
|---|---|---|---|---|
| 6% (baseline 0.926) | Pearson | 0.966, 0.938 | 0.944, 0.924 | 0.958, 0.946 |
| raw cosine | 0.968, 1.001 | 0.944, 0.958 | 0.943, 0.955 | |
| 15% (baseline 0.928) | Pearson | 0.838, 0.825 | 0.811, 0.810 | 0.839, 0.836 |
| raw cosine | 0.873, 0.974 | 0.856, 0.932 | 0.905, 0.926 |
- At 6% density, user-based CF could not beat the bias baseline: its best RMSE was 0.924 against 0.926. With so few co-rated items, similarities were too noisy to add information.
- At 15% density it was clearly useful: 0.810 against 0.928, a 13% reduction.
- k = 20 was best; k = 5 was noisy, and k = 100 diluted the signal with weak neighbours.
- Significance weighting helped Pearson, most with few neighbours (0.966 → 0.938 at k = 5, 6%). It hurt raw cosine, whose uncentred similarities mostly reflect overlap.
- Mean-centred Pearson beat raw cosine everywhere at 15%. Removing each user’s rating level is essential.
User-based CF in AI, robotics and aerospace
- Procedure and document recommendation: technicians with similar job histories tend to need similar documents.
- Analyst tooling: recommending dashboards, queries or datasets used by colleagues with overlapping work.
- Crew and route preferences: suggesting options favoured by similar operators, with care for sparsity and bias.
References
- P. Resnick, N. Iacovou, M. Suchak, P. Bergstrom, J. Riedl (1994). “GroupLens: an open architecture for collaborative filtering of netnews.” Proc. ACM CSCW.
- J. L. Herlocker, J. A. Konstan, A. Borchers, J. Riedl (1999). “An algorithmic framework for performing collaborative filtering.” Proc. ACM SIGIR.
- Y. Koren (2010). “Factor in the neighbors: scalable and accurate collaborative filtering.” ACM Transactions on Knowledge Discovery from Data 4(1).
- B. Marlin, R. Zemel (2009). “Collaborative prediction and ranking with non-random missing data.” Proc. ACM RecSys.