DL 103 Sigmoid neuron - TypeError: bad operand type for unary -: 'method'

[DL 103 Sigmoid neuron - TypeError: bad operand type for unary -: ‘method’ ]

I am just stuck here in this part of DL 103 where I am trying to run the fit function but I encounter a type error. Please see the Fit for toy data section in the following link for this type error.
https://colab.research.google.com/drive/1_qXjBTJOpO-nI_mUg2tOHyKBslUrtvKM

Kindly help me to fix the error.

X = np.asarray([[2.5, 2.5], [4, -1], [1, -4], [3, 1.25], [2, 4], [1, 5]])
Y = [1, 1, 1, 0, 0, 0]

sig_neu = SigmoidNeuron()
# fit function is called
sig_neu.fit(X, Y, 1, 0.25, True)

def sigmoid(self, x):
    # TypeError: bad operand type for unary -: 'method'  
    return 1.0 / (1.0 + np.exp(-x))

@4deep.prk There are 2 mistakes in your class methods.

def grad_w(self, x, y):
    y_pred = self.sigmoid(self.perceptron(x)) # fixed
    return (y_pred - y) * y_pred * (1 - y_pred) * x

  def grad_b(self, x, y):
    y_pred = self.sigmoid(self.perceptron(x)) # fixed
    return (y_pred - y) * y_pred * (1 - y_pred)

 def perceptron(self, x):
    return np.dot(x, self.w.T) + self.b # fixed

You didn’t pass the parameter x to the perceptron method. and also you need to take the transpose of the w in the perceptron method. then the problem will be over. I’ve fixed it for you in the colab ipynb file that you’ve given. Hope it helps.

1 Like

Thank you so much for pointing out the mistakes.