From 2d6da3e3d4867546eb49c11184eef3de72c9057f Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 6 Nov 2014 01:12:38 +0100 Subject: [PATCH] Regularized linear regression gradient --- ex5/linearRegCostFunction.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ex5/linearRegCostFunction.m b/ex5/linearRegCostFunction.m index 1d70418..e90732b 100644 --- a/ex5/linearRegCostFunction.m +++ b/ex5/linearRegCostFunction.m @@ -22,6 +22,8 @@ grad = zeros(size(theta)); J = 1/(2*m) * sum(((X*theta)-y).^2) ... + lambda/(2*m) * sum(theta(2:end).^2); +grad = 1/m * X' * ((X*theta)-y) + (lambda/m) * [0; theta(2:end)]; + % ========================================================================= grad = grad(:);