Why is my very simple neural network not doing at all well?
<p>I have created an extremely simple neural network to help my understanding. It has one neuron, and one input, and one weight. The idea is simple: given many random numbers between 0,200, learn that anything over 100 is correct, and under 100 is in correct (instead of just being told). </p>

<pre><code>import random

weight = random.uniform(-1,1)


def train(g,c,i):
    global weight
    weight = weight + (i*(c-g)) #change weight by error change 
    if(g==c):
        return True
    else:
        return False


def trial(i):
    global weight
    sum = i*weight 
    if(sum&gt;0):
        return 1
    else:
        return -1


def feedData():
    suc = 0
    for x in range(0,10000):
        d = random.randint(0,200)
        if(d&gt;100): #tell what is correct and not (this is like the dataset)
            correct = 1
        else:
            correct = -1

        g = trial(d)
        if(train(g,correct, d)==True):
             suc += 1


    print(suc)


feedData();
</code></pre>

<p>Out of 10000, I would expect at least 8000 to be correct. However, it always ranges between 4990 and 5100 success.</p>

<p>I obviously have a slight flaw in my understanding. Cheers for any advice.</p>

<p>This is mostly because of this line</p>

<p><code>
d = random.randint(0,200)
</code></p>

<p>By the problem itself, you have 50% chances to get the right number (>100). If you increase the maximum value from 200 to 500 as example, you'll get closer to what you want.</p>

<p>You need to find a better way to generate random number or to create your own algorithm for this.</p>

python machine-learning neural-network