TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Item-Based CF Prediction

Recommender Systems
Medium

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.

r^t=∑i≠tsiri∑i≠tsi\widehat{r}_t = \frac{\sum_{i \ne t} s_i r_i}{\sum_{i \ne t} s_i}rt​=∑i=t​si​∑i=t​si​ri​​

Here, 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.

Loading visualization...

Examples

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

Hint 1

Accumulate similarity times rating and similarity in separate totals.

Hint 2

Return zero before division when the similarity total is zero.

Requirements

  • Exclude the target index from the calculation.
  • Include only items with a nonzero rating and positive similarity.
  • Divide the weighted rating sum by the included similarity sum.
  • Return 0.0 when no item qualifies.

Constraints

  • user_ratings and item_similarities have equal length.
  • A zero rating represents an unrated item.
  • target is a valid index.
  • Time limit: 300 ms.
Try Similar Problems
User Based Cf PredictionAdjusted Cosine SimilarityMatrix Factorization Sgd StepTop K RecommendationsBaseline Predictor

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Item-Based CF Prediction

Recommender Systems
Medium

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.

r^t=∑i≠tsiri∑i≠tsi\widehat{r}_t = \frac{\sum_{i \ne t} s_i r_i}{\sum_{i \ne t} s_i}rt​=∑i=t​si​∑i=t​si​ri​​

Here, 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.

Loading visualization...

Examples

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

Hint 1

Accumulate similarity times rating and similarity in separate totals.

Hint 2

Return zero before division when the similarity total is zero.

Requirements

  • Exclude the target index from the calculation.
  • Include only items with a nonzero rating and positive similarity.
  • Divide the weighted rating sum by the included similarity sum.
  • Return 0.0 when no item qualifies.

Constraints

  • user_ratings and item_similarities have equal length.
  • A zero rating represents an unrated item.
  • target is a valid index.
  • Time limit: 300 ms.
Try Similar Problems
User Based Cf PredictionAdjusted Cosine SimilarityMatrix Factorization Sgd StepTop K RecommendationsBaseline Predictor

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.