Computer ScienceFoundation20 min read

Introduction to Artificial Intelligence and Machine Learning

What it means for a program to learn from data instead of being told the rules

This topic appears in:

01

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 programMachine learning
You supplyrules and datadata and answers
Computer producesanswersrules (a model)
Changing the behaviouredit the codesupply better data
Good atexact, defined tasksmessy patterns, images, language
Can explain itselfyes — read the codeoften not
02

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.

03

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.

Worked example

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.

  1. The gap between training and new performance is the signature of overfitting.A model that generalised would score similarly on both.
  2. 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.
  3. Collect more varied training data: different farms, lighting conditions, cameras and seasons.Variety forces the model to rely on what actually distinguishes the disease.
  4. 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.

04

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

  1. Traditional programming: rules in, answers out. Machine learning: answers in, rules out.
  2. AI ⊃ machine learning ⊃ deep learning — nested, not synonyms.
  3. Supervised uses labelled data; unsupervised finds structure; reinforcement learns from reward.
  4. Always keep a test set the model has never seen. Overfitting means it memorised instead of generalising.
  5. Bias comes from the data, not the code, and a black-box model cannot justify its decisions.
06

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.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
Differentiate between artificial intelligence and machine learning.
Model answer

Artificial intelligence is the broad field of making machines perform tasks that would ordinarily require human intelligence. Machine learning is a subset of AI in which the system learns patterns from data rather than being given explicit rules. All machine learning is AI; not all AI is machine learning.

Examiner tip. The containment sentence is usually the second mark. Saying which is the subset of which removes any ambiguity.

SQ2[2 marks]
What is supervised learning? Give an example.
Model answer

Learning from data in which each example is labelled with the correct answer. The model learns to reproduce those labels on new data. Example: training on photographs already tagged "cat" or "dog" so the system can classify unseen photographs.

Examiner tip. The word "labelled" is the mark. An example without it usually scores one.

SQ3[2 marks]
Why must a model be tested on data it has not been trained on?
Model answer

Because a model can score perfectly on data it has effectively memorised, which says nothing about how it will behave on new examples. Only unseen data measures whether it has learned the general pattern — the property that actually matters in use.

Examiner tip. Name overfitting as the failure being guarded against. That connects the practice to the reason for it.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
Describe the difference between supervised, unsupervised and reinforcement learning, giving one use of each.
Full working
  1. Supervised: trained on labelled data — for example spam detection from emails already marked spam or not[1]
  2. Unsupervised: trained on unlabelled data and finds structure itself — for example grouping customers into segments[1]
  3. Reinforcement: learns by acting and receiving rewards or penalties — for example a program learning to play a game[1]
  4. The distinguishing factor is what the training data contains: answers, no answers, or a reward signalthe unifying statement earns the fourth mark[1]

Labelled data, unlabelled data, and reward feedback respectively.

Examiner tip. Ending with the general principle — that the three differ in what the training data provides — shows you understand the classification rather than having memorised three examples.

N2[4 marks]
A bank uses a machine learning model trained on its past lending decisions to approve loans. Explain how bias could arise and state two ways to reduce it.
Full working
  1. The model learns the patterns in the historical decisions, including any that were unfair[1]
  2. If certain groups were refused disproportionately in the past, the model reproduces that pattern while appearing objectivethe appearance of objectivity is part of the harm[1]
  3. Reduce it by examining the training data for representativeness, and testing outcomes separately for each group[1]
  4. And by keeping a human decision-maker for consequential decisions, with a documented route to appealaccept requiring the model to be explainable[1]

The model learns historical unfairness. Audit the data, test outcomes per group, and keep human oversight.

Examiner tip. Say that bias comes from the data rather than the code. Answers proposing to "fix the algorithm" miss where the problem actually lives.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A school wants to use machine learning to predict which students are at risk of failing, so extra help can be offered.
  1. Describe the data the system would need and how it would be trained.
  2. Explain one way the system could produce unfair results.
  3. Explain why a teacher should review every prediction before action is taken.
Mark scheme
  1. Historical records of past students — attendance, assessment marks, homework completion — each labelled with whether that student ultimately passed or failedlabelled data, so this is supervised learning[1]
  2. The data is split into a training set and a test set; the model learns from the first and is measured on the second[1]
  3. Unfairness: if the historical data reflects a group that was under-supported in the past, the model predicts failure for that group and the prediction becomes self-fulfilling[1]
  4. Or: a feature that correlates with background rather than ability — such as distance travelled to school — drives the predictioneither example accepted[1]
  5. A prediction is a statistical likelihood about a group, not a fact about the individual student in front of the teacher[1]
  6. The model cannot explain its reasoning, and being labelled "likely to fail" could itself affect how a student is treated and how they see themselves[1]

(a) labelled historical records, split into training and test sets (b) it reproduces past under-support as a prediction (c) a prediction is about likelihood, not about the individual, and cannot justify itself

Examiner tip. The self-fulfilling prophecy is the strongest point available here: a student predicted to fail may be treated differently, which then makes failure more likely. Naming that effect lifts the answer well above a general privacy point.