← ⚙️ Inside AI

Inside AI · Topic 5 of 10

Training and testing a model

Data is split into training, validation and test sets. We measure accuracy and loss, and watch out for overfitting and underfitting.

📌 Key points

  1. Data is usually split into three sets: a training set (the model learns from it), a validation set (to check progress and tune settings) and a test set (a final check on data never seen).
  2. Most data goes to training, e.g. about 70% training, 15% validation and 15% test.
  3. Accuracy = correct predictions ÷ total predictions, often given as a percentage.
  4. Loss is a number that measures how wrong the predictions are. Training tries to make the loss as small as possible.
  5. One full pass through all the training data is called an epoch. Training often takes many epochs.
  6. Overfitting: the model learns the training data too closely, even its mistakes and odd details. It scores well in training but badly on new data, like memorising practice answers.
  7. Underfitting: the model is too simple or has not trained enough. It does badly even on the training data.
  8. Good data matters: more examples, many different kinds, correct labels and a fair mix. "Garbage in, garbage out."

📖 Key words

Training set
The data the model learns from.
Validation set
Data used during development to check progress and choose settings.
Test set
New data kept back until the end, to check how well the model really works.
Accuracy
The fraction (or percentage) of predictions that are correct.
Loss
A number that measures how wrong the model's predictions are.
Overfitting
When a model learns the training data too closely and does badly on new data.
Underfitting
When a model is too simple to learn the patterns, even in its training data.

✏️ Worked example

A model scores 99% accuracy on its training data but only 60% on the test set. What is going on, and what can be done?

  1. There is a big gap between training (99%) and test (60%), so the model does well on examples it has seen but not on new ones.
  2. This is overfitting: it has memorised the training examples instead of learning general patterns.
  3. Fixes: collect more, and more varied, training data; use a simpler model; or stop training earlier, when the validation score stops improving.
  4. After the changes, check again on the test set. A good model scores well on both.
💡 Remember

Remember: never judge a model only on the data it trained on. The real test is new data.

Test yourself8 questions from a bank of 19. A new mix every time.
Start the quiz →

It’s bedtime! 😴

It’s late, and even Numo is getting sleepy. The best thing you can do for your learning now is… go to sleep!

✨ Sleep helps you

  • 🧠 remember what you learned today: your brain saves it while you sleep
  • 🌱 grow and stay healthy
  • ⚡ wake up with energy, ready to learn and play
  • 😊 feel happy and calm

🦉 Going to bed late can make you

  • 😩 tired and sleepy at school tomorrow
  • 🤯 find it harder to focus and to remember
  • 😠 grumpy and easily upset
  • 🤧 catch colds more easily

Children your age need 9 to 12 hours of sleep every night. Numo will be right here tomorrow!