Programa para implementar a rede neural [fechada]

0

Eu encontrei um programa para implementar a rede neural. Mas dando um erro ..

x=np.array(([3,5], [5, 1], [10, 2]), dtype=float)
y=np.array(([75], [82],[93]), dtype=float)
x=x/np.amax(x, axis=0)
y=y/100
print(x)

class NeuralNetwork(object):

    def _init_(self):
        #Define Hyperparameters
        self.inputLayerSize=2
        self.hiddenLayerSize=3
        self.outputLayerSize=1


        #weight Parameters
        self.w1=np.random.randn(self.inputLayerSize, self.hiddenLayerSize)
        self.w2=np.random.randn(self.hiddenLayerSize, self.outputLayerSize)

    def forwardPropagation(self,X):
        self.z2=np.dot(X, self.w1)
        self.a2=self.sigmoid(self.z2)
        self.z3=np.dot(self.a2, self.w2)
        yHat=self.sigmoid(self.z3)
        return yHat

    def sigmoid(self,z):
        return 1/(1+np.exp(-z))

NN=NeuralNetwork()
YHat=NN.forwardPropagation(x)


Error: 
AttributeError                            Traceback (most recent call last)
<ipython-input-83-b2ae5338432a> in <module>()
      1 NN=NeuralNetwork()
----> 2 YHat=NN.forwardPropagation(x)
      3 #testInput=np.arange(-6,6,0.01)
      4 #plt.plot(testInput, NN.sigmoid(testInput), linewidth=2)
      5 #plt.show()

<ipython-input-82-5a9b5641f6b6> in forwardPropagation(self, X)
     13 
     14     def forwardPropagation(self,X):
---> 15         self.z2=np.dot(X, self.w1)
     16         self.a2=self.sigmoid(self.z2)
     17         self.z3=np.dot(self.a2, self.w2)

AttributeError: 'NeuralNetwork' object has no attribute 'w1'
    
por Diganta Kumar Pathak 16.03.2018 / 14:22

1 resposta

1

Você escreveu seu init errado. Deve ser sublinhados duplos como __init__

    
por Uduse 17.03.2018 / 08:32

Tags