You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
479 B
Matlab
18 lines
479 B
Matlab
10 years ago
|
function [Ynorm, Ymean] = normalizeRatings(Y, R)
|
||
|
%NORMALIZERATINGS Preprocess data by subtracting mean rating for every
|
||
|
%movie (every row)
|
||
|
% [Ynorm, Ymean] = NORMALIZERATINGS(Y, R) normalized Y so that each movie
|
||
|
% has a rating of 0 on average, and returns the mean rating in Ymean.
|
||
|
%
|
||
|
|
||
|
[m, n] = size(Y);
|
||
|
Ymean = zeros(m, 1);
|
||
|
Ynorm = zeros(size(Y));
|
||
|
for i = 1:m
|
||
|
idx = find(R(i, :) == 1);
|
||
|
Ymean(i) = mean(Y(i, idx));
|
||
|
Ynorm(i, idx) = Y(i, idx) - Ymean(i);
|
||
|
end
|
||
|
|
||
|
end
|