+2

Neural network not working

I made a neural network which takes 2 input and gives out a number. The output should be num1 - num2 But i am getting errors And [nan] as output . I had done almost everyrhing same as in tutorial given in python course neural network to predict number . I only changed inputs and outputs plz help https://code.sololearn.com/cUBhr3tkniM6/?ref=app

9/21/2019 6:28:33 PM

Devarsh Mavani

7 Answers

New Answer

0

Decrease the number of iteration.

+6

Try reducing the step size in the adjustment, your network is diverging.

+1

hahahaha *** , your totally right. i added a 0 to 0.01 to make 0.001 and i actually got output

0

I tried but then resut is not accurate I am posting code below . https://www.sololearn.com/learn/744/?ref=app In this it works fine even with 10000 itrrations . then why not in mine?

0

Its not my code and also it is already public You can find it under courses->python->more Or i am just pasting here from numpy import exp, array, random, dot class neural_network: def __init__(self): random.seed(1) # We model a single neuron, with 3 inputs and 1 output and assign random weight. self.weights = 2 * random.random((2, 1)) - 1 def train(self, inputs, outputs, num): for iteration in range(num): output = self.think(inputs) error = outputs - output adjustment = 0.01*dot(inputs.T, error) self.weights += adjustment def think(self, inputs): return (dot(inputs, self.weights)) neural_network = neural_network() # The training set inputs = array([[2, 3], [1, 1], [5, 2], [12, 3]]) outputs = array([[10, 4, 14, 30]]).T # Training the neural network using the training set. neural_network.train(inputs, outputs, 10000) # Ask the neural network the output print(neural_network.think(array([15, 2])))

0

i made this code a while ago, but instead of subtraction , its addition. https://code.sololearn.com/c8R7Cf4f4eyA/?ref=app edit: in java important edit: its not addition. given input : 10 and 20 my NNW multiplies both by 2 then adds them together, like so.... (2*10)+(2*20) = 60 ...... sorry its been awile since ive looked at this code

0

Thanks all for explaining now it is working