File tree 1 file changed +3
-5
lines changed
logistic_regression_class
1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change 36
36
ones = np .ones ((N , 1 ))
37
37
38
38
# add a column of r = sqrt(x^2 + y^2)
39
- r = np .zeros ((N ,1 ))
40
- for i in xrange (N ):
41
- r [i ] = np .sqrt (X [i ,:].dot (X [i ,]))
39
+ r = np .sqrt ( (X * X ).sum (axis = 1 ) ).reshape (- 1 , 1 )
42
40
Xb = np .concatenate ((ones , r , X ), axis = 1 )
43
41
44
42
# randomly initialize the weights
@@ -62,7 +60,7 @@ def cross_entropy(T, Y):
62
60
# else:
63
61
# E -= np.log(1 - Y[i])
64
62
# return E
65
- return (T * np .log (Y ) + (1 - T )* np .log (1 - Y )).sum ()
63
+ return - (T * np .log (Y ) + (1 - T )* np .log (1 - Y )).sum ()
66
64
67
65
68
66
# let's do gradient descent 100 times
@@ -71,7 +69,7 @@ def cross_entropy(T, Y):
71
69
for i in xrange (5000 ):
72
70
e = cross_entropy (T , Y )
73
71
error .append (e )
74
- if i % 100 == 0 :
72
+ if i % 500 == 0 :
75
73
print e
76
74
77
75
# gradient descent weight udpate with regularization
You can’t perform that action at this time.
0 commit comments