The difference from ordinary programming
In ordinary programming you write the rules and the computer applies them to data. To detect spam you would write conditions: if the subject contains "free money", if the sender is unknown, and so on. That works until spammers change their wording, which they do immediately.
Machine learning inverts the arrangement. You supply the data and the answers, and the program works out the rules. Show it fifty thousand emails already labelled spam or not spam, and it finds the patterns that separate them — including patterns nobody thought to write down.
Artificial intelligence is the wider field of making machines perform tasks that would need human judgement. Machine learning is the branch of AI that achieves this by learning from data, and deep learning is a branch of machine learning using large neural networks. They are three nested circles, not three synonyms.
| Traditional program | Machine learning | |
|---|---|---|
| You supply | rules and data | data and answers |
| Computer produces | answers | rules (a model) |
| Changing the behaviour | edit the code | supply better data |
| Good at | exact, defined tasks | messy patterns, images, language |
| Can explain itself | yes — read the code | often not |
Three ways a system learns
The syllabus names three kinds of learning, distinguished by what the training data contains.
- Supervised learning — the data comes with correct answers attached. Photographs labelled "cat" or "dog", houses labelled with their selling price. The model learns to reproduce the labels, and this is by far the most common kind.
- Unsupervised learning — the data has no labels, and the system finds structure by itself. Grouping customers into segments nobody defined in advance is the standard example; the groups are discovered, not specified.
- Reinforcement learning — the system acts, receives a reward or penalty, and adjusts. A program learning to play a game gets no instructions, only the score, and improves over millions of attempts.
Where the labels come from
Supervised learning needs data that someone has already labelled correctly, and the labelling is usually done by people. That is the real cost of most machine-learning projects: not the computing, but paying humans to look at fifty thousand images and say what is in each one. A question asking why a project is expensive is often asking about this.
Training, testing and what goes wrong
Data is split before training. The training set is what the model learns from; the test set is held back and used once, at the end, to measure how well it does on examples it has never seen.
Testing on the training data is meaningless — a model that has memorised its examples scores perfectly and may still be useless. That failure has a name: overfitting, where the model learns the noise and quirks of the training set rather than the general pattern, and performs badly on anything new. The opposite, underfitting, is a model too simple to capture the pattern at all.
A model trained to identify diseased leaves scores 99% on its training photographs but only 55% on new ones. Explain what has happened and what to do.
- The gap between training and new performance is the signature of overfitting.A model that generalised would score similarly on both.
- It has learned features specific to the training photographs — the background, the lighting, the particular camera — rather than the disease itself.Those features happened to separate the training examples, so the model used them.
- Collect more varied training data: different farms, lighting conditions, cameras and seasons.Variety forces the model to rely on what actually distinguishes the disease.
- Simplify the model, and verify on a test set kept entirely separate.A less flexible model has less capacity to memorise irrelevant detail.
Overfitting — it memorised the training photographs. Fix with more varied data and a held-back test set.
Bias, and why it is not a technical fault
A model learns whatever patterns are in its training data, including unfair ones. A recruitment model trained on a company's past hiring decisions learns those decisions — if the company historically hired few women, the model learns to score women lower, and does so while appearing objective because it is a computer.
This is not a bug to be fixed in code. The model is working correctly; the data described an unfair world and the model reproduced it. The remedies are all upstream: examine the training data for representativeness, test the model's outcomes separately for each group, and keep a human decision-maker for anything consequential.
The black box problem
A large model can make an accurate decision that nobody — including its creators — can explain. That is tolerable for recommending a film and unacceptable for refusing a loan or a medical treatment, where the person affected has a right to know why. "The system is very accurate" is not an answer to "why was I refused", and exam questions about AI in medicine or finance are usually pointing here.
Before you leave this chapter
- Traditional programming: rules in, answers out. Machine learning: answers in, rules out.
- AI ⊃ machine learning ⊃ deep learning — nested, not synonyms.
- Supervised uses labelled data; unsupervised finds structure; reinforcement learns from reward.
- Always keep a test set the model has never seen. Overfitting means it memorised instead of generalising.
- Bias comes from the data, not the code, and a black-box model cannot justify its decisions.
Seeing overfitting happen
Overfitting is easy to state and hard to picture, which is why students recognise the definition in a question and still cannot say what to do about it. Drawn, it becomes obvious: the model that scores best on the training data is not the one that has learned the pattern.
Choose Overfit with Training data — it looks like the best of the three. Now switch to New data without changing the model. The twists were fitted to noise that never repeats, and the boundary now cuts straight through both clusters.
How you detect it in practice
Compare the score on the training set with the score on the held-back test set. Similar scores mean the model generalises, whatever the numbers are. A large gap — excellent on training, poor on test — is overfitting, and no amount of further training fixes it. The remedy is more varied data or a simpler model, not more epochs.