The training loop, three ways to learn, neural networks, and overfitting
Overview
In Lesson 1.1 you saw that a machine learning model learns from examples instead of following a rule. This lesson opens the box: what "learning" means for a computer, the three main ways models learn, what a neural network is, and the most common way learning goes wrong. About 15-20 minutes.
By the end of this lesson you can:
Describe training as: guess, compare with the answer, adjust, repeat.
Explain supervised, unsupervised and reinforcement learning in one line each.
Describe a neural network as layers that build simple features into complex ones.
Explain overfitting with the exam-cramming analogy.
A model is a machine with knobs
Picture a machine that takes in a chest X-ray and puts out a number between 0 and 1: how likely it is that the film shows a pneumothorax. Inside are a huge number of adjustable knobs, called parameters. Each knob changes how much attention the machine pays to some part of the image.
At the start the knobs are set randomly, so the answers are random too. Training is the process of turning the knobs, a tiny bit at a time, until the answers match the labels. PTX-Detect, like most image models, has millions of knobs. Nobody turns them by hand; the computer does it automatically.
The training loop
Step through how PTX-Detect is trained. The same four steps repeat thousands of times.
Step through
1. Guess
Model's guess
True label
The untrained model looks at an X-ray from the training set and gives a score: 0.30, "probably no pneumothorax."
Its knobs are still random, so this is basically a guess.
2. Compare with the answer
Model's guess
Error
The label, written by a radiologist, says this film does show a pneumothorax (1.0).
The gap between guess and label is the error: 1.0 − 0.30 = 0.70. Big error, big lesson.
3. Adjust the knobs
Before
After
The computer works out which knobs pushed the answer the wrong way and nudges each one slightly in the right direction.
If it saw the same film again, it would now say 0.36. A small step, on purpose: big jumps would make it forget what it learned from other films.
4. Repeat, many times
Round 1
Round 1,000
Round 50,000
Bars show the share of training films it gets wrong.
Next film, and the next. Guess, compare, adjust, tens of thousands of times, cycling through the whole training set again and again.
Slowly the knobs settle into a pattern that gives the right answer for most films.
5. Check on films it has never seen
Training films
New films
Doing well on the films it practiced on proves little. The real question is how it does on new films. A bit worse is normal. Much worse means it memorized instead of learning (see overfitting below).
Try it yourself (about 3 minutes): open Teachable Machine, choose "Image Project", and train a model with your webcam: for example, class 1 is you holding a pen, class 2 is you without one. Give it 30-50 pictures of each, press Train, and test it. You have just run the training loop. Keep the tab open: in Lesson 1.5 you will try to fool it.
Optional: TensorFlow Playground lets you watch a small network train in your browser.
Three ways to learn
Supervised learningLearns from examples that come with the right answer (labels). PTX-Detect is supervised: every training X-ray was labeled pneumothorax yes or no. Real example:detecting diabetic retinopathy from graded retinal photos.
Unsupervised learningGets data with no labels and finds groups or patterns on its own. Real example: grouping ICU patients into four sepsis phenotypes that nobody had defined beforehand.
Reinforcement learningLearns by trial and error, getting a reward for good outcomes, like learning a game. Real example: the "AI Clinician", which learned fluid and vasopressor strategies in sepsis from past ICU records.
Interactive: which kind of learning?
Drag each project into the kind of learning it uses. On a phone, tap a card and then tap a box.
10,000 wrist X-rays, each marked "fracture" or "no fracture" by a radiologist
Thousands of lung CT scans with no labels, sorted by the program into groups that look alike
A program that tries different scan settings and gets a reward when the image is clear at a low radiation dose
Mammograms paired with whether the woman was diagnosed with cancer within a year
Health records of 20,000 ICU patients, grouped into types nobody had defined before
A program that learns when to give fluids in sepsis by trying choices on past records and scoring the outcome
Supervisedexamples with the right answer
Unsupervisedno answers; finds groups
Reinforcementtrial, error and reward
Most radiology AI you will meet is supervised. That is why labels matter so much, which is the topic of Lesson 1.3.
Neural networks and deep learning
A neural network is a particular design for the knob machine. It is built in layers. Each layer takes what the layer before found and combines it into something a little more complex. With images it works roughly like this:
Figure 1. Layers build simple features into complex ones. Simplified: real networks do not label their layers this neatly.
"Deep" learning just means a network with many layers. Nobody tells the layers to look for edges or ribs; that structure emerges during training. Two names you will hear:
Convolutional neural networks (CNNs) are designed for images. They scan small patches across the picture, which suits X-rays, CT and MRI.
Transformers are the design behind large language models such as ChatGPT, and they are now also used for images.
Watch the StatQuest video first. The 3Blue1Brown video goes deeper into how layers work; watch it if you want the full picture.
Overfitting: memorizing instead of learning
You know two kinds of exam preparation. One student understands the topic. Another memorizes the answers to last year's practice questions. Both ace the practice set. Only one passes the real exam.
Models can do the same thing. With millions of knobs, a model can memorize the exact training films, including irrelevant details, instead of learning what a pneumothorax looks like. This is called overfitting. The model looks excellent on its training data and disappoints on new patients.
Figure 2. Training errors keep falling. Errors on new data fall and then rise once the model starts memorizing. Developers stop training near the lowest point of the dashed line.
This is why a model must always be tested on data it never trained on. How that data is set aside is covered in Lesson 1.3.
Knowledge check
Answer each question to continue. Any answer is fine; read the explanation.
Which order describes one round of training?
The model first guesses, then the guess is compared with the label to get the error, then the knobs are nudged to reduce that error, and the loop repeats with the next example.
Which type of learning needs every training example to come with the right answer?
Supervised learning learns from labeled examples, like PTX-Detect's X-rays marked yes or no. Unsupervised learning has no labels, and reinforcement learning learns from rewards rather than answers.
A model scores 100% on its training films but only 60% on new films. What most likely happened?
A large gap between training and new data is the classic sign of overfitting. The model memorized its practice set instead of learning a pattern that carries over to new patients. Adding knobs usually makes this worse.
Key takeaways
A model is a machine with many adjustable knobs (parameters). Training turns them until its answers match the labels.
The training loop: guess, compare, adjust, repeat.
Supervised learning uses labels; unsupervised finds groups; reinforcement learns from rewards. Most radiology AI is supervised.
Neural networks build simple features into complex ones, layer by layer. "Deep" means many layers.
Overfitting is memorizing instead of learning. Only testing on new data reveals it.