7 · Item-item collaborative filtering
Flip the matrix: measure similarity between ITEMS that the same users co-rated, then predict your rating for a new item from the items you already rated. Amazon popularized this because it's stable and precomputable.
One idea, one try. At your own pace.
LEARN BY DOINGPut your intuition to work3 steps
7 · Item-item collaborative filtering
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Item-item CF measures similarity between items based on the users who co-rated them, then predicts a user's rating for an item as the similarity-weighted average over the items that user already rated. Because items change far more slowly than users, the item-item similarity matrix is stable enough to precompute offline.
Without this:
With pure user-user CF, every new rating can shift a user's neighborhood and similarities must be recomputed live for millions of users — exactly the bottleneck Amazon solved by flipping to items.
User-user CF has a practical problem at scale: there are usually far more users than items, users' tastes drift constantly, and every new rating can change someone's neighborhood — so similarities go stale fast and must be recomputed live. Item-item collaborative filtering flips the perspective and solves this.
Instead of asking 'which users are like me?', item-item CF asks 'which items are like this one?' Two items are similar if the same users tend to rate them similarly — that is, we compute similarity over the columns of the matrix. Then, to predict user u's rating for item i:
pred(u,i) = Σ_j sim(i,j)·R[u,j] / Σ_j |sim(i,j)| over items j that u already rated.
In words: to guess how much you'll like item i, look at the items you already rated, weight each by how similar it is to i, and average. If you rated 'Interstellar' a 5 and it's highly similar to 'Inception', you'll probably like 'Inception' too.
The big practical win is stability and precomputability. Items change far more slowly than users — Inception's neighbors are basically the same this week as last week — so the item-item similarity matrix can be computed offline and cached, and serving a recommendation becomes a cheap lookup. Amazon popularized this approach ('Customers who bought this also bought…') in their famous 2003 paper precisely because item-item CF scaled to their catalog where user-user did not.
Python (in browser)
Item-item CF: cosine similarity between item columns, then predict a missing rating from the items that user already rated, weighted by item-item similarity.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Real-world item-item CF with the `implicit` library: fit once to precompute item-item similarities, then `recommend` and `similar_items` are cheap lookups (runs server-side, shown for reference).
Why is item-item CF usually preferred over user-user CF in large production systems like Amazon?
- Item-item CF computes similarity over the matrix columns (items co-rated by the same users) and predicts a rating from the user's already-rated, similar items.
- Because items change slowly, the item-item similarity matrix is stable and precomputable offline — serving becomes a cheap lookup.
- Amazon popularized item-item CF ('customers who bought this also bought…') because it scaled where user-user did not.
Amazon's 'customers also bought', YouTube's related videos, and Spotify's 'fans also like' are item-item neighbor lookups served from a precomputed similarity matrix.
If you remove it: Without item-item, large catalogs would have to recompute user neighborhoods live on every interaction — too slow and expensive to serve at scale.