Item-based collaborative filtering predicts a rating for a target item from the user's ratings of similar items. A rating of zero means that the item is unrated. For every item other than the target, include it only when its rating and similarity are both positive.
rt=∑i=tsi∑i=tsiriHere, t is the target index, r_i is the user's rating for item i, and s_i is that item's similarity to the target. The sums include only qualifying items. Return 0.0 when none qualify; otherwise return the predicted rating as a float.
Input: user_ratings = [5, 0, 3, 0, 4], item_similarities = [0.8, 0, 0.9, 0.1, 0.5], target = 1
Output: 3.954545
Explanation: Items 0, 2, and 4 contribute, giving a weighted sum of 8.7 and a similarity sum of 2.2.
Input: user_ratings = [2, 4, 6], item_similarities = [0.5, 0, 0.5], target = 1
Output: 4.000000
Accumulate similarity times rating and similarity in separate totals.
Return zero before division when the similarity total is zero.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Item-based collaborative filtering predicts a rating for a target item from the user's ratings of similar items. A rating of zero means that the item is unrated. For every item other than the target, include it only when its rating and similarity are both positive.
rt=∑i=tsi∑i=tsiriHere, t is the target index, r_i is the user's rating for item i, and s_i is that item's similarity to the target. The sums include only qualifying items. Return 0.0 when none qualify; otherwise return the predicted rating as a float.
Input: user_ratings = [5, 0, 3, 0, 4], item_similarities = [0.8, 0, 0.9, 0.1, 0.5], target = 1
Output: 3.954545
Explanation: Items 0, 2, and 4 contribute, giving a weighted sum of 8.7 and a similarity sum of 2.2.
Input: user_ratings = [2, 4, 6], item_similarities = [0.5, 0, 0.5], target = 1
Output: 4.000000
Accumulate similarity times rating and similarity in separate totals.
Return zero before division when the similarity total is zero.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number