python - Numpy Neural Network error:'NeuralNetwork' object has no attribute 'think' -
i interested in learning machine learnging, started clicking around. started following instructions , created code.
from numpy import exp, array, random, dot class neuralnetwork(): def __init__(self): # seed genarator random.seed(1) self.synaptic_weights = 2 * random.random((3,1)) - 1 def __sigmoid(self, x): return 1 /(1 + exp(-x)) def predict(self, inputs): return self.__sigmoid(dot(inputs, self.synaptic_weights)) def __sigmoid_derivative(self, x): return x * (x - 1) def train(self, trainingsetinputs, trainingsetoutputs, numberofiterations): iteration in range(numberofiterations): output = self.predict(trainingsetinputs) error = trainingsetoutputs - output adjustment = dot(trainingsetinputs.t, error * self.__sigmoid_derivative(output)) self.synaptic_weights += adjustment if __name__ == '__main__': # make 1 network neuralnetwork = neuralnetwork() print('random starting synaptic weights') print(neuralnetwork.synaptic_weights) # training data trainingsetinputs = array([[0,0,1], [1,1,1], [1,0,1], [0,1,1]]) trainingsetoutputs = array([[0,1,1,0]]).t #train network 10000 times neuralnetwork.train(trainingsetinputs, trainingsetoutputs, 10000) print('new wheights') print(neuralnetwork.synaptic_weights) # test network print("testing") print(neuralnetwork.think(array([1,0,1])))
i followed instuctions letter, maybe missed something? tutorial here.
edit: error got was: 'neuralnetwork' object has no attribute 'think'
you need create think() method. looking @ code should be:
def think(self, inputs): #pass inputs through our single neuron(our single neuron) return self.___sigmoid(dot(inputs, self.synaptic_weights))
do , you'll fine!
Comments
Post a Comment