Amazon's classic recommender: "people who liked this also liked…". Compare items by the users who rated them, then predict a user's rating for an item from their ratings of similar items.
R is a users × items matrix where 0 means "not rated". Implement:
item_similarity(R): cosine similarity between item columns (treating missing as 0), with a zero diagonal. Items with no ratings have similarity 0 to everything.predict(R, S, u, i, k=5): among the items user u has rated (excluding i), take the k with the highest similarity to i (ties: lower index), and return their similarity-weighted average rating, . Return 0.0 if the weights are all zero.recommend(R, S, u, n, k=5): the n unrated items with the highest predicted ratings (ties: lower index)