Collaborative Filtering Cost
This commit is contained in:
parent
87457bb7b4
commit
fc28204594
1 changed files with 6 additions and 18 deletions
|
@ -11,7 +11,7 @@ X = reshape(params(1:num_movies*num_features), num_movies, num_features);
|
||||||
Theta = reshape(params(num_movies*num_features+1:end), ...
|
Theta = reshape(params(num_movies*num_features+1:end), ...
|
||||||
num_users, num_features);
|
num_users, num_features);
|
||||||
|
|
||||||
|
|
||||||
% You need to return the following values correctly
|
% You need to return the following values correctly
|
||||||
J = 0;
|
J = 0;
|
||||||
X_grad = zeros(size(X));
|
X_grad = zeros(size(X));
|
||||||
|
@ -21,7 +21,7 @@ Theta_grad = zeros(size(Theta));
|
||||||
% Instructions: Compute the cost function and gradient for collaborative
|
% Instructions: Compute the cost function and gradient for collaborative
|
||||||
% filtering. Concretely, you should first implement the cost
|
% filtering. Concretely, you should first implement the cost
|
||||||
% function (without regularization) and make sure it is
|
% function (without regularization) and make sure it is
|
||||||
% matches our costs. After that, you should implement the
|
% matches our costs. After that, you should implement the
|
||||||
% gradient and use the checkCostFunction routine to check
|
% gradient and use the checkCostFunction routine to check
|
||||||
% that the gradient is correct. Finally, you should implement
|
% that the gradient is correct. Finally, you should implement
|
||||||
% regularization.
|
% regularization.
|
||||||
|
@ -29,30 +29,18 @@ Theta_grad = zeros(size(Theta));
|
||||||
% Notes: X - num_movies x num_features matrix of movie features
|
% Notes: X - num_movies x num_features matrix of movie features
|
||||||
% Theta - num_users x num_features matrix of user features
|
% Theta - num_users x num_features matrix of user features
|
||||||
% Y - num_movies x num_users matrix of user ratings of movies
|
% Y - num_movies x num_users matrix of user ratings of movies
|
||||||
% R - num_movies x num_users matrix, where R(i, j) = 1 if the
|
% R - num_movies x num_users matrix, where R(i, j) = 1 if the
|
||||||
% i-th movie was rated by the j-th user
|
% i-th movie was rated by the j-th user
|
||||||
%
|
%
|
||||||
% You should set the following variables correctly:
|
% You should set the following variables correctly:
|
||||||
%
|
%
|
||||||
% X_grad - num_movies x num_features matrix, containing the
|
% X_grad - num_movies x num_features matrix, containing the
|
||||||
% partial derivatives w.r.t. to each element of X
|
% partial derivatives w.r.t. to each element of X
|
||||||
% Theta_grad - num_users x num_features matrix, containing the
|
% Theta_grad - num_users x num_features matrix, containing the
|
||||||
% partial derivatives w.r.t. to each element of Theta
|
% partial derivatives w.r.t. to each element of Theta
|
||||||
%
|
%
|
||||||
|
|
||||||
|
J = 0.5 * sum(sum(R.*(X*Theta'-Y).^2));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% =============================================================
|
% =============================================================
|
||||||
|
|
Reference in a new issue