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

User-Based CF Prediction

Recommender Systems
Medium

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.

Algorithm

Filter to users with positive similarity, then compute the weighted average:

r^=∑u:su>0su⋅ru∑u:su>0su\hat{r} = \frac{\sum_{u: s_u > 0} s_u \cdot r_u}{\sum_{u: s_u > 0} s_u}r^=∑u:su​>0​su​∑u:su​>0​su​⋅ru​​

If no user has positive similarity, return 0.0.

Return the predicted rating rounded to six decimals for display.

Loading visualization...

Examples

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

Hint 1

Accumulate similarity times rating only when similarity is positive.

Hint 2

Divide by the included similarity sum, returning zero when that sum is zero.

Requirements

  • Only include users whose similarity is strictly greater than 0
  • Compute the predicted rating as the similarity-weighted average of their ratings
  • Return 0.0 if no user has positive similarity
  • Return the prediction as a float

Constraints

  • similarities and ratings have the same length (at least 1)
  • Similarities can be negative, zero, or positive
  • Ratings are positive numbers
  • Return a float
  • Time limit: 300 ms
Try Similar Problems
Item Cf PredictAdjusted Cosine SimilarityMatrix Factorization Sgd StepTop K RecommendationsBaseline Predictor

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

User-Based CF Prediction

Recommender Systems
Medium

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.

Algorithm

Filter to users with positive similarity, then compute the weighted average:

r^=∑u:su>0su⋅ru∑u:su>0su\hat{r} = \frac{\sum_{u: s_u > 0} s_u \cdot r_u}{\sum_{u: s_u > 0} s_u}r^=∑u:su​>0​su​∑u:su​>0​su​⋅ru​​

If no user has positive similarity, return 0.0.

Return the predicted rating rounded to six decimals for display.

Loading visualization...

Examples

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

Hint 1

Accumulate similarity times rating only when similarity is positive.

Hint 2

Divide by the included similarity sum, returning zero when that sum is zero.

Requirements

  • Only include users whose similarity is strictly greater than 0
  • Compute the predicted rating as the similarity-weighted average of their ratings
  • Return 0.0 if no user has positive similarity
  • Return the prediction as a float

Constraints

  • similarities and ratings have the same length (at least 1)
  • Similarities can be negative, zero, or positive
  • Ratings are positive numbers
  • Return a float
  • Time limit: 300 ms
Try Similar Problems
Item Cf PredictAdjusted Cosine SimilarityMatrix Factorization Sgd StepTop K RecommendationsBaseline Predictor

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.