please check whats wrong in my code
import matplotlib.pyplot as plt
from sklearn.datasets import make_moons
X,Y = make_moons(n_samples=1000,shuffle = True,noise = 0.2,random_state=1)
plt.style.use(“seaborn”)
plt.scatter(X[:,0],X[:,1],c=Y,cmap=plt.cm.Accent)
plt.show()
#MODEL AND HELPER FUNCTION
def sigmoid(self):
return (1.0)/(1+np.exp(-z))
#IMPLEMENT PERCEPTRON LEARNING ALGO
#Learn the WEIGHTS
#REDUCE THE LOSS
#make the prediction
def predict(X,weights):
“”"X ->m*(n+1) matrix, weights -->(n1) vector"""
z = np.dot(X,weights)
predictions = sigmoid(z)
return predictions
def loss(X,Y,weights):
“”“Binary Cross Entropy is loss”""
Y_ = predict(X,weights)
cost = np.mean(-Ynp.log(Y_)-(1-Y)*np.log(1-Y_))
return cost
def update(X,Y,weights,learning_rate):
“”“perform weight updates for 1 epoch”""
Y_ = predict(X,weights)
dw = np.dot(X.T,Y_ - Y)
m = X.shape[0]
weights = weights - learning_rate*dw/(float(m))
return weights
def train(X,Y,learning_rate=0.5,maxEpochs=1000):
#modify the input to handle the bias term
ones = np.ones((X.shape[0],1))
X = np.hstack((ones,X))
#Init Weights 0
weights = np.zeros(X.shape[1]) #n+1 entries
#Iterate over all epochs and make updates
for epoch in range(maxEpochs):
weights = update(X,Y,weights,learning_rate)
if epoch%10==0:
l = loss(X,Y,weights)
print("Epoch %d Loss %.4f"%(epoch,l))
return weights
weights = train(X,Y,learning_rate=0.8,maxEpochs=1000)
ValueError Traceback (most recent call last)
in
----> 1 weights = train(X,Y,learning_rate=0.8,maxEpochs=1000)
in train(X, Y, learning_rate, maxEpochs)
30
31 for epoch in range(maxEpochs):
—> 32 weights = update(X,Y,weights,learning_rate)
33
34 if epoch%10==0:
in update(X, Y, weights, learning_rate)
13 “”“perform weight updates for 1 epoch”""
14 Y_ = predict(X,weights)
—> 15 dw = np.dot(X.T,Y_ - Y)
16
17 m = X.shape[0]
ValueError: operands could not be broadcast together with shapes (5,) (1000,)