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

Mean Rating Imputation

Recommender SystemsData Processing
Medium

A user-item rating matrix is often sparse, with zero representing a missing rating. Mean imputation fills each missing entry using observed ratings from either the same user or the same item.

In user mode, replace each zero in a row with the mean of that row's nonzero ratings. In item mode, replace each zero in a column with the mean of that column's nonzero ratings. If a user or item has no observed ratings, use 0.0 as its mean. Return a new matrix and leave ratings_matrix unchanged.

Loading visualization...

Examples

Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 5]], mode = "user"

Output: [[5, 3, 4.0], [4, 3.0, 2], [3.0, 1, 5]]

Explanation: Each zero is replaced by the mean of the nonzero ratings in its row.

Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 5]], mode = "item"

Output: [[5, 3, 3.5], [4, 2.0, 2], [4.5, 1, 5]]

Hint 1

For user mode, compute one mean from each row before replacing its zeros.

Hint 2

For item mode, compute all column means before filling the copied matrix.

Requirements

  • Treat zero as a missing rating.
  • In user mode, impute each zero with its user mean.
  • In item mode, impute each zero with its item mean.
  • Use 0.0 when the corresponding user or item has no observed ratings.
  • Return a new matrix with the same shape.

Constraints

  • ratings_matrix is a nonempty rectangular matrix.
  • mode is either user or item.
  • Ratings are nonnegative numbers.
  • Time limit: 300 ms.
Try Similar Problems
Impute MissingRating NormalizationBaseline PredictorMatrix Factorization Sgd StepZscore Standardization

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: string

You must run your code first.
PrevNext

Mean Rating Imputation

Recommender SystemsData Processing
Medium

A user-item rating matrix is often sparse, with zero representing a missing rating. Mean imputation fills each missing entry using observed ratings from either the same user or the same item.

In user mode, replace each zero in a row with the mean of that row's nonzero ratings. In item mode, replace each zero in a column with the mean of that column's nonzero ratings. If a user or item has no observed ratings, use 0.0 as its mean. Return a new matrix and leave ratings_matrix unchanged.

Loading visualization...

Examples

Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 5]], mode = "user"

Output: [[5, 3, 4.0], [4, 3.0, 2], [3.0, 1, 5]]

Explanation: Each zero is replaced by the mean of the nonzero ratings in its row.

Input: ratings_matrix = [[5, 3, 0], [4, 0, 2], [0, 1, 5]], mode = "item"

Output: [[5, 3, 3.5], [4, 2.0, 2], [4.5, 1, 5]]

Hint 1

For user mode, compute one mean from each row before replacing its zeros.

Hint 2

For item mode, compute all column means before filling the copied matrix.

Requirements

  • Treat zero as a missing rating.
  • In user mode, impute each zero with its user mean.
  • In item mode, impute each zero with its item mean.
  • Use 0.0 when the corresponding user or item has no observed ratings.
  • Return a new matrix with the same shape.

Constraints

  • ratings_matrix is a nonempty rectangular matrix.
  • mode is either user or item.
  • Ratings are nonnegative numbers.
  • Time limit: 300 ms.
Try Similar Problems
Impute MissingRating NormalizationBaseline PredictorMatrix Factorization Sgd StepZscore Standardization

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: string

You must run your code first.