Collaborative Filtering (Neighborhood)
Throw the item descriptions away and listen to behaviour: people who agreed in the past will agree in the future. The only input is the URM — and it reuses the exact cosine + KNN machinery from content-based filtering, pointed at the rating matrix. User-based vs item-based, Pearson, and memory vs model.
01 · Let behaviour speak
The collaborative idea
No attributes. No descriptions. Just the matrix of who rated what.
Content-based filtering needed someone to build the ICM. Collaborative filtering needs none of that — its premise is purely behavioural: users who agreed in the past tend to agree in the future. If Alice and Bob rated the same films almost identically, a film Bob loved but Alice hasn’t seen is a strong recommendation for Alice — regardless of what that film is about. The single input is the URM. There are two ways to read it: user-based (compare rows) and item-based (compare columns).
Content-Based (Ch. 4)
Collaborative (Ch. 5)
The cold-start flip side
Because CF only knows an item through its ratings, a brand-new item with zero ratings is invisible — the exact case content-based handled effortlessly. This is why real systems hybridise the two (Ch. 9).
02 · Compare the rows
User-based collaborative filtering
Find your nearest neighbours among users; borrow their ratings.
Two users are similar if their rating rows point the same way. For implicit data (1/0) the dot product counts items both interacted with; the cosine similarity normalises it. For explicit ratings we use the same cosine on the values, then add the familiar shrinkage term so a pair with one or two films in common isn’t trusted like a pair with twenty.
User neighbours · who agrees with whom
Similarity between the selected user's rating row and every other. The shrink term h pulls low-overlap pairs toward zero; switch to implicit to compare 0/1 interaction patterns instead.
Once we have user ‘s K nearest neighbours, the predicted rating for an unseen item is a similarity-weighted average of the neighbours’ ratings for that item.
Different users use the scale differently
One user’s “3” is another’s “5”. Plain cosine ignores this. The pearson correlation fixes it by subtracting each user’s average rating before comparing — so it measures whether two users agree about what is above/below their own average, not whether they press the same buttons.
Formal Definition 5.1 — user similarity & prediction
Cosine similarity between users (with shrink ), and the bias-removing Pearson correlation:
Prediction over the K most similar users: .
03 · Compare the columns
Item-based collaborative filtering
Two items are similar if the same people rated them the same way.
Turn the matrix on its side. Two items are similar when the same users rated them similarly — a similarity read straight from the URM columns. The slide’s one-liner captures it: item-based CF is “content-based filtering, but without knowing the attributes.” It produces an item–item similarity matrix just like Chapter 4 — except learned from behaviour, not tags.
Item similarity from behaviour · slide K to sparsify
Item-item cosine from the URM columns. Darker = more similar. This is collaborative filtering discovering structure attributes can't see — similarity from co-ratings, not tags.
Why item-based is usually preferred
There are typically far fewer items than users, and an item’s rating column is more stable over time than a user’s row (tastes drift; a movie’s audience pattern doesn’t). So the item–item matrix is smaller, cheaper, and can be pre-computed once and reused — which makes it a model (§5.5).
Formal Definition 5.2 — item similarity
Cosine over item columns, and adjusted cosine which removes the user bias (subtracted per-user, since the same users span both columns):
The item–item matrix is symmetric with a zero diagonal, then sparsified with KNN — exactly as in Ch. 4.
04 · From similarity to a ranking
Making recommendations
One weighted sum over the K nearest neighbours — and one matrix product.
Both flavours score an unseen item the same way: a similarity-weighted sum over the K nearest neighbours, normalised by the total similarity. In matrix notation the entire prediction is a single product — for user-based (multiply on the left by user similarity) and for item-based (multiply on the right by item similarity).
CF recommender · user-based vs item-based
Only unseen items are scored, by a similarity-weighted average over the K nearest neighbours. Switch method and user — the rankings stay inside each taste cluster.
Formal Definition 5.3 — prediction & matrix form
Item-based prediction, and the bias-aware user-based form (predict the delta from the user’s mean, then add it back):
Matrix form: (user-based) and (item-based).
05 · A unifying view
Memory-based vs model-based
The same two-step skeleton that organises every recommender in the course.
Every recommender is two steps: build a model from the data, then score with that model and a user profile — or , then . The distinction is whether the user’s profile is baked into the model:
- Memory-based — the user profile is part of the URM the model was built from. User-based CF is the archetype: to score Alice you re-scan the stored rows. You can only recommend to users already in the model.
- Model-based — the profile is not needed to build the model. Item-based CF learns once; then works for any profile — even a brand-new user who wasn’t in the training URM.
The killer feature of item-based CF
Because the item–item similarity doesn’t depend on any particular user, you can serve a user who just signed up the moment they rate a couple of items — no retraining. User-based CF cannot: the new user wasn’t one of the rows. Everything from SLIM (Ch. 6) to Matrix Factorization (Ch. 8) is a smarter way to learn that model.
06 · Exam intel
What the exam tests
Distinguish user-based vs item-based CF; compute a user–user (or item–item) cosine from the URM; explain why Pearson / adjusted cosine remove bias; and classify a method as memory- vs model-based.
Worked question — cosine between two users (implicit and explicit)
From the URM, compute the cosine similarity between Alice = [5,4,5,4,0,0,4,0] and
Bob = [4,5,4,0,0,1,5,0].
- Implicit — binarise: Alice =
[1,1,1,1,0,0,1,0], Bob =[1,1,1,0,0,1,1,0]. Co-rated dot = 4 (TopGun, MI, Inter, Avengers); each has 5 ones. . - Explicit — dot ; , ; .
Both confirm Alice and Bob sit in the same action/sci-fi cluster. Traps: saying CF “needs item attributes” (that’s content-based); calling user-based CF model-based (it is memory-based); forgetting the zero diagonal of .
07 · Exam · past papers
Past-paper questions
Past paper Exam 2020 · 7 pts — user-based CF end to end
Q. Idea + predictions with/without user bias; cosine; Pearson (when/why); implicit Top-N simplification; the shrink term; KNN.
Model answer. Predict from users similar to . Without bias: ; with bias: ; matrix form . Cosine . Pearson subtracts each mean (use on explicit data when users use the scale differently). Implicit + Top-N: ranking only needs the order, so drop the denominator and bias → (). Shrink down-weights similarities from few co-ratings. KNN keeps each user’s top-K neighbours (inverted-U quality curve).
Past paper RS Exam · 8 pts — similarity measures compared
Q. Basic idea; different approaches to measure user similarity (advantages, disadvantages, peculiarities); how to estimate ratings; user-based in matrix notation.
Model answer. Cosine — angle between rating rows; simple, but conflates harsh/generous raters and rewards overlap. Pearson — cosine after subtracting each user’s mean ; corrects rating-scale bias, best for explicit data, but unstable with very few co-ratings. Jaccard / dot-product — for implicit data, count shared interactions; cheap, natural for 0/1, ignores magnitude. All add a shrink term . Estimate: . Matrix: — each predicted row is a similarity-weighted combination of the other rows, so multiplies on the left.
Past paper Practice Exam 1 · user-based vs item-based
Q. Difference between user-based and item-based CF; how cosine is calculated and its role; the similarity matrix in item-based prediction.
Model answer. User-based compares URM rows and recommends what similar users liked (); item-based compares URM columns (). Item-based is usually preferred — fewer, more stable items, and is user-independent so it can be precomputed (a model). Cosine provides the neighbour weights. Item-based: build item-item (cosine over columns, zero diagonal, KNN), then , i.e. .
08 · Self-check
Three questions before you move on
Collaborative filtering computes similarity from:
Item-based CF is called "content-based filtering, but without knowing the attributes." Why?
Item-based CF precomputes S_II = f(URM) once and can then score a brand-new user not in the training data. This makes it:
09 · Recap
One-screen summary
Chapter 05 — load-bearing ideas
- CF = similarity from the URM: rows → user-based, columns → item-based. Same cosine + shrink + KNN machinery as content-based, pointed at behaviour.
- Remove bias for explicit ratings: Pearson (user) and adjusted cosine (item) subtract the user mean so “agreement” means above/below-average, not pressing the same number.
- Item-based is model-based: is precomputed and user-independent, so it serves new users — user-based CF (memory-based) cannot.
- Matrix form: (user) and (item). CF is blind to zero-rating items (cold start).