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=ru−μCompute each item's bias:
bi=ri−μPredict a requested user-item pair:
rui=μ+bu+biThe 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.
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]
Build user means from rows and item means from columns while skipping zeros.
For each pair, add the global mean, its user bias, and its item bias.
Accepts: array
Accepts: array
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=ru−μCompute each item's bias:
bi=ri−μPredict a requested user-item pair:
rui=μ+bu+biThe 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.
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]
Build user means from rows and item means from columns while skipping zeros.
For each pair, add the global mean, its user bias, and its item bias.
Accepts: array
Accepts: array