Skip to content

P1: Amazon item-to-item collaborative filtering (Linden, Smith & York, 2003)

  • Status: done
  • Code: recsys/models/item_to_item.py
  • Experiment: EXP-001

What the paper did

Amazon needed "customers who bought this also bought" recommendations for tens of millions of customers and millions of products, computed in real time. Instead of comparing customers to each other, they compared items: two items are similar when the same customers bought both. A table of each item's most similar items is built offline. At request time, the recommender looks up the similar items for everything in the customer's basket and adds them up.

Why they built it this way

The constraint was scale and speed. User-to-user CF compares the current customer with every other customer at request time, and customers change constantly. Items change slowly, so the expensive similarity work can be done offline once. The online step is a few table lookups, independent of the number of customers. That is why item-to-item scaled when user-based CF didn't.

What I built

  1. A users × items matrix X with a 1 where a user reviewed an item.
  2. All co-occurrence counts at once: C = Xᵀ X. Entry C[i, j] is the number of users who had both items.
  3. Cosine similarity: C[i, j] / sqrt(n_i × n_j), where n_i is the number of users who had item i. Dividing by the square root stops very popular items from looking similar to everything.
  4. Optionally keep only each item's top-N neighbours (the offline table from the paper).
  5. For a user: sum the similarity rows of their history items, remove what they already have, take the top k. If fewer than k items have any similarity, fill the rest from all-time popularity.

What differs

  • Data: Amazon Reviews 2023, Video Games, 5-core: 25,612 items and about 95k users, not millions. Reviews stand in for purchases.
  • Similarity: binary cosine, as in the paper. No weighting by recency or rating.
  • Neighbours: tuned on validation. Keeping all neighbours was best; at this size there is no need to prune.

Result vs the paper's trend

Model (test, Dec 2022) Recall@10 Recall@50 NDCG@10
Popularity, all time 0.0032 0.0113 0.0017
Popularity, last 30 days 0.0280 0.0691 0.0186
This project 0.0187 0.0541 0.0101

The paper's claim holds against the baseline it was built to replace: item-to-item is about 6× better than recommending all-time bestsellers, and the gap is statistically clear.

But it loses to a 30-day popularity list. A third of December's interactions were with games released in the previous 60 days. Item-to-item needs co-purchases before it can recommend an item, and a three-week-old game has almost none.

What I learned

  • Item similarity is a memory of the past. It is strong for the back catalogue and blind to launches.
  • In a time-based evaluation, "popularity" must mean recent popularity, or every model looks good.
  • The new-item gap is exactly what fault 9 (cold-start starvation) will make worse on purpose. P1 shows the healthy level of that weakness.