def hypothesis(X,theta):
hx=np.dot(X,theta);
return sigmoid(hx);
def sigmoid(hx):
return 1.0/(1.0+np.exp(-1*hx));
def Gradient(X,theta,y):
m=X.shape[0]
hx=hypothesis(X,theta);
grad=np.dot(X.T,(hx-y))
return grad/m;
def error(X,theta,y):
m,n=X.shape;
hx=hypothesis(X,theta);
err=0;
for i in range(m):
err+=y[i]*np.log2(hx[i])+(1-y[i])*np.log2(1-hx[i]);
return -err/m;
def GradientDescent(X,y,iteration):
alpha=0.1;
m,n=X.shape;
theta=np.zeros((n,1));
err=[];
for i in range(iteration):
e=error(X,theta,y);
stepsize=alpha*Gradient(X,theta,y);
theta=theta-stepsize;
err.append(e);
return theta,err;
m,n=X_train.shape
ones=np.ones((m,1));
X_train=np.hstack((ones,X_train));
iteration=300;
theta,error=GradientDescent(X_train,Y_train,iteration);
# plt.plot(error);
error
this is taking much time to execute
please help where i am wrong??
also not plotting the error