Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Films like the ones you rated
“Customers who bought this also bought…”: two items are related if the same people tend to like (or dislike) both. Item-based collaborative filtering builds a table of how related every pair of items is, using everyone’s ratings. To guess how much you will like a new item, it looks at the items you already rated that are most related to it and averages your own ratings of them. It is like recommending a book because it resembles your favourites, where “resembles” means “is enjoyed by the same readers”.
Item-item models are the workhorse of production recommenders (Amazon’s original system, YouTube’s early related videos). They scale because the item table is computed offline and lookups are cheap. In engineering contexts they power “procedures often used together”, “parts often replaced together” and “documents often opened after this one”.
- 1. Item-based CF compares…
- 2. To predict your rating for a new item, it uses…
- 3. The item–item table can usually be computed…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Adjusted cosine and prediction by hand
Adjusted cosine. Centre each rating by its user’s mean, then take the cosine between the two items’ columns over users who rated both:
s(i, j) = Σᵤ (rᵤᵢ − r̄ᵤ)(rᵤⱼ − r̄ᵤ) / (√Σᵤ (rᵤᵢ − r̄ᵤ)² · √Σᵤ (rᵤⱼ − r̄ᵤ)²).
Users x, y, z have means 3, 4, 2. They rate item i as 5, 5, 1 (centred 2, 1, −1) and item j as 4, 5, 1 (centred 1, 1, −1), so s = 4/(√6 · √3) = 0.943. Centring by user means, rather than item means, removes rating-scale differences between users.
Prediction. From the user’s own ratings of the k most similar items N:
r̂ᵤᵢ = Σⱼ s(i, j) rᵤⱼ / Σⱼ |s(i, j)|.
With similarities 0.9 and 0.3 to items the user rated 5 and 3: (4.5 + 0.9)/1.2 = 4.5.
With baselines. Predict residuals from bᵤⱼ = μ + bᵤ + bⱼ:
r̂ᵤᵢ = bᵤᵢ + Σⱼ s(i, j)(rᵤⱼ − bᵤⱼ) / Σⱼ |s(i, j)|.
With bᵤᵢ = 3.6, two neighbours of similarity 0.5, ratings 5 and 4, and baselines 4 and 4: 3.6 + 0.5 = 4.1.
Cost. n items need n(n − 1)/2 similarities: 19 900 for 200 items, against 179 700 user–user similarities for 600 users. In practice, keep only each item’s top-k neighbours.
- 1. Adjusted cosine centres ratings by…
- 2. The item-based prediction averages…
- 3. Item–item similarities for 1000 items number…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Why items are better neighbours
More evidence per similarity. With m users and n items, an item has on average m · density raters, and a user has n · density ratings. When m ≫ n, as in most catalogues, item pairs share many more raters than user pairs share items, so item–item similarities are estimated from more data.
Stability. A user’s neighbourhood changes with every new rating they give. An item’s neighbourhood, averaged over thousands of users, drifts slowly, so it can be refreshed nightly rather than per request.
Explainability. “Because you liked Engines and Jets” is a statement about the user’s own actions, which users find more convincing than “users like you”.
Exercise 1 (600 users × 200 items, 10.8% observed, 2701 held out). RMSE:
- bias baseline 0.948;
- item-based k-NN (adjusted cosine, k = 20, shrinkage, baseline residuals) 0.852.
from surprise import KNNBaseline
algo = KNNBaseline(k=20, sim_options={"name": "pearson_baseline", "user_based": False}) # item-based with baselines- 1. When users far outnumber items, item–item similarities are…
- 2. Item neighbourhoods change…
- 3. Item-based explanations refer to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Relation to linear models. The item-based prediction is a weighted sum of the user’s own ratings, so it is a linear model with fixed weights. SLIM (Ning and Karypis, 2011) learns sparse item–item weights by regression instead of setting them to similarities, and EASE (Steck, 2019) solves a closed-form ridge version. Both are strong baselines for implicit feedback.
Scaling. Sparse matrix products compute co-rating counts and similarities; locality-sensitive hashing (MinHash, SimHash) or approximate nearest-neighbour indexes find top-k neighbours for millions of items. Linden et al. (2003) noted that most item pairs share no customers, so only co-occurring pairs need computing.
Limits. New items have no co-ratings (item cold start; content features or hybrids help). Popular items dominate neighbourhoods unless similarities are normalised or popularity-penalised. Neighbourhoods capture local, pairwise relations; matrix factorisation captures global latent structure, and the two combine well (Koren, 2008).
Interview questions.
- Why did Amazon choose item-to-item CF? Scale (millions of customers, an item table computed offline), real-time recommendations from a lookup, quality with sparse data, and explainable “because you bought X”.
- How would you handle a new product with no purchases? Use content similarity to existing products for its neighbour list, then shift toward collaborative similarities as co-purchases accumulate.
- 1. SLIM and EASE learn…
- 2. Linden et al. sped up item–item computation by…
- 3. The item cold-start problem means…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Items or users?
History.
- B. Sarwar, G. Karypis, J. Konstan and J. Riedl (2001) studied item-based CF and adjusted cosine.
- G. Linden, B. Smith and J. York (2003) described Amazon’s item-to-item CF.
- Y. Koren (2008) combined neighbourhoods with factorisation.
- X. Ning and G. Karypis (2011) introduced SLIM, and H. Steck (2019) EASE.
Exercise 2. 600 users × 200 items at two densities, user-based (Pearson) against item-based (adjusted cosine with baseline residuals), k = 20, with shrinkage. Stability is the correlation between similarities computed from two disjoint halves of the data: two halves of the users for item–item similarities, two halves of the items for user–user similarities.
| density | baseline RMSE | user-based | item-based | item–item stability | user–user stability |
|---|---|---|---|---|---|
| 6% | 1.000 | 1.006 | 0.965 | 0.251 | 0.025 |
| 15% | 0.924 | 0.825 | 0.819 | 0.417 | 0.111 |
- At 6% density, only item-based CF beat the baseline (0.965 against 1.000). User-based CF was slightly worse than the baseline.
- At 15%, both helped a lot, with item-based CF marginally ahead (0.819 against 0.825).
- Item–item similarities were 4–10 times more reproducible across disjoint halves of the data (0.25 against 0.03, and 0.42 against 0.11). With three times as many users as items, each item pair rests on far more co-ratings. That stability is what makes offline precomputation safe.
Item-based CF in AI, robotics and aerospace
- Parts and procedures: “replaced together” and “performed together” lists from maintenance histories, precomputed per fleet.
- Engineering knowledge bases: documents, test cases or design templates frequently used together.
- Mission planning tools: options frequently chosen together by planners, with explanations rooted in the user’s own selections.
References
- B. Sarwar, G. Karypis, J. Konstan, J. Riedl (2001). “Item-based collaborative filtering recommendation algorithms.” Proc. WWW.
- G. Linden, B. Smith, J. York (2003). “Amazon.com recommendations: item-to-item collaborative filtering.” IEEE Internet Computing 7(1).
- X. Ning, G. Karypis (2011). “SLIM: sparse linear methods for top-N recommender systems.” Proc. IEEE ICDM.
- H. Steck (2019). “Embarrassingly shallow autoencoders for sparse data.” Proc. WWW.