How Machine Learning Works

Follow how machine learning models learn from data, make predictions and are tested on new examples.

About 3 min read
  • Describe how supervised machine learning works
  • Explain training data, features and labels
  • Explain why a model is tested on unseen data
  • Identify overfitting
Before you start

You know that an algorithm follows rules. In machine learning, a program finds patterns from data instead of following only hand-written rules.

Learning from examples

Machine learning builds a model that finds patterns in data. In supervised learning, the training data contains examples with correct answers. A spam filter, for example, studies emails labelled spam or not spam. The model adjusts its internal values to reduce its errors, then uses the patterns it learned to make predictions.

Definition: feature

A measurable input used by a model, such as the number of links in an email.

Definition: label

The correct output in a training example.

Training and testing

We split data into a training set and a test set. The model learns from the training set. The test set is kept aside so that we can measure how well the model handles new data. Training accuracy alone can be misleading.

Definition: overfitting

When a model learns details of the training data so closely that it performs poorly on new data.

Spot overfitting

A model scores 99% on training data but only 62% on test data. What does this suggest?

It works very well on known examples.

It works much less well on new examples.

Answer: The model has probably overfitted, so it has not generalised well.

Data shapes results

A model learns from the data it receives. Biased or unrepresentative data can produce unfair predictions.

Exam focus
Say it like this“Unseen test data shows whether the model can generalise.”
Not like this“Test data checks the code.” — Refer to performance on new data.
Common mistakeMeasuring a model only on the same data used to train it.

Practice

What is a label in supervised learning?
The correct answer attached to a training example.
Give one possible feature for predicting house prices.
Floor area, number of rooms or location.
Why is a test set kept separate?
So that the model can be measured on data it did not learn from.
Going further
A loan model is trained mostly on applicants from one city. Explain one risk of using it in another city.
The data may not represent the new population, so predictions could be less accurate or unfair.

Quick check

Machine learning quick check

What does a model learn from?

Training examples let it adjust internal values and improve its predictions.

What is overfitting?

The model memorises details and fails to generalise to fresh examples.

What might biased training data cause?

A model repeats patterns in its data, including patterns that disadvantage some groups.
Key takeaways
  • Machine learning finds patterns in data.
  • Supervised learning uses features and labels.
  • Test data shows whether a model generalises.
  • Biased data can lead to unfair results.