Skip to content

Commit

Permalink
question 1
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Nov 6, 2011
1 parent 15329dc commit 5b92130
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions mlclass-ex3/mlclass-ex3/lrCostFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion octave_cheat_sheet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.