User-based collaborative filtering predicts a target user's rating for an item by computing a weighted average of ratings from similar users. The intuition is that users who agreed in the past will agree in the future. Only users with positive similarity are considered, and their ratings are weighted by how similar they are to the target user.
Given a list of similarity scores and corresponding ratings from neighbor users who have rated the target item, compute the predicted rating.
Filter to users with positive similarity, then compute the weighted average:
r^=∑u:su>0su∑u:su>0su⋅ruIf no user has positive similarity, return 0.0.
Return the predicted rating rounded to six decimals for display.
Input: similarities = [0.9, 0.8, 0.3], ratings = [4, 5, 2]
Output: 4.1
Explanation: The weighted sum is 8.2 and the positive-similarity sum is 2.0.
Input: similarities = [0.8, -0.2, 0.6], ratings = [5, 1, 3]
Output: 4.142857
Accumulate similarity times rating only when similarity is positive.
Divide by the included similarity sum, returning zero when that sum is zero.
Sign in to take notes on this problem
Accepts: array
Accepts: array
User-based collaborative filtering predicts a target user's rating for an item by computing a weighted average of ratings from similar users. The intuition is that users who agreed in the past will agree in the future. Only users with positive similarity are considered, and their ratings are weighted by how similar they are to the target user.
Given a list of similarity scores and corresponding ratings from neighbor users who have rated the target item, compute the predicted rating.
Filter to users with positive similarity, then compute the weighted average:
r^=∑u:su>0su∑u:su>0su⋅ruIf no user has positive similarity, return 0.0.
Return the predicted rating rounded to six decimals for display.
Input: similarities = [0.9, 0.8, 0.3], ratings = [4, 5, 2]
Output: 4.1
Explanation: The weighted sum is 8.2 and the positive-similarity sum is 2.0.
Input: similarities = [0.8, -0.2, 0.6], ratings = [5, 1, 3]
Output: 4.142857
Accumulate similarity times rating only when similarity is positive.
Divide by the included similarity sum, returning zero when that sum is zero.
Sign in to take notes on this problem
Accepts: array
Accepts: array