AttributeError: 'SigmoidNeuron' object has no attribute 'dw'

class SigmoidNeuron:

  def __init__(self):

    self.w = None

    self.b = None

  def perceptron(self,x):

    return (np.dot(x,self.w.T) + self.b)

  def sigmoid(self,x):

    return 1.0 / 1.0 + np.exp(-x)

  def grad_w(self,x,y):

    y_pred = self.sigmoid(self.perceptron(x))

    return (y_pred - y) * y_pred * (1-y_pred) * x

  def grad_b(self,x,y):

    y_pred = self.sigmoid(self.perceptron(x))

    return (y_pred - y) * y_pred * (1-y_pred) 

  def fit(self,X,Y, lr=0.1, epochs=10, initialise=True):

    if initialise:

       self.w = np.random.randn(1,X.shape[1])

       self.b = 0

    for i in range(epochs):

      dw=0

      db=0

      

      for x,y in zip(X,Y):

        dw += self.grad_w(x,y)

        db += self.grad_b(x,y)

      self.w -= lr*self.dw

      self.b -= lr*self.db

Hi @shreyasvalake,
dw and db are global scope, and will be same for all the instances of class.
Whereas, self.dw and self.db are different.
You can either initialise them to class attributes, or the global variables.
But keep in mind to use them the same way.

can you tell me where i need to make changes in code?

Here, just write dw instead of self.dw and do the same for db.