Mean-Centering Ratings: Generous vs Harsh Users

Recommender SystemsEasy+10 XP+10

Mean-Centering Ratings: Generous vs Harsh Users

Two users both rate a film 4. For a generous user who gives everything 4s and 5s, that's indifference. For a harsh user who rarely goes above 2, it's enthusiasm. Comparing raw ratings across users therefore compares their personalities as much as their tastes.

Mean-centering removes that. Subtract each user's own average and what's left is how they felt about the item relative to their usual.

Task: write normalize_ratings(ratings) returning the centred matrix, every value rounded to 4 decimal places.

  • ratings is a list of rows, one per user, with one column per item. None means that user never rated that item.
  • Each user's mean is computed over the items they actually rated — the Nones must not count toward it or toward the item count.
  • None stays None in the output. A missing rating isn't zero; zero would mean "exactly average", which is a claim you don't get to make.
  • Every user has rated at least one item.

After centring, a positive number means above that user's norm, negative means below, and 0 means exactly typical for them. That change of meaning is what makes the numbers comparable across users at all — and it's why a user who gave everything the same rating comes out as all zeros, correctly telling you their ratings carry no information about preference.

Examples

ratings = [[5, 3, None], [None, 2, 4]]
returns [[1.0, -1.0, None], [None, -1.0, 1.0]]
ratings = [[1, 1, 1]]
returns [[0.0, 0.0, 0.0]]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run