What Is Training
How does a model go from guessing to knowing? Advitha, in San Francisco, is building a fruit-sorting app for a farmers' market stall. On day one, her model calls an apple "orange" more often than not. A week later, it is right almost every time. Nobody rewrote it by hand. It was trained.
Training is the process of adjusting a model's parameters so that its outputs match the examples it learns from. This lesson walks through the training loop, one step at a time.
The Training Loop
| Step | What happens | In the apple example |
|---|---|---|
| 1. Collect | Gather labeled examples | Thousands of fruit photos, each marked apple, banana or orange |
| 2. Feed | Give the model one example (or a small batch) | A photo of red apples |
| 3. Predict | The model makes its best guess | "Orange, 60%" |
| 4. Compare | Check the guess against the label | The label says "Apple": wrong |
| 5. Measure the error | Turn "how wrong" into a number | A large error |
| 6. Adjust | Nudge the parameters to reduce the error | "Apple" becomes a little more likely |
| 7. Repeat | Go back to step 2 with the next example | Thousands of rounds over all the photos |
This is a simplified picture of supervised learning, the kind from "Types of Machine Learning" where every example has a label. Real training feeds examples in batches, uses careful mathematics to decide each nudge, and runs for hours, days or weeks on specialized chips.
The Loop in Python
This tiny model sorts fruit by one number: how yellow the photo is, from 0 to 1. Its single parameter is a threshold: above it, the model says "banana". Watch the seven steps, marked in the comments:
# 1. Collect labeled examples: (how yellow the photo is, from 0 to 1, label)
examples = [(0.9, "banana"), (0.2, "apple"), (0.8, "banana"),
(0.35, "apple"), (0.7, "banana"), (0.45, "apple")]
threshold = 0.1 # the model's parameter: above it, predict "banana"
for round_number in range(1, 5): # 7. repeat
mistakes = 0
for yellow, label in examples: # 2. feed each example in
prediction = "banana" if yellow > threshold else "apple" # 3. predict
if prediction != label: # 4. compare with the label
mistakes += 1 # 5. measure the error
threshold = round(threshold + (0.1 if label == "apple" else -0.1), 2) # 6. adjust
word = "mistake" if mistakes == 1 else "mistakes"
print(f"Round {round_number}: {mistakes} {word}, threshold = {threshold}")Round 1: 3 mistakes, threshold = 0.4
Round 2: 1 mistake, threshold = 0.5
Round 3: 0 mistakes, threshold = 0.5
Round 4: 0 mistakes, threshold = 0.5The mistakes fall from 3 to 0, and the parameter settles at 0.5. Nobody chose 0.5; training found it. Once it stops changing, the model is trained. Each full pass over the examples is called an epoch; here, each round is one epoch.
Common Mistakes
Thinking training happens while you use a model. Training happens before release; using a model is inference, the next lesson's topic.
Thinking a model learns from one example. Each example nudges the parameters only a little; learning comes from many examples, many times over.
Thinking zero training mistakes means a perfect model. A model can learn its training examples by heart and still fail on new ones, as "Overfitting and Generalization" explains.
Interview Corner
What is training?
Adjusting a model's parameters so its outputs match the training examples. The model predicts, its prediction is compared with the label, the error is measured, the parameters are nudged to reduce it, and the loop repeats many times.
What is an epoch?
One full pass over all the training examples. Training usually runs for several epochs, with the error falling as the parameters improve.
Practice
Exercise: break the loop. Run the program, then change the starting threshold to 0.9. How many rounds does it take now, and where does the threshold settle? Then add a seventh example, (0.55, "apple"), and describe what happens. Write one sentence about why the examples matter as much as the loop.
Check your understanding:
- List the seven steps of the training loop in order.
- In the Python example, what is the parameter, and where did its final value come from?
- What is an epoch?
Key Takeaways
Quick reference
| Term | Meaning |
|---|---|
| Training | Adjusting parameters so outputs match the examples |
| Prediction | The model's guess for one example |
| Error (loss) | A number for how wrong a prediction was |
| Epoch | One full pass over all the training examples |
| Batch | A small group of examples processed together |
Was this tutorial helpful?