mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-28 01:16:42 +00:00
requested changes addressed
This commit is contained in:
parent
ade3ed3784
commit
f018ddc4c0
@ -31,13 +31,13 @@ def sigmoid_function(z):
|
|||||||
def cost_function(h,y):
|
def cost_function(h,y):
|
||||||
return (-y*np.log(h)-(1-y)*np.log(1-h)).mean()
|
return (-y*np.log(h)-(1-y)*np.log(1-h)).mean()
|
||||||
|
|
||||||
# here alpha is the learning rate, X is the featue matrix,y is the target matrix
|
# here alpha is the learning rate, X is the feature matrix,y is the target matrix
|
||||||
def logistic_reg(alpha,X,y,max_iterations=70000):
|
def logistic_reg(alpha,X,y,max_iterations=70000):
|
||||||
converged=False
|
converged=False
|
||||||
iterations=0
|
iterations=0
|
||||||
theta=np.zeros(X.shape[1])
|
theta=np.zeros(X.shape[1])
|
||||||
|
|
||||||
num_iterations=0
|
|
||||||
while not converged:
|
while not converged:
|
||||||
z=np.dot(X,theta)
|
z=np.dot(X,theta)
|
||||||
h=sigmoid_function(z)
|
h=sigmoid_function(z)
|
||||||
@ -46,9 +46,9 @@ def logistic_reg(alpha,X,y,max_iterations=70000):
|
|||||||
|
|
||||||
z=np.dot(X,theta)
|
z=np.dot(X,theta)
|
||||||
h=sigmoid_function(z)
|
h=sigmoid_function(z)
|
||||||
e=cost_function(h,y)
|
J=cost_function(h,y)
|
||||||
print('J=',e)
|
|
||||||
J=e
|
|
||||||
|
|
||||||
iterations+=1 #update iterations
|
iterations+=1 #update iterations
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user