What Is Training

Updated · 6 min read

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

Seven steps, repeated many times
StepWhat happensIn the apple example
1. CollectGather labeled examplesThousands of fruit photos, each marked apple, banana or orange
2. FeedGive the model one example (or a small batch)A photo of red apples
3. PredictThe model makes its best guess"Orange, 60%"
4. CompareCheck the guess against the labelThe label says "Apple": wrong
5. Measure the errorTurn "how wrong" into a numberA large error
6. AdjustNudge the parameters to reduce the error"Apple" becomes a little more likely
7. RepeatGo back to step 2 with the next exampleThousands 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:

Python
# 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}")
Output
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.5

The 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:

  1. List the seven steps of the training loop in order.
  2. In the Python example, what is the parameter, and where did its final value come from?
  3. What is an epoch?

Quick check: what is training

4 questions
1What does training change inside a model?
2What happens right after the model makes a prediction during training?
3In the Python example, what did training find?
4Why is the loop repeated many times?

Key Takeaways

Quick reference

TermMeaning
TrainingAdjusting parameters so outputs match the examples
PredictionThe model's guess for one example
Error (loss)A number for how wrong a prediction was
EpochOne full pass over all the training examples
BatchA small group of examples processed together

Was this tutorial helpful?

Lesson 18 of 186