Skip to content
Browse files

question 1

  • Loading branch information...
1 parent 15329dc commit 5b92130bbe67f934ea58bc619f81f8651be01a22 @schneems committed Nov 6, 2011
Showing with 9 additions and 3 deletions.
  1. +6 −2 mlclass-ex3/mlclass-ex3/lrCostFunction.m
  2. +3 −1 octave_cheat_sheet.txt
View
8 mlclass-ex3/mlclass-ex3/lrCostFunction.m
@@ -37,16 +37,20 @@
%
+% calculate hypothesis
+h = sigmoid(X*theta);
+% regularize theta by removing first value
+theta_reg = [0;theta(2:end, :);];
+J = (1/m)*(-y'* log(h) - (1 - y)'*log(1-h))+(lambda/(2*m))*theta_reg'*theta_reg;
+grad = (1/m)*(X'*(h-y)+lambda*theta_reg);
% =============================================================
-grad = grad(:);
-
end
View
4 octave_cheat_sheet.txt
@@ -270,4 +270,6 @@ initialTheta = zeros(n,1); % can we do better?
% INIT_EPSILON is unrelated to EPSILON
Theta1 = rand(10,11) * (2*INIT_EPSILON) - INIT_EPSILON;
-Theta1 = rand(1,11) * (2*INIT_EPSILON) - INIT_EPSILON;
+Theta1 = rand(1,11) * (2*INIT_EPSILON) - INIT_EPSILON;
+
+load('ex3data1.mat');

0 comments on commit 5b92130

Please sign in to comment.
Something went wrong with that request. Please try again.