To guess how a user would rate an item they haven't seen, find the users most like them who have rated it, and take a weighted average of what those people thought — corrected for the fact that some of them are simply more generous raters.
Task: write predict_user_cf(ratings, user, item, k) returning the prediction, rounded to 4 decimal places.
The steps, pinned down:
item.0, the similarity is 0.k candidates with the highest similarity. Ties go to the lower user index.ratings is a list of rows, one per user, with None for unrated. Every user's mean is over the items they actually rated.0, return the target user's mean alone.k candidates is fine — use what there is.Two details carry the whole method. The deviations are why a harsh critic's 3 can push a prediction up: what transfers is "they liked it more than usual", not the number itself. And the denominator is a sum of absolute similarities, so a negatively-correlated neighbour still contributes a full share of the weight — their rating just gets flipped, which is information too.