lesson
50 min

A Single Neuron

An artificial neuron is weighted inputs, a sum, and a decision. Build one and watch it learn.

Objective

By the end of this lesson, you can describe what an artificial neuron computes and train one to learn a simple rule from examples.

What a neuron computes

An artificial neuron is a tiny math function, loosely inspired by brain cells. It is much simpler than a real brain cell. It does three things:

  1. Multiply each input by a weight (how much that input matters).
  2. Add them up, plus a bias (a starting nudge).
  3. Make a decision from the total. The simplest version says 1 if the total is above 0, otherwise 0.

That is the same idea as logistic regression from Module 11. A neural network is many of these, connected.

How it learns

The oldest learning rule is the perceptron rule, from the 1950s:

  • Make a prediction.
  • If it is wrong, nudge each weight in the direction that would have helped.
  • Repeat over all examples until there are no mistakes (or you stop).

The size of each nudge is the learning rate.

Run it. The neuron learns the AND rule: output 1 only when both inputs are 1. Then change the targets so it learns OR (output 1 when either input is 1).
Python 3
Ctrl+Enter to run | Tab to indent | Python runs in your browser via Pyodide

Each full pass over the data is called an epoch.

What one neuron cannot do

Try teaching it XOR: output 1 when exactly one input is 1. Change the targets to 0, 1, 1, 0 and raise the epochs to 100. It never stops making mistakes. A single neuron can only draw one straight line between the 1s and 0s, and XOR needs two. This limit, pointed out in 1969, is why we stack neurons into layers.

A national example

Reflection

Private. Saved only in this browser. No one else can see it.

Ask. Answer. Build together.