Adjusted cosine similarity compares two items after removing each user's average rating. A zero entry in ratings_matrix means unrated. Compute each user's mean from all of that user's nonzero ratings, but include a user in the similarity only when both requested items are rated.
sim(i,j)=∑u∈Uij(rui−ru)2∑u∈Uij(ruj−ru)2∑u∈Uij(rui−ru)(ruj−ru)The sums include only users who rated both requested items. For each included user, subtract that user's mean observed rating from both item ratings before computing the similarity. Return 0.0 when the denominator is zero.
Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 4]], item_i = 0, item_j = 1
Output: -1.0
Explanation: Only user 0 rated both items, and its centered ratings are 1 and -1.
Input: ratings_matrix = [[5, 1], [4, 2], [3, 3]], item_i = 0, item_j = 1
Output: -1.0
Accumulate the centered cross-product and the two centered square sums separately.
Take the square root of each square sum before multiplying the denominator terms.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Adjusted cosine similarity compares two items after removing each user's average rating. A zero entry in ratings_matrix means unrated. Compute each user's mean from all of that user's nonzero ratings, but include a user in the similarity only when both requested items are rated.
sim(i,j)=∑u∈Uij(rui−ru)2∑u∈Uij(ruj−ru)2∑u∈Uij(rui−ru)(ruj−ru)The sums include only users who rated both requested items. For each included user, subtract that user's mean observed rating from both item ratings before computing the similarity. Return 0.0 when the denominator is zero.
Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 4]], item_i = 0, item_j = 1
Output: -1.0
Explanation: Only user 0 rated both items, and its centered ratings are 1 and -1.
Input: ratings_matrix = [[5, 1], [4, 2], [3, 3]], item_i = 0, item_j = 1
Output: -1.0
Accumulate the centered cross-product and the two centered square sums separately.
Take the square root of each square sum before multiplying the denominator terms.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number