Codiqo

Understanding AI · lesson 13 of 60 · about 5 minutes

Training: Learning by Example

What actually happens when a model is trained, and what it ends up with afterwards.

What you'll learn

  • Explain what training a model means
  • Tell training apart from using a model
  • Explain why a trained model can handle new examples

Two stages

Machine learning happens in two stages.

Training: the model is shown lots of examples with their labels and adjusts itself until its guesses match the labels well.

Using it (often called inference): the trained model gets a new example, with no label, and makes its guess.

Like learning to recognise birds

Someone shows you hundreds of bird photos, telling you each name. At first you guess badly, then better. Later you spot a robin you've never seen before. You didn't memorise that robin: you learned what robins look like.

Training examples: each is a pair of features (weight in grams, how smooth the skin is from 0 to 10) and a label.

examples = [
    (150, 9, "apple"),
    (170, 8, "apple"),
    (140, 3, "orange"),
    (160, 2, "orange"),
]
for weight, smooth, label in examples:
    print(label, weight, smooth)

Output

apple 150 9
apple 170 8
orange 140 3
orange 160 2

Tip

Look at the smoothness column: apples are smooth, oranges are bumpy. That's the pattern a model would learn.

Now try it yourself

This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.