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

Baseline Predictor

Recommender Systems
Hard

A collaborative-filtering baseline separates ratings into a global average, a user bias, and an item bias. A zero in ratings_matrix means that no rating was observed and must be excluded from all averages.

Compute each user's bias:

bu=r‾u−μb_u = \overline{r}_u - \mubu​=ru​−μ

Compute each item's bias:

bi=r‾i−μb_i = \overline{r}_i - \mubi​=ri​−μ

Predict a requested user-item pair:

r^ui=μ+bu+bi\widehat{r}_{ui} = \mu + b_u + b_irui​=μ+bu​+bi​

The global average is the mean of every nonzero rating. A user's observed-rating mean determines the user bias, while an item's observed-rating mean determines the item bias. Use a bias of zero for a user or item with no observed ratings. Return predictions for target_pairs in their original order.

Loading visualization...

Examples

Input: ratings_matrix = [[5, 3, 0], [4, 0, 1], [0, 1, 5]], target_pairs = [[0, 2], [1, 1], [2, 0]]

Output: [3.833333, 1.333333, 4.333333]

Explanation: The global mean is 19 / 6. Each prediction adds that mean to the corresponding user and item deviations.

Input: ratings_matrix = [[5, 0], [0, 3]], target_pairs = [[0, 1], [1, 0]]

Output: [4.0, 4.0]

Hint 1

Build user means from rows and item means from columns while skipping zeros.

Hint 2

For each pair, add the global mean, its user bias, and its item bias.

Requirements

  • Compute the global mean from nonzero ratings only.
  • Compute user and item biases from their observed ratings only.
  • Use zero bias when a user or item has no observed ratings.
  • Return one prediction for each pair in target_pairs.

Constraints

  • ratings_matrix is rectangular and contains at least one nonzero rating.
  • A zero entry represents a missing rating.
  • Every target pair contains valid user and item indices.
  • Time limit: 300 ms.
Try Similar Problems
Mean Rating ImputationItem Cf PredictUser Based Cf PredictionPopularity RankingMatrix Factorization Sgd Step

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Baseline Predictor

Recommender Systems
Hard

A collaborative-filtering baseline separates ratings into a global average, a user bias, and an item bias. A zero in ratings_matrix means that no rating was observed and must be excluded from all averages.

Compute each user's bias:

bu=r‾u−μb_u = \overline{r}_u - \mubu​=ru​−μ

Compute each item's bias:

bi=r‾i−μb_i = \overline{r}_i - \mubi​=ri​−μ

Predict a requested user-item pair:

r^ui=μ+bu+bi\widehat{r}_{ui} = \mu + b_u + b_irui​=μ+bu​+bi​

The global average is the mean of every nonzero rating. A user's observed-rating mean determines the user bias, while an item's observed-rating mean determines the item bias. Use a bias of zero for a user or item with no observed ratings. Return predictions for target_pairs in their original order.

Loading visualization...

Examples

Input: ratings_matrix = [[5, 3, 0], [4, 0, 1], [0, 1, 5]], target_pairs = [[0, 2], [1, 1], [2, 0]]

Output: [3.833333, 1.333333, 4.333333]

Explanation: The global mean is 19 / 6. Each prediction adds that mean to the corresponding user and item deviations.

Input: ratings_matrix = [[5, 0], [0, 3]], target_pairs = [[0, 1], [1, 0]]

Output: [4.0, 4.0]

Hint 1

Build user means from rows and item means from columns while skipping zeros.

Hint 2

For each pair, add the global mean, its user bias, and its item bias.

Requirements

  • Compute the global mean from nonzero ratings only.
  • Compute user and item biases from their observed ratings only.
  • Use zero bias when a user or item has no observed ratings.
  • Return one prediction for each pair in target_pairs.

Constraints

  • ratings_matrix is rectangular and contains at least one nonzero rating.
  • A zero entry represents a missing rating.
  • Every target pair contains valid user and item indices.
  • Time limit: 300 ms.
Try Similar Problems
Mean Rating ImputationItem Cf PredictUser Based Cf PredictionPopularity RankingMatrix Factorization Sgd Step

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.