One neuron

AI from scratch · 5 of a series

One neuron: lesson transcript

1. Two numbers in, one answer out

The café now records two things each day, temperature and hours of sun, and whether the day turned out busy or quiet. Tomorrow: 28° and 7 hours of sun. Busy or not? The answer is a yes-or-no, not a number, so a straight line through the points will not do.

2. A neuron

Here is the smallest thinking machine in AI. Each input is multiplied by a weight, the products are added together with a bias, and the total z is checked against zero. Positive means busy. That is all a neuron does.

3. The neuron is a line

Ask the neuron about every possible day and colour the ones it calls busy. The answer flips exactly where z = 0, and z = 0 is a straight line. A neuron does not see points; it makes one straight cut across the plane and says which side you are on.

4. Weights tilt, bias slides

The weights are an arrow pointing to the busy side, and the cut is always at right angles to it. Change the weights and the cut rotates; change the bias and it slides along the arrow without turning. Three numbers, one line.

5. Score it, then fix it

Start with a bad guess and count the days it gets wrong, ringed in amber. Then let the three numbers move, exactly as they did in gradient descent, until the wrong count falls to zero. Same recipe as before: score, slope, step.

6. Play with it

Find a cut with zero wrong days. Then find a second, quite different one that also scores zero. Several cuts work, which is worth remembering: the data never pins down the neuron completely.

7. Where one cut fails

A different café: it is busy only on mild, moderately sunny days, quiet when it is too cold, too hot, or too bright. The busy days sit in a ring of quiet ones. No straight cut can separate them. One neuron cannot learn this, no matter how it is trained. Next: what happens when you stack them.

8. Did it land?

Think about what each number does to the cut.

Check your understanding

You double all three numbers: w₁, w₂ and b. What happens to the cut?

The cut is where z = 0, and doubling every term doubles z, which is still zero in exactly the same places. Only the ratios of the three numbers decide the line; the overall size just changes how far from zero z gets.