Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Question 1: User-based Collaborative filtering

Given a small dataset of user-item preferences, in which the rating value ranges from 1 to 5,
predict the feedback rating for a target user (A) on movie 5 with user-based collaborative
filtering using the Pearson correlation coefficient as the similarity measure. (Note: use
neighbourhood size = 2 for each user. Round to the closest integer. Round down to 5 if the
resulted rating is greater than 5 and round up to 1 if the resulted rating is less than 1.)

Dataset:
User Movie 1 Movie 2 Movie 3 Movie 4 Movie 5
A 5 3 4 4 ?
B 3 1 2 3 3
C 4 3 4 3 5
D 3 3 1 5 4
E 1 5 5 2 1

Answer:
1. Compute the average rating for each user:
- A: (5+3+4+4)/4 = 4.0
- B: (3+1+2+3+3)/5 = 2.4
- C: (4+3+4+3+5)/5 = 3.8
- D: (3+3+1+5+4)/5 = 3.2
- E: (1+5+5+2+1)/5 = 2.8

2. Calculate the Pearson correlation coefficient between the target user (A) and all other
users:
- A and B: 0.84
- A and C: 0.61
- A and D: 0
- A and E: -0.77

3. Select the k most similar users (for example, k=2) to the target user:
- A and B: 0.84
- A and C: 0.61

4. Predict the target user's rating for the unrated item (Movie 5) using a weighted average of
the selected neighbours' ratings:
- Prediction = A's average + (B's similarity * (B's rating - B's average) + C's similarity * (C's
rating - C's average)) / (sum of absolute similarities)
- Prediction = 4.0 + (0.84* (3-2.4) + 0.61 * (5-3.8)) / (0.84 + 0.61)
- Prediction = 4.0 + (0.504 + 0.732) / 1.45
- Prediction ≈ 4.85
The predicted rating for Movie 5 for user A is 5.

Question 2: Item-based Collaborative Filtering


Using the following modified user-item rating matrix, where users A, B, C, and D have rated
items W, X, Y, and Z on a scale of 1 to 5. Empty cells indicate that the user has not yet rated
the item.

W X Y Z
User A 4 2 3
User B 3 1 4
User C 4 5 3
User D 1 5 3

Perform item-based collaborative filtering with cosine similarity (no need to use
adjusted cosine similarity for the sake of simplicity) to predict the rating of User A for
item Y. Show your work step by step, and include the following calculations:

Answer:

1. Cosine similarity calculation (Grading note: full marks also apply for those who use
overlapped terms in the square roots. For example, Cosine(Y,W) = (1*3 + 3*1) /
(sqrt(1^2 + 3^2) * sqrt(3^2 + 1^2)))

o Cosine(Y,W) = (1*3 + 3*1) / (sqrt(1^2 + 5^2 + 3^2) * sqrt(4^2 + 3^2 + 1^2)) = 6 /


(sqrt(35) * sqrt(26)) ≈ 0.199
o Cosine(Y,X) = (4*5 + 5*3)/ (sqrt(2^2+4^2+5^2)*sqrt(1^2+5^2+3^2)) = 35 /
sqrt(45)*sqrt(35) ≈ 0.882
o Cosine(Y,Z) = (1*4 + 5*3) / (sqrt(3^2+4^2+3^2)*sqrt(1^2+5^2+3^2)) = 19 /
sqrt(34)*sqrt(35) ≈ 0.551

2. Select the most similar items as neighbours to Y (neighbourhood size = 2)


Neighbour items to Y is {X, Z}.

4. Calculate the predicted rating of User A for item Y.

Pred(A, Y) = (Cosine(Y,X)*Rating(A,X) + Cosine(Y,Z)*Rating(A,Z)) / (Cosine(Y,X) +


Cosine(Y,Z)) = 0.882 * 2 + 0.551*3 / 0.882 + 0.551 ≈ 2.38

You might also like