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.
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]]
For user mode, compute one mean from each row before replacing its zeros.
For item mode, compute all column means before filling the copied matrix.
Sign in to take notes on this problem
Accepts: array
Accepts: string
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.
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]]
For user mode, compute one mean from each row before replacing its zeros.
For item mode, compute all column means before filling the copied matrix.
Sign in to take notes on this problem
Accepts: array
Accepts: string