User-User Collaborative Filtering
User-User Collaborative Filtering (also called user-based CF or k-Nearest-Neighbour user CF) is the original automated form of Collaborative Filtering. The algorithm predicts what a target user
uwill think of an itemiby finding the users in the system most similar toubased on their past interactions, looking up how those taste neighbours ratedi, and aggregating those neighbour ratings into a single prediction foru. The mental model is intuitive — it is the algorithmic version of “what does the friend with similar taste think of this?” — and it was the first collaborative-filtering algorithm to ship in a deployed system, the GroupLens Usenet recommender at the University of Minnesota in 1994. User-user CF is conceptually clean and easy to explain, but it does not scale to large user bases, which is why production systems migrated to Item-Item Collaborative Filtering in the early 2000s. Understanding user-user CF is still important because (a) it remains a valid choice for small-to-medium datasets, (b) it is the conceptual ancestor of every later collaborative method, and (c) modern neural retrieval methods like the Two-Tower Retrieval Model are essentially scalable user-user CF reimagined.
1. Origin and Historical Significance — The 1994 GroupLens Paper
User-user collaborative filtering was introduced by Paul Resnick, Neophytos Iacovou, Mitesh Suchak, Peter Bergstrom and John Riedl at the University of Minnesota in their 1994 paper “GroupLens: An Open Architecture for Collaborative Filtering of Netnews”, published at the ACM Computer Supported Cooperative Work (CSCW) conference. The paper’s stated motivation: Usenet news had become unmanageably high-volume by the early 1990s, and existing keyword-filtering tools could only filter on text content, not on whether other readers had found a message useful. The authors proposed a Better Bit Bureau — a server that gathered ratings from readers and predicted, for any (reader, message) pair, what the reader’s rating of that message would be, based on the heuristic that “people who agreed in the past will probably agree again.”
The technical architecture: each reader rates messages on a scale (the prototype used 1 to 5). Rating servers compute, for each pair of users (u, v) who have rated some messages in common, a Pearson correlation coefficient between their ratings on the co-rated messages — a number in [−1, 1] that captures how aligned their tastes are. To predict u’s rating on a message m they have not seen, the server finds users similar to u who have rated m, and computes a weighted average of those users’ ratings (after mean-centering — see §3 for the exact formula). The 1994 paper was the first published demonstration of this algorithmic pattern, and almost every memory-based collaborative-filtering algorithm in the subsequent thirty years descends directly from it.
GroupLens later evolved into MovieLens (1997 onward), which is still operating and which has produced the standard public benchmark dataset for collaborative-filtering research. The MovieLens datasets (100K, 1M, 10M, 20M, 25M, and 32M variants) are downloaded thousands of times per year by researchers and constitute the most-used recommendation evaluation corpus in academic literature.
The historical significance of user-user CF is therefore twofold. First, it operationalized the abstract idea of collaborative filtering — taking it from a hand-wavy concept to a working algorithm with concrete mathematical underpinnings. Second, it produced the dataset that became the field’s de facto benchmark, which constrained subsequent research to focus on the algorithmic class GroupLens introduced. Item-item CF, matrix factorization, and neural CF are all responses to the limits of GroupLens-style user-user CF.
2. The Core Algorithm
The procedure to predict user u’s preference for item i, in three steps:
flowchart LR U[Target user u] --> Sim[Compute similarity<br/>to every other user] Sim --> Top[Select top-k neighbours<br/>who have rated i] Top --> Agg[Weighted average of<br/>their ratings on i] Agg --> P[Predicted rating r̂_u,i]
What this diagram shows. The leftmost node is the target user u for whom we are making a prediction. The first arrow goes to a similarity computation step that compares u’s rating history to every other user’s rating history and produces a similarity score for each pair (u, v). The second step selects the top-k most-similar users who have rated the target item i (users who have not rated i carry no signal for this prediction). The third step computes a weighted average of those neighbours’ ratings on i, weighted by similarity. The output is the predicted rating r̂_{u,i}. The key insight from this diagram is that the algorithm operates entirely at prediction time — there is no separate training phase. The matrix R is the model. This is what makes user-user CF a memory-based method.
2.1 Step 1 — Compute user-user similarity
For every pair of users (u, v), compute a similarity score sim(u, v) ∈ ℝ based on the items they have both rated. The choice of similarity measure is consequential and is discussed in §3.
In practice, full pairwise computation across all user pairs is O(m²) where m is the number of users; for any system with more than a few hundred thousand users this is infeasible at request time, and the similarities are precomputed and cached. See §6 for the scalability discussion.
2.2 Step 2 — Select neighbourhood
For the prediction at hand, restrict to users who satisfy two conditions:
sim(u, v)is high (above a threshold or in the top-k).- User
vhas actually rated itemi(otherwise they contribute no signal for this prediction).
Typical choices: take the top 20 to 50 users meeting both conditions. Larger neighbourhoods dilute the signal with less-similar users; smaller neighbourhoods are unstable because individual neighbours’ ratings dominate.
2.3 Step 3 — Aggregate
Compute the predicted rating r̂_{u,i} as a weighted average of the neighbours’ ratings on i. The classic formula, mean-centered to handle per-user rating scale differences:
r̂_{u,i} = r̄_u + (Σ_{v ∈ N(u)} sim(u, v) · (r_{v,i} − r̄_v)) / (Σ_{v ∈ N(u)} |sim(u, v)|)
where:
r̂_{u,i}is the predicted rating for useruon itemi.r̄_uis the mean rating that userugives across all items they have rated (their personal baseline).N(u)is the neighbourhood selected in Step 2 — the top-k similar users who have ratedi.sim(u, v)is the similarity between usersuandvfrom Step 1.r_{v,i}is the rating uservgave to itemi(an observed value).r̄_vis the mean rating that uservgives across all items they have rated.(r_{v,i} − r̄_v)isv’s rating onirelative tov’s personal baseline. This mean-centering is what removes per-user rating-scale bias.- The denominator
|sim(u, v)|(absolute value) handles negative similarities (anti-correlated users); their evidence is informative even though it is “evidence the other way.” - The outer addition of
r̄_ure-addsu’s personal baseline so the prediction is onu’s scale.
The mean-centering step is essential and is the most commonly omitted detail in textbook treatments. To see why: suppose user u rates everything 4–5 stars (a “generous rater”) and user v rates everything 1–2 stars (a “strict rater”). If they like the same items, their centered ratings will agree (each rates their favourites high relative to their personal baseline), but their raw ratings will disagree by a constant offset. Without mean-centering, the prediction is contaminated by the offset. With mean-centering, the offset cancels out and the prediction reflects only the signal.
3. Similarity Measures — Mathematical Definitions
Four standard similarity measures, each with the precise formula and the situation it suits.
3.1 Pearson correlation coefficient
The textbook default for explicit-rating data:
sim_Pearson(u, v) = Σ_{i ∈ I_{u,v}} (r_{u,i} − r̄_u) · (r_{v,i} − r̄_v)
─────────────────────────────────────────────────────
√Σ_{i ∈ I_{u,v}} (r_{u,i} − r̄_u)² · √Σ_{i ∈ I_{u,v}} (r_{v,i} − r̄_v)²
where:
I_{u,v}is the set of items both users have rated (the co-rated set). The summations are over this set only.r̄_u, r̄_vare the mean ratings of usersuandv(computed over their entire rating histories, not justI_{u,v}).- The numerator is the sample covariance of their centered ratings on co-rated items.
- The denominators are the standard deviations.
- The result lies in
[−1, 1]. Value 1 means perfect positive correlation (their centered ratings move in lockstep); value 0 means uncorrelated; value −1 means perfectly anti-correlated.
Pearson is appropriate for explicit ratings because (a) ratings are continuous-ish and roughly Gaussian, (b) it implicitly accounts for rating-scale differences via the centering, and (c) the correlation interpretation is intuitive.
3.2 Cosine similarity
sim_cos(u, v) = (r_u · r_v) / (‖r_u‖ · ‖r_v‖)
where:
r_uandr_vare the rating vectors of the two users, treated as vectors in ℝ^n wherenis the catalog size (with zeros for unrated items, though see §3.5 for why this is wrong in many settings).r_u · r_v = Σ_i r_{u,i} · r_{v,i}is the dot product.‖r_u‖ = √(r_u · r_u)is the L2 (Euclidean) norm.- The result is in
[−1, 1]for general vectors, in[0, 1]for non-negative vectors.
Cosine measures the angle between rating vectors and is faster than Pearson because it does not require the per-user mean computation. It does not, however, account for per-user rating scale. Two users with the same ratings on the same items will have cosine 1.0; two users with the same relative preferences but different scales will have cosine less than 1.0 (because their absolute ratings differ).
3.3 Adjusted cosine similarity
The compromise: cosine after subtracting per-user means.
sim_adj_cos(u, v) = Σ_{i ∈ I_{u,v}} (r_{u,i} − r̄_u)(r_{v,i} − r̄_v)
─────────────────────────────────────────────────────
√Σ_i (r_{u,i} − r̄_u)² · √Σ_i (r_{v,i} − r̄_v)²
This is structurally similar to Pearson. The difference is in the normalization in the denominator: Pearson uses standard deviations computed over only the co-rated items; adjusted cosine uses standard deviations over each user’s entire rating history. The two can differ for users whose rating distribution differs between their co-rated items and their full history.
3.4 Jaccard similarity
For binary or set-based interaction data (which user clicked which item, ignoring magnitude or rating):
sim_Jaccard(u, v) = |I_u ∩ I_v| / |I_u ∪ I_v|
where:
I_uis the set of items useruhas interacted with (a binary set, ignoring rating).|I_u ∩ I_v|is the number of items both have touched.|I_u ∪ I_v|is the number of items either has touched.- The result is in
[0, 1].
Jaccard is the natural similarity for click-streams and other implicit binary signals, where the question “did the user touch the item or not” is the only signal available. It does not generalize to rated data.
3.5 Choosing among them — practical rule
- Explicit ratings: Pearson is the textbook default.
- Implicit binary signals (clicks, follows): Jaccard or cosine on the binary indicators.
- Implicit count signals (play counts, watch durations): cosine or adjusted cosine on count vectors, ideally after a log-transform to dampen heavy-tailed counts.
- Mixed signals: consider switching to a model-based approach (Matrix Factorization) where the loss function rather than the similarity measure handles the mixing.
A common pitfall worth flagging here: do not use Pearson on binary implicit data. Pearson assumes the data is roughly Gaussian; on a binary {0, 1} matrix, “mean rating” is just the user’s interaction rate, and the math becomes degenerate.
4. A Worked Numerical Example
Three users, three movies, with ratings on a 1-to-5-star scale. Predict Alice’s rating on The Matrix.
| User | Inception | Interstellar | The Matrix |
|---|---|---|---|
| Alice | 5 | 5 | ? |
| Bob | 5 | 4 | 5 |
| Carol | 1 | 2 | 1 |
Step 1 — Pearson similarities, computed over the co-rated set {Inception, Interstellar}.
Alice’s ratings on the co-rated set: [5, 5]; her mean over this set is 5. Bob’s ratings: [5, 4]; mean over this set is 4.5. Carol’s ratings: [1, 2]; mean over this set is 1.5.
Pearson correlation between Alice and Bob:
numerator = (5 − 5)(5 − 4.5) + (5 − 5)(4 − 4.5) = 0 · 0.5 + 0 · (−0.5) = 0
denominator = √((5−5)² + (5−5)²) · √((5−4.5)² + (4−4.5)²) = √0 · √0.5 = 0
Pearson is undefined (zero in the numerator AND denominator) because Alice’s centered ratings are all zero — she rated both items the same. This is a real limit of Pearson: when one user’s ratings have zero variance over the co-rated set, the correlation is undefined.
This illustrates a structural issue with raw Pearson on small co-rated sets. Production implementations either (a) require a minimum number of co-rated items with non-trivial variance before computing similarity, (b) fall back to cosine similarity in the degenerate case, or (c) use a smoothed estimator that biases toward zero for small samples (a form of shrinkage; see Item-Item Collaborative Filtering §6 for the corresponding shrinkage formula in the item-similarity setting).
Step 1 (revised) — cosine similarities (the simpler measure, well-defined here).
Cosine between Alice ([5, 5]) and Bob ([5, 4]):
sim(Alice, Bob) = (5·5 + 5·4) / (√(5² + 5²) · √(5² + 4²))
= (25 + 20) / (√50 · √41)
= 45 / (7.07 · 6.40)
= 45 / 45.27 ≈ 0.994
Cosine between Alice ([5, 5]) and Carol ([1, 2]):
sim(Alice, Carol) = (5·1 + 5·2) / (√50 · √(1 + 4))
= (5 + 10) / (7.07 · 2.24)
= 15 / 15.84 ≈ 0.947
Both similarities are very high — and they shouldn’t be! Alice and Bob clearly track each other (both gave high ratings); Alice and Carol clearly disagree (Alice gave 5s, Carol gave 1s). The high cosine between Alice and Carol is an artifact of cosine ignoring magnitude. It treats [5, 5] and [1, 2] as “both pointing roughly into the upper-right quadrant” and rates them similar.
This worked example shows the failure mode of plain cosine on rating data: it confounds direction and magnitude. The fix in the production literature is to use Pearson (when the co-rated set is large enough to have variance) or adjusted cosine. For pedagogical simplicity, however, let’s continue with cosine and see what prediction we get.
Step 3 — Aggregate (using both Bob and Carol as neighbours since both rated The Matrix).
Compute the means of Bob and Carol over their full rating histories:
- Bob: (5 + 4 + 5) / 3 = 4.667
- Carol: (1 + 2 + 1) / 3 = 1.333
Compute their centered ratings on The Matrix:
- Bob: 5 − 4.667 = +0.333
- Carol: 1 − 1.333 = −0.333
Alice’s mean rating: (5 + 5) / 2 = 5.0.
Apply the prediction formula:
numerator = sim(Alice, Bob) · 0.333 + sim(Alice, Carol) · (−0.333)
= 0.994 · 0.333 + 0.947 · (−0.333)
= 0.331 − 0.315
= 0.016
denominator = |0.994| + |0.947| = 1.941
predicted offset = 0.016 / 1.941 ≈ 0.008
prediction = 5.0 + 0.008 ≈ 5.0
So the prediction is essentially Alice’s personal mean of 5.0. The prediction is reasonable — Alice rates everything 5 — but the path to it is not informative. Cosine treated Bob and Carol as similarly trustworthy, even though they should weight very differently. The lesson: when using cosine on rating data, you should mean-center first (i.e., use adjusted cosine), or use Pearson and require minimum co-rated set variance, or move to a model-based method. Plain cosine on rating data is a beginner’s trap.
5. The Stable Prediction Formula in Production
The formula in §2.3 is the textbook form, and it is what the GroupLens 1994 paper used. In production, several refinements are standard:
Significance weighting. Down-weight similarities computed from very few co-ratings:
sim_significant(u, v) = sim(u, v) · min(|I_{u,v}|, β) / β
where β is a threshold (e.g., 50) above which full weight is given. A pair of users with three co-ratings and apparent similarity 1.0 is much less reliable than a pair with 100 co-ratings and similarity 0.8, and significance weighting captures this.
Top-k filtering. Use only the top k neighbours by similarity, not all users with positive similarity. Typical k is 20 to 50 for medium datasets.
Shrinkage toward the global mean. When a user has very few ratings, fall back to a global average. Rather than predicting Alice’s rating on item i as a pure neighbourhood-weighted average, use:
r̂_{u,i} = (n_u / (n_u + λ)) · r̂_{u,i}^{neighbour} + (λ / (n_u + λ)) · μ
where n_u is the number of ratings Alice has given, μ is the global mean rating, and λ is a smoothing constant. New users get pulled toward μ; established users get their neighbour-derived prediction.
Time decay. Recent co-ratings carry more weight than older ones. Multiply each contribution by an exponential decay e^{−γ · age} where γ is a decay rate.
These refinements are all known and discussed in textbooks (Aggarwal 2016, Recommender Systems: The Textbook) but are often left out of pedagogical treatments.
6. Scalability — Why User-User Was Largely Replaced
The user-user similarity matrix is m × m where m is the number of users. Two structural problems make this infeasible at large scale:
Compute. Computing all pairwise similarities is O(m² · n_avg) where n_avg is the average number of items per user. For a system with 10⁵ users and 10² items per user on average, that is 10¹² operations — feasible offline but only just. For a system with 10⁸ users (Amazon’s scale by 2003), that is 10¹⁸ operations — structurally impossible. Approximate methods (Locality-Sensitive Hashing, LSH; or learned embeddings) can make this tractable, but at that point you are essentially building a two-tower retrieval model.
Stability. User taste drifts on the time-scale of weeks or months. The user-similarity matrix needs to be recomputed frequently to stay current, which compounds the compute problem. By contrast, items themselves do not change; an item-similarity matrix is much more stable and can be refreshed less often. This stability advantage is one of the reasons Linden et al. 2003 chose Item-Item Collaborative Filtering over user-user when they re-architected Amazon’s recommender.
The combination of compute infeasibility and stability disadvantage made user-user CF a non-starter for any system with more than about 10⁵ users by the early 2000s. The replacements:
- Item-item CF (Linden, Smith & York 2003) — flips the algorithm to use item-similarity, which has both the smaller similarity matrix (catalog tends to be smaller than user base) and the better stability. See Item-Item Collaborative Filtering.
- Matrix factorization (Funk SVD 2006, Koren et al. 2009) — replaces the explicit similarity matrix with a learned low-rank representation. See Matrix Factorization.
- Neural retrieval (Two-Tower Retrieval Model) — the modern reimagining of user-user CF as a learned-embedding nearest-neighbour problem with an Approximate Nearest Neighbor (ANN) index. The user tower learns a vector representation of each user; the item tower learns a vector representation of each item; the dot product is the score. The “find similar users” step is replaced with “look up the user’s vector in an ANN index” — efficient at billion-item scale.
7. When User-User Is Still the Right Choice
User-user CF remains a defensible choice in three settings:
Small-to-medium datasets (up to ~10⁵ users). The full user-similarity matrix is computable; the stability issue is manageable; the algorithm is simple to implement and easy to debug.
Explainability is paramount. “We recommended this because three other users similar to you liked it” is an explanation a user can grasp. Black-box matrix factorization or deep models cannot offer this.
Cold-start adaptation. With a single new rating, a user’s similarity to others can be recomputed instantly, so the recommendations adapt immediately. Matrix factorization methods often need a re-fit (or an approximate online update) to react to new ratings.
For all other production-scale settings, item-item CF or model-based methods are strictly preferable.
8. Pitfalls and Misconceptions
“Similar users always agree.” Coincidental overlap on a small number of items does not mean shared taste. Require a minimum number of co-rated items (typically 5 to 10) before computing similarity, and apply significance weighting.
Forgetting to mean-center. Without it, neighbours who rate everything high will dominate the prediction simply because their raw ratings are larger numbers. Always normalize per-user.
Using all neighbours instead of top-k. Aggregating over hundreds of weak neighbours dilutes the signal. Pick k = 20 to k = 50.
Pearson on implicit binary data. Pearson correlation assumes continuous, roughly Gaussian ratings. On binary {0, 1} click data, Pearson degenerates. Use Jaccard or cosine on the binary indicator vectors.
Treating user-user as scalable. It isn’t. Accept this and move to item-item, matrix factorization, or two-tower retrieval once the user base exceeds about 10⁵.
Ignoring the cold-user case. A new user with one rating has no meaningful neighbourhood (similarity to others is computed from one data point). Production systems either fall back to popularity for cold users or use an onboarding questionnaire to bootstrap a profile.
Confusing user-similarity with user-clustering. User-user CF computes pairwise similarities and uses the top-k for prediction — it does not cluster users. Some textbooks blur this; the algorithms are different (clustering would group users into groups; user-user CF leaves them as a continuous space of similarities).
9. Open Questions
- Are there modern setups where user-user beats item-item? Possibly when user-side features are rich and items are commoditized (very-similar SKUs, e.g., low-end electronics where every item is functionally a substitute). Even there, modern model-based approaches usually win.
- Hybrid user-user and matrix-factorization. Some research (Koren 2008’s SVD++) effectively combines neighbourhood and factor models. It is not common in production but remains an active research thread.
10. See Also
- Collaborative Filtering — the parent paradigm
- Item-Item Collaborative Filtering — the dual approach that replaced user-user at scale
- Matrix Factorization — the model-based replacement that addresses both scalability and sparsity
- Two-Tower Retrieval Model — the modern feature-driven reimagining at industrial scale
- Building a Simple Recommender — the staged code progression discusses user-user CF as one of the early stages
- Explicit vs Implicit Feedback — drives the choice between Pearson and Jaccard/cosine
- Recommender Systems MOC