Item-based collaborative filtering recommends items by finding other items consumed by the same users. Instead of comparing users, it compares columns in a user–item interaction matrix, exposing behavioral relationships that item metadata may miss. section 1.3.2 section 2.6
A simple implementation follows this path:
- Represent clicks, purchases, ratings, or consumption as a user–item matrix. section 1.3.2
- Select a seed item and compute its similarity to every other item with a dot product over user interactions. section 1.3.2
- Remove the seed item, sort the similarity scores, and return the highest-ranked items. section 1.3.2
- Place the result in retrieval, filtering, scoring, and ordering stages when building a broader recommender pipeline. section 2.6
From a comic to related items
If Asterix and Superman were consumed by 21 users, their co-consumption contributes to item similarity. Querying Superman can therefore return Lucky Luke and Tintin, reflecting behavioral overlap rather than shared metadata. section 1.3.2
More like this
For Toy Story (1995), item-based recommendations include Toy Story 2, Aladdin, Monsters, Inc., The Lion King, and A Bug's Life. The learned connections come from users who enjoyed the seed movie. section 3.3.7
Listing 1.7 Item-based Collaborative filtering .
def find_similar_items(matrix: np.array, item_id: int, top_n: int = 3):
item_sim = np.dot(matrix.T[item_id], matrix.T) #A
item_sim[item_id] = 0 #B
most_similar_items = np.argsort(item_sim)[::-1][:top_n] #C
return most_similar_items.tolist()The listing shows the minimal item-based calculation: transpose the interaction matrix, compute similarity for one item, exclude that item, and select the top results. section 1.3.2
