normalizeRatings.m 479 B

1234567891011121314151617
  1. function [Ynorm, Ymean] = normalizeRatings(Y, R)
  2. %NORMALIZERATINGS Preprocess data by subtracting mean rating for every
  3. %movie (every row)
  4. % [Ynorm, Ymean] = NORMALIZERATINGS(Y, R) normalized Y so that each movie
  5. % has a rating of 0 on average, and returns the mean rating in Ymean.
  6. %
  7. [m, n] = size(Y);
  8. Ymean = zeros(m, 1);
  9. Ynorm = zeros(size(Y));
  10. for i = 1:m
  11. idx = find(R(i, :) == 1);
  12. Ymean(i) = mean(Y(i, idx));
  13. Ynorm(i, idx) = Y(i, idx) - Ymean(i);
  14. end
  15. end