Skip to content

Commit b29deff

Browse files
committed
finish ex2
1 parent 1b75f38 commit b29deff

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

ML/ex2/costFunctionReg.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@
1818
% derivatives of the cost w.r.t. each parameter in theta
1919

2020

21+
H = sigmoid(X*theta);
2122

23+
reg = (sum(theta.*theta) - theta(1)*theta(1))*(lambda/(2*m));
2224

25+
J = (-1 / m) * (y' * log(H) + (1 - y)' * log(1 - H)) + reg;
2326

27+
grad = (H - y)' * X * (1/m);
28+
29+
for j=2:length(grad)
30+
grad(j) = grad(j) + (lambda/m)*theta(j);
31+
endfor
2432

2533
% =============================================================
2634

ML/ex2/ml_login_data.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created by Octave 3.6.2, Tue Sep 18 23:18:34 2012 CST <[email protected]>
1+
# Created by Octave 3.6.2, Wed Sep 19 16:38:15 2012 CST <[email protected]>
22
# name: login
33
# type: sq_string
44
# elements: 1

ML/ex2/predict.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
% You should set p to a vector of 0's and 1's
1616
%
1717

18-
19-
20-
18+
for i=1:m
19+
if(sigmoid(X(i,:) * theta) >= 0.5)
20+
p(i) = 1;
21+
end
22+
endfor
2123

2224

2325

0 commit comments

Comments
 (0)