0

I am trying to run this code for simple Neural Network in python however an error is prompted saying " module 'numpy' has no attribute 'exe' ". I tried searching online but couldn't figure out where the problem is, here is the code:

import numpy as np

x=np.array([ [0,0,1],
           [0,1,1],
           [1,0,1],
           [1,1,1] ])
y=np.array([ [1,0,0,1]]).T

class NeuralNetwork(object):
def __init__(self):
    #parameters
    self.inputsize= 3
    self.outputsize= 1
    self.hiddensize=4
    self.learning_rate=0.005
    
    #(3x4) weight matrix from input layer to hidden layer
    self.w0= np.random.randn(self.inputsize, self.hiddensize) 
    #(4x1) weight matrix from hidden layer to output layer 
    self.w1=np.random.randn(self.hiddensize, self.outputsize)

def feedforward(self, x):  
    #forward propegation through the network
    self.z = np.dot(x, self.w0) #dot product with input and first set of weights
    self.z2= self.sigmoid(self.z) #activation function
    self.z3= np.dot(self.z2, self.w1) #dot product with hidden layer and second set of weights
    output= self.sigmoid(self.z3)
    return output
def sigmoid(self, s, deriv=False):
    if (deriv==True):
        return s*(1-s)
    return 1/(1+np.exe(-s))

def backward(self, x, y, output):
    #backward propegation through the network
    self.output_error= y - output #error in output
    self.output_delta= self.output_error * self.sigmoid(output, deriv=True)
    #hidden layer error & delta
    self.z2_error=self.output_delta.dot(self.w1.T)
    self.z2_delta=self.z2_error * self.sigmoid(self.z2, deriv=True)
    #updating weights
    
    self.w0 += self.learning_rate*(x.T.dot(self.z2_delta))
    self.w1 += self.learning_rate*(self.z2.T.dot(self.output_delta))
    
def train(self, x, y):
    output=self.feedforward(x)
    self.backward(x,y, output)

so far no errors, but when I run the loop

NN=NeuralNetwork()
for i in range(1000):
    NN.train(x,y)
    
print("predicted output:  " + str(NN.feedforward(x)))

the error prompted is

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-42-f9adb58b2d65> in <module>
      1 NN=NeuralNetwork()
      2 for i in range(1000):
----> 3     NN.train(x, y)

<ipython-input-39-83a1cb894a8f> in train(self, x, y)
     39 
     40     def train(self, x, y):
---> 41         output=self.feedforward(x)
     42         self.backward(x,y, output)
     43 

<ipython-input-39-83a1cb894a8f> in feedforward(self, x)
     15         #forward propegation through the network
     16         self.z = np.dot(x, self.w0) #dot product with input and first set of weights
---> 17         self.z2= self.sigmoid(self.z) #activation function
     18         self.z3= np.dot(self.z2, self.w1) #dot product with hidden layer and second set of weights
     19         output= self.sigmoid(self.z3)

<ipython-input-39-83a1cb894a8f> in sigmoid(self, s, deriv)
     22         if (deriv==True):
     23             return s*(1-s)
---> 24         return 1/(1+np.exe(-s))
     25 
     26     def backward(self, x, y, output):

~\anaconda3\lib\site-packages\numpy\__init__.py in __getattr__(attr)
    217                 return Tester
    218             else:
--> 219                 raise AttributeError("module {!r} has no attribute "
    220                                      "{!r}".format(__name__, attr))
    221 

AttributeError: module 'numpy' has no attribute 'exe'

This is my first post here so I apologize if there are any mistakes

1
  • 2
    typo. it should be np.exp and not np.exe Commented Oct 10, 2020 at 6:26

2 Answers 2

1

In Your sigmoid function you are using np.exe where it should be np.exp

Numpy doesn't have any function named exe so you are getting AttributeError

Sign up to request clarification or add additional context in comments.

Comments

0

Try this sigmoid function insted:

def sigmoid(self, s, deriv=False):
    if (deriv==True):
        return s*(1-s)
    return 1/(1+np.exp(-s))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.