Welcome. In our previous lesson, we explored user-based collaborative filtering, a method for making predictions by answering the question: "What might a person like, based on what similar people have liked?" We calculated similarities between users to predict a missing rating.
Today, we will investigate the other side of the collaborative filtering coin: item-based collaborative filtering. This approach answers a subtly different, yet equally powerful question: "Since you liked item X, and other people who liked item X also liked item Y, how much will you like item Y?" This method shifts the focus from similar users to similar items.
Your learning outcome for this lesson is to predict a missing rating in a user-item matrix using item-based collaborative filtering with a small number of items. As always, we will work through the full mathematical process by hand, applying it to your bra-fitting and relationship management scenarios.
From User Similarity to Item Similarity
In user-based filtering, we found similar users by comparing rows in the user-item matrix. For item-based filtering, we find similar items by comparing the columns.

The core assumption is that if two items tend to receive similar ratings from the same users, they are similar. For example, if customers who rate the 'Balconette' bra highly also tend to rate the 'Push-up' bra highly, and those who dislike one tend to dislike the other, these two items are considered similar.
The process for predicting a rating is as follows:
- Calculate Item-Item Similarity: For our target item (the one with the missing rating), we compute a similarity score between it and every other item in the dataset. We'll use a metric called Adjusted Cosine Similarity, which is effectively the Pearson correlation applied to item columns instead of user rows. This correctly accounts for the fact that different users have different rating scales (e.g., some are lenient, some are harsh).
- Select Neighboring Items: We identify the k most similar items to our target item, but with a crucial condition: we only consider items that the target user has actually rated.
- Predict Rating: We calculate the predicted rating as a weighted average of the target user's ratings for those neighboring items. The weights are the item-item similarity scores.
Let's look at the formulas.
1. Adjusted Cosine Similarity
The similarity between a target item and another item is calculated as:
Where:
- is the set of users who have rated both item and item .
- is the rating of user for item .
- is the average rating given by user .
This is mathematically identical to the Pearson correlation formula from our last lesson, but the context is different. We are correlating vectors of ratings for two items across all users who rated both, and we are adjusting for each user's average rating.
2. Prediction Formula
Once we have the item similarities, we predict the rating of user for item using the following formula:
Where:
- is the set of neighbor items—the k items most similar to item that have also been rated by user .
- is the similarity between target item and neighbor item .
- is user 's rating for the neighbor item .
This formula calculates a straightforward weighted average. It says the predicted rating for an item is the average of the ratings the user gave to similar items, weighted by the degree of similarity.
Now, let's put this into practice.
Application 1: Recommending a Bra Style, Revisited
We'll use the same scenario as last time: predicting how customer Elara will rate the 'Plunge' style. This will allow us to compare the results of the two collaborative filtering methods.
Here is the user-item rating matrix:
| Customer | Balconette | Strapless | T-shirt | Plunge | Sports |
|---|---|---|---|---|---|
| Anika | 4 | 2 | 5 | 4 | 3 |
| Beth | 5 | 3 | 4 | 5 | 2 |
| Chloe | 2 | 5 | 2 | 3 | 5 |
| Dana | - | 3 | 3 | 2 | 4 |
| Elara (Target) | 4 | 5 | 3 | ? | 4 |
Our goal is to predict Elara's rating for 'Plunge'. Elara has rated Balconette, Strapless, T-shirt, and Sports. We will use the top 2 most similar items (k=2) as neighbors for our prediction.
Step 1: Calculate Average Ratings for Each User
We need each user's average rating to calculate the adjusted cosine similarities.
Step 2: Calculate Similarity between 'Plunge' and Other Items
We need to find the similarity between our target item ('Plunge') and the items Elara has actually rated: 'Balconette', 'Strapless', 'T-shirt', and 'Sports'.
-
sim(Plunge, Balconette):
- Co-raters: Anika, Beth, Chloe.
- Ratings deviations for Plunge:
- Ratings deviations for Balconette:
- Numerator:
- Denominator:
-
sim(Plunge, Strapless):
- Co-raters: Anika, Beth, Chloe, Dana.
- Deviations for Plunge:
- Deviations for Strapless:
- Numerator:
- Denominator:
-
sim(Plunge, T-shirt):
- Co-raters: Anika, Beth, Chloe, Dana.
- Deviations for Plunge:
- Deviations for T-shirt:
- Numerator:
- Denominator:
-
sim(Plunge, Sports):
- Co-raters: Anika, Beth, Chloe, Dana.
- Deviations for Plunge:
- Deviations for Sports:
- Numerator:
- Denominator:
Step 3: Select Neighboring Items
We want the top k=2 neighbors for 'Plunge' from the items Elara has rated. The similarities are:
- Balconette: 0.863
- T-shirt: 0.411
- Strapless: -0.562
- Sports: -0.909
The two most similar items are Balconette and T-shirt.
Step 4: Predict the Rating for 'Plunge'
Now we use the prediction formula. Our neighbors are {Balconette, T-shirt}. We need Elara's ratings for these items: and .
Numerator:
Denominator:
Prediction:
Interpretation: Item-based collaborative filtering predicts that Elara would rate the Plunge bra approximately 3.68 out of 5. This prediction is based on the fact that the Plunge style is very similar to the Balconette style (which she rated a 4) and moderately similar to the T-shirt style (which she rated a 3). Notice this is a different prediction from the user-based method (3.36), showcasing how the two approaches can yield different but equally valid insights.
Application 2: Predicting Activity Satisfaction, Revisited
Let's use the same item-based method for your relationship management scenario. We want to predict Partner B's satisfaction for the 'Weekend Trip' in your V1 relationship.
| Relationship | Date Night | Shared Hobby | Daily Check-in | Weekend Trip | Meet Friends |
|---|---|---|---|---|---|
| V1 (Target) | 5 | 4 | 3 | ? | 4 |
| V2 | 2 | 2 | 5 | 3 | 4 |
| V3 | 5 | 5 | 2 | 5 | 1 |
| V4 | 1 | 2 | 4 | 2 | 5 |
We want to predict the '?' for V1. The activities V1 has rated are {Date Night, Shared Hobby, Daily Check-in, Meet Friends}. We will use k=2 neighbors.
Step 1: Calculate Average Ratings for Each 'User' (Relationship)
(Note: V1's average isn't needed for the similarity part).
Step 2: Calculate Similarity between 'Weekend Trip' and Other Activities
-
sim(Trip, Date Night):
- Co-raters: V2, V3, V4.
- Deviations for Trip:
- Deviations for Date Night:
- Num:
- Denom:
-
sim(Trip, Shared Hobby):
- Co-raters: V2, V3, V4.
- Deviations for Trip:
- Deviations for Hobby:
- These deviation vectors are identical. This means the correlation is perfect.
-
sim(Trip, Daily Check-in):
- Co-raters: V2, V3, V4.
- Deviations for Trip:
- Deviations for Check-in:
- Num:
- Denom:
-
sim(Trip, Meet Friends):
- Co-raters: V2, V3, V4.
- Deviations for Trip:
- Deviations for Friends:
- Num:
- Denom:
Step 3: Select Neighboring Activities
The top k=2 most similar activities to 'Weekend Trip' are:
- Shared Hobby: 1.0
- Date Night: 0.869
Step 4: Predict the Rating for 'Weekend Trip'
We use V1's ratings for the neighbors: and .
Numerator:
Denominator:
Prediction:
Interpretation: Item-based filtering predicts a satisfaction score of 4.46 for the 'Weekend Trip'. The model found that 'Weekend Trip' is perfectly correlated with 'Shared Hobby' and highly correlated with 'Date Night' based on the patterns of other relationships. Since Partner B's satisfaction is high for those two activities (4 and 5), the model strongly suggests satisfaction will also be high for the trip. This again provides a data-driven justification for planning the activity.
Conclusion
In this lesson, you have mastered the mechanics of item-based collaborative filtering. By computing similarities between items based on user rating patterns, you can make robust predictions for unrated items.
Key Takeaways:
- Item-based collaborative filtering predicts ratings based on the user's ratings for similar items.
- It works by comparing columns (items) in the user-item matrix, in contrast to user-based filtering which compares rows (users).
- Adjusted Cosine Similarity (or Pearson correlation on item vectors) is used to find item similarity while accounting for user-specific rating biases.
- The final prediction is a weighted average of the user's ratings on neighboring items.
- In many real-world systems, item-based approaches are favored because item-to-item relationships are often more stable over time than user tastes, allowing similarities to be pre-computed efficiently.
This lesson concludes our exploration of recommendation algorithms. We now pivot from predictive modeling to a different class of quantitative reasoning. In our next lesson, we will enter the world of decision science and begin with the optimal stopping rule, a fascinating mathematical tool for knowing when to stop searching and make a choice.