Skip to main content

Lesson 4 — How a machine actually learns

"The machine learns" is a phrase that hides the mechanism. There is no magic in it, and no understanding either. There is a very large number of small numerical adjustments, repeated until the mistakes stop shrinking. This lesson walks through the loop, without a single equation.

The ingredients

Every supervised learning system has four parts, and it is worth naming them because the vocabulary comes up constantly.

The dataset — examples, each paired with the correct answer. Ten thousand photographs each tagged "cat" or "dog". Fifty thousand loan applications each tagged "repaid" or "defaulted".

The model — a mathematical function with adjustable dials. A simple model has a handful; a large language model has hundreds of billions. Those dials are called parameters or weights, and at the start they are set to random values, so the model's output is pure noise.

The loss function — a way to score how wrong the model is on an example. Predicting "dog" with 90% confidence on a cat photo produces a large loss. Predicting "cat" with 85% confidence produces a small one. The loss turns "being wrong" into a number you can act on.

The optimiser — the procedure that nudges every parameter in the direction that reduces the loss.

The loop

That loop runs thousands or millions of times. Nothing else happens. There is no moment of insight, no representation of "catness" being formed on purpose. There is a score being pushed downward, one small step at a time.

The analogy that makes it click

Picture yourself on a hillside in thick fog, trying to reach the valley floor. You cannot see the bottom. What you can feel is the slope under your feet. So you take a step in the steepest downhill direction, feel again, step again.

That is gradient descent, and it is genuinely all that training is. The "slope" is the direction in which changing each parameter would most reduce the loss. The size of your step is the learning rate — take steps that are too small and you never arrive; too large and you bound over the valley and end up on the opposite slope.

The fog matters in the analogy. The optimiser has no map of the whole landscape. It only knows the slope where it currently stands, which is why training can settle in a shallow dip rather than the true bottom, and why it does not always converge to the same place twice.

Why so much data

Here is where the data appetite becomes obvious. Each example provides one small correction to the parameters. A model with a million parameters and a thousand examples has far more dials than evidence: many different settings fit those thousand examples perfectly, and the model has no way to know which one reflects reality.

Give it a million examples and the contradictory settings get eliminated. Only configurations consistent with a large, varied body of evidence survive.

The order of magnitude

As a rough working rule, a classical model on tabular data needs hundreds to a few thousand rows. An image classifier trained from scratch wants thousands per class. A large language model is trained on trillions of words. If you have three hundred examples and someone proposes a deep network, the number of examples is the problem, not the architecture.

Overfitting, the failure that catches everyone

This is the single most important idea in this lesson, and it is the reason machine learning projects fail in ways that are invisible until it is too late.

A model can achieve perfect accuracy on its training data and be worthless on anything new. It happens when the model, rather than capturing the general pattern, memorises the specific examples — including their noise and their accidents.

The classic illustration: a model trained to distinguish wolves from huskies reached impressive accuracy. Inspection revealed it had learned to detect snow. Nearly every wolf photograph in the dataset had a snowy background, and nearly every husky photograph did not. On the training set the shortcut worked perfectly. On a husky in snow, it failed completely.

The model did nothing wrong. It found the easiest signal that separated the two piles. It was the dataset that was misleading.

How it is caught

The defence is procedural and non-negotiable: split the data before training.

  • Training set, around 70%: the model learns from this.
  • Validation set, around 15%: used to tune settings and decide when to stop.
  • Test set, around 15%: locked away and touched exactly once, at the very end.

If accuracy is 99% on the training set and 71% on the test set, the model has memorised rather than learned. That gap is the diagnostic.

SymptomDiagnosisUsual remedy
Poor on training, poor on testunderfitting — model too simplea richer model, better features
Excellent on training, poor on testoverfitting — memorisationmore data, simplify, regularise
Good on bothgenuine learningship it, then monitor
The mistake that invalidates everything

Looking at the test set to guide your choices destroys its purpose. Once you have used it to pick between two models, it has become a validation set and it no longer gives an honest estimate of real-world performance. Teams do this without noticing, and then wonder why production accuracy is ten points below the figure in the presentation.

Prediction, once training ends

Training is expensive and happens once, or occasionally. Inference — using the trained model — is cheap and happens constantly. The parameters are frozen; new input goes in, a prediction comes out in milliseconds.

Two consequences follow, and both surprise people.

A deployed model does not learn from use. Unless it is explicitly retrained, the version answering your query today is identical to the one shipped last month. It does not improve by being used.

A model decays without changing. The world moves: customer behaviour shifts, fraud patterns evolve, vocabulary drifts. The model stays where it was trained. This is drift, and it is why models are monitored and periodically retrained. The MLOps course is about exactly this problem.


In three sentences

Training is a loop that scores the model's mistakes as a number and nudges every parameter downhill against that score, millions of times, with no insight involved. It needs a lot of data because each example is only one small correction, and too few examples let the model memorise instead of generalise. That failure, overfitting, is only visible if you hold back a test set and never peek at it.


NextLesson 5: where AI is really used →