Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit 19b0740

Browse files
committed
Implementing cost function for collaborative filtering
1 parent 1da677d commit 19b0740

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Machine Learning/Week 9/machine-learning-ex8/ex8/cofiCostFunc.m

+6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
%
4242

4343

44+
errors = (X*Theta' - Y) .* R;
45+
regularizationTheta = lambda/2 * sum(sum(Theta.^2));
46+
regularizationX = lambda/2 * sum(sum(X.^2));
4447

48+
J = 1/2 * sum(sum(errors .^2)) + regularizationTheta + regularizationX;
49+
X_grad = errors * Theta + lambda * X;
50+
Theta_grad = errors' * X + lambda * Theta;
4551

4652
% =============================================================
4753

0 commit comments

Comments
 (0)