Unit 7 · Machine Learning and Artificial Intelligence
7-1 The Basics of Machine Learning
How do you teach a computer to tell a cat from a dog when you cannot write down a rule for it? You do not write the rule — you show it thousands of examples and let it find the rule itself. That is machine learning, the engine behind most of today's AI. It learns patterns from data to make judgments on new data. Yet it is not magic: if the examples are biased, the judgments are biased, and its reasoning can be a black box even to its makers. Machine learning is therefore best used to support human judgment, not to replace it.
Guiding question
How does machine learning solve problems differently from ordinary programming, and what are its main types and limits?
Learning outcome. Explain the idea of machine learning and distinguish supervised, unsupervised and reinforcement learning, describe classification, clustering and reinforcement learning with examples, and explain the limits caused by data bias and the black-box problem.
1 · What it is
Machine learning is a technology that learns patterns and regularities from large amounts of data so that judgments and predictions can be made on new data. It is the most common method used to make AI work.
2 · How it differs from ordinary programming
| Approach | What humans provide | What the computer does |
|---|---|---|
| Conventional programming | Decision rules (procedures) and input data | Produces answers by following the rules |
| Machine learning | Large amounts of data (with correct answers, where available) | Finds the decision rules from the data on its own |
Read the two rows against each other. In one, the rules go in. In the other, the rules come out. That reversal is the whole idea.
3 · What it is for
Machine learning is used for problems where it is difficult for humans to express the rules in words: judging whether a photo shows a dog or a cat; distinguishing whether an email is spam; transcribing audio into text. For such problems the rules are too complex to write out completely, so letting the computer learn from examples becomes effective.
4 · And what it is not
Machine learning is not a panacea. Because the quality and bias of the training data affect the results, biased data leads to biased judgments (bias). There is also the black-box problem, in which the basis for the model’s judgments becomes hard for humans to see. Given these limitations, it is important to use machine learning not as a replacement for human judgment, but as a tool that supports it.
Before the reversal, one more picture. The book gives the three kinds of learning as a table of three rows, and the rows all look alike. Here they are instead as the same six emails, learned three different ways — so the only thing that changes is what the learner was handed.
Step 1 of 7 — The same six emails, every time
Six emails, placed along a line by how many suspicious words each contains. The three on the left have few; the three on the right have many. Nothing about these six will change for the rest of this animation. The ONLY thing that changes is what the learner is given alongside them.
The exam question is almost always “which method suits this situation?”, and it is answered by asking what you have been given, not what you want. Past data with answers → supervised. Data without answers → unsupervised. Only the ability to try things and see how they turn out → reinforcement. And remember the grey frame: clustering finds the groups and cannot tell you what they are.
Do not try to remember which method goes with which situation. Ask instead: what was the learner given?
Given the answers too → supervised learning; it can learn to predict them. Given the data only → unsupervised learning; it can find groups, but it cannot name them. Given no answers, but a reward after acting → reinforcement learning; it learns which actions pay.
The grey frame in the animation is the one students most often get wrong. Clustering finds two piles and has no idea which pile is spam. Somebody has to look.
The table you have just read is the most important thing in this lesson, and it is very easy to read it without seeing what it says. Look again at the two rows and ask: which column did “the rules” move to?
Step 1 of 5 — The ordinary way to use a computer
In normal programming YOU supply two things: the data, and the rules for what to do with it. The computer follows your rules and hands back the answers. Every program you have ever used works this way — a calculator, a game, a website.
If you can state the reversal in one sentence — “normally you give the rules and get answers; in machine learning you give answers and get the rules” — you have the guiding question of this lesson, the book’s table on page 58, and half of the exam-style answer. The other half is the price: bias and the black-box problem.
The book’s wording, which is what an exam wants: Information in the training data that serves as a clue useful for prediction is called a feature. (p.60)
🧮 Is this a good feature? — testing two clues on the same twenty emails
- 1
Take the 20 emails above. You already know which 10 are spam, because people labelled them.
Why this step: This is supervised learning, so the answers come with the data. You need them for two separate purposes: to find a rule in the first place, and — the part people forget — to measure whether the rule you found is any good.
- 2
Pick the first clue, “number of suspicious words”, and try a boundary: 5 or more = spam.
Why this step: Classification “draws a boundary between labelled groups” (p.60). On a single clue, a boundary is nothing more exotic than one number to compare against.
- 3
Count how many of the 20 that boundary gets right: 20 out of 20 = 100%.
Why this step: Accuracy is simply how many it got right divided by how many there were. Check the spam AND the normal mail: all 10 spam emails have 5 or more suspicious words, and all 10 normal ones have 4 or fewer.
Most people slip here: Always check both groups. A lazy rule that shouts “spam!” at every single email gets all 10 spam right and would look impressive if you only counted those — while being completely useless. It scores 10/20, which is the number to beat.
- 4
Now do exactly the same with the second clue, “length of the body”. The best boundary possible is 8 lines or more, and it gets 11 out of 20 = 55%.
Why this step: Same twenty emails, same method, same effort — only the clue has changed. And the result has collapsed from 100% to barely better than the 50% you would get by calling everything spam.
Most people slip here: This is not because the boundary was chosen badly. Every possible boundary was tried and 11/20 is the best any of them can do — long and short emails simply are not sorted by whether they are spam.
- 5
Conclude: the clue mattered far more than the method.
Why this step: Nothing about the algorithm changed between those two tests. This is what page 60 means when it says the choice of features greatly affects accuracy — and it is why a real project spends most of its time deciding what to measure, not which clever technique to use.
Where the comparison breaks down: A trainee doctor can be asked “why did you say that?” and will answer. A trained model cannot — which is the black-box problem the animation ends on, and the reason the book insists machine learning should support human judgment rather than replace it.
Notice that nothing here was a programming mistake. The model did exactly what it was asked to do — find whatever separates the two labelled groups — and the marker genuinely did separate them. This is bias and the black-box problem arriving together: a clue nobody intended, and no way to notice from the accuracy score alone.
A widely cited failure mode in medical-imaging research; variations of it have been reported in several published studies.
1 · Told apart by the data they are given
| Learning method | Data given | What is learned |
|---|---|---|
| Supervised learning | Pairs of input and the correct answer (label) | Rules for predicting the correct answer from the input |
| Unsupervised learning | Input only (no correct answers) | Hidden structure or groups in the data |
| Reinforcement learning | Actions and their results (rewards) | How to choose actions to obtain better results |
2 · Which one to use
The method is decided by the type of data at hand and the nature of the problem. Past data has correct answers and you want to predict for new data → supervised. Data is available without correct answers and you want to find tendencies or groups → unsupervised. You want the system to learn how to choose actions for better results through trial and error → reinforcement.
1 · Classification — the representative supervised task
Classification predicts which type (class) the input data belongs to. Sorting emails into “spam” or “normal”; sorting medical images into “abnormal” or “normal”; classifying animals in photos as “dog”, “cat” or “bird”.
Large amounts of data with correct answers (labels) attached are given in advance for learning. After training is complete, the model can predict which class new data without known labels belongs to.
Training
Find rules for classification from pairs of input data and correct answers (labels)
Prediction
Use the learned rules to determine which class new data belongs to
2 · Features, and why the choice matters
Information in the training data that serves as a clue useful for prediction is a feature. In spam classification, the types of words contained in the email, the sender’s address, and the length of the body are features. The choice of features greatly affects the accuracy of classification — choosing features that match the purpose is important for building a good model.
Same twenty emails, two different clues — and then the labels taken away
Twenty emails. Ten really are spam and ten really are not.
Nobody can write a rule for “spam” in words. So instead, choose a feature — a clue in the data — and let the computer find the rule itself.
Look at the spread before pressing anything. Using the suspicious words, could you draw one vertical line that puts all the red on one side and all the blue on the other?
3 · Clustering — the representative unsupervised task
Clustering groups similar items together into groups (clusters) within data. Grouping users of an online shop by similar purchase tendencies; grouping users with similar listening patterns on a music streaming service; automatically grouping news articles with similar content.
| Method | Correct answers (labels) | Purpose |
|---|---|---|
| Classification | Given in advance | Predict which class new data belongs to |
| Clustering | Not given | Find natural groups within the data |
In clustering the computer itself finds “what is similar”. Even when the names or number of groups are not known in advance, grouping can be done automatically from the features of the data. It is used to grasp the overall picture, or to look at data from a new perspective — and humans interpret the results and use them in marketing, product development and so on.
1 · Learning from what happens next
Reinforcement learning is a method in which actions are chosen in a certain situation, and how to choose better actions is learned based on the reward obtained as a result. Learning how to get a high score in a game through trial and error; a robot learning to walk without falling by trying movements; a self-driving car learning safe driving operations.
2 · Three elements
| Element | Description |
|---|---|
| State | The situation in which the agent (the learning side) is placed |
| Action | The choices that can be selected in that situation |
| Reward | The evaluation given as a result of the action (a numerical value indicating goodness or badness) |
Learn something with nobody to tell you the answer
Three ways to walk home. Nobody will ever tell you which is best.
There is no correct answer to learn from — but after each walk you know how long that one took. That is the reward: not an answer, just an evaluation of what you did.
State
standing at the school gate, needing to get home
Action
which of the three routes you choose
Reward
the minutes it took — lower is better
Take a route. Then take it again, and take the others — you cannot learn anything from a route you never tried.
3 · What makes it different from the other two
What distinguishes reinforcement learning is that it learns from the consequences of its own actions. Unlike supervised learning, where there is a correspondence of “this input has this correct answer”, reinforcement learning gradually learns better choices from the rewards obtained for the actions it tries.
4 · And when it suits
It is suited to problems where the correct answer is not known in advance, but the goodness of the result can be judged. It is often used in combination with environments where trial and error can be repeated — simulators or games.
How the real paper is built
The ministry sets half multiple choice and half written answer in every subject. The two halves are not the same skill. In the multiple-choice half you have to spot the wrong options quickly — and the wrong options are built out of the mistakes students really make. In the written half nobody gives you the answer to recognise; you have to produce it, in your own words, with a reason.
Practise both. Being good at one half and weak at the other costs you exactly half the paper.
- machine learning
- — learning rules from data to judge new data.
- supervised learning
- — learns from labelled examples.
- unsupervised learning
- — finds groups with no labels.
- reinforcement learning
- — learns actions from rewards.
- label
- — the known correct answer attached to training data.
- classification
- — predict which class an input belongs to.
- feature
- — a clue in the data useful for prediction.
- clustering
- — group similar items with no labels.
- state
- — the situation the agent is placed in.
- action
- — the choices selectable in that situation.
- reward
- — a value scoring how good an action was.
- bias
- — skewed data leading to skewed judgments.
- black-box problem
- — the basis of a judgment being hard to see.
Worked Example
(1) Mark each statement with ○ if it is true or × if it is false.
A Machine learning is a technology that learns patterns and regularities from large amounts of data so that judgments and predictions can be made on new data.
B In supervised learning, the model learns from data without correct answers (labels).
C Clustering is a method that groups data according to labels given in advance.
D Reinforcement learning is a method in which how to choose better actions is learned based on the reward obtained as a result of an action.
(2) Match each description with a term: A Feature, B Supervised learning, C Clustering.
a A learning method that learns rules for predicting correct answers for inputs from pairs of input and correct answer
b A method that finds groups of similar items from data without correct answers
c Information in the input data that serves as a clue for prediction in classification
1 · Answer the following questions.
2(1) · Which is NOT an appropriate situation in which machine learning is used?
Mark ○ for the tasks machine learning suits, and × for the one it does not.
Distinguishing the type of animal in a photograph.
Transcribing audio into text.
Calculating the sum of two integers.
Distinguishing whether an email is spam.
2(2) · Choose the most appropriate learning method for each purpose.
Match each description with the choice that fits it.
Predict, from past purchase history data and whether or not a purchase was made, whether a new customer will buy the product.
Find groups of customers with similar purchase tendencies from customer purchase data.
Have a robot walk and learn movements that allow it to advance without falling through trial and error.
2(3) · Which most appropriately describes the difference between classification and clustering?
Mark ○ for the correct description, and × for the ones that name the wrong difference.
Classification divides data into a small number of groups, and clustering divides data into many groups.
Classification handles only numerical data, and clustering handles only text data.
Classification learns from data with correct answers (labels), and clustering learns from data without correct answers.
Classification is unsupervised learning, and clustering is supervised learning.
2(4) · Which is NOT an appropriate point of caution when using machine learning?
Mark ○ for the real cautions, and × for the one that is not.
If the training data is biased, the model’s judgments may also be biased.
The basis for a machine learning model’s judgments may be hard to see, so for important judgments human checking is needed.
Machine learning is a panacea and can make more accurate judgments than humans on any problem.
It is important to use machine learning as a tool that supports human judgment.
Think as an Engineer — Investigate & Decide
Your school has years of data and wants help with two tasks: (i) flagging students who may need extra support early, and (ii) discovering natural groups of study habits it did not know about. You advise on how to use machine learning responsibly.
1 · Identify the method.
For task (i) and task (ii), name which learning type fits (supervised, unsupervised or reinforcement). For each, name one piece of data the school would need to collect, and one kind of student that data might miss.2 · Analyze the risks.
Name one way the training data for task (i) could be biased — for example if it only includes students who already asked for help — and say what harm the black-box problem could cause if a teacher acts on a flag without understanding it. This is a judgment the lesson’s tables do not make for you.3 · Decide the role of the human.
State which decisions you would keep a human in charge of, and which you would let the model assist with, and why. In pairs, compare plans and agree on the one safeguard you would never remove.
In a New Context
A bank wants software that reads each loan application and flags the risky ones for a human officer to review. Name which learning type this is, name one feature the model might use, and explain why the officer must stay in the loop rather than letting the model decide alone.
Lesson Question — Answered
In conventional programming, humans provide the rules and the computer follows them; in machine learning, humans provide data and examples and the computer finds the rules itself — which is why it suits problems whose rules are too complex to write, like recognising images or speech.
It comes in three types: supervised learning (labelled examples, whose representative task is classification, using features to predict a class), unsupervised learning (no labels, whose representative task is clustering, finding natural groups), and reinforcement learning (learning from rewards through trial and error, described by state, action and reward).
Its limits matter as much as its power: results depend on the quality and bias of the data, so biased data gives biased judgments, and the black-box problem hides the basis of a decision. For these reasons machine learning is best used to support human judgment, not to replace it.
2 · Read the passage and fill in the blanks (a)–(g).
Machine learning is a technology that learns patterns and regularities from large amounts of data so that judgments and predictions can be made on new data. It is broadly divided into three types depending on the form of data given and the method of learning. There is ( a ) learning, which learns from pairs of input and correct answer; ( b ) learning, which finds structure or groups from data without correct answers; and ( c ) learning, which learns how to choose better actions based on the ( d ) obtained as a result of an action. In ( e ), a representative example of supervised learning, the choice of ( f ), which serves as a clue for prediction, greatly affects the result. In ( g ), a representative example of unsupervised learning, the computer itself finds “what is similar” and discovers natural groups.
3(1) · Which most appropriately describes the difference between conventional programming and machine learning?
Mark ○ for the correct description, and × for the others.
In conventional programming, humans provide the decision rules; in machine learning, the computer finds the decision rules from data on its own.
Conventional programming requires large amounts of data, and machine learning requires only rules.
Conventional programming is included in AI, but machine learning is not included in AI.
Conventional programming can handle new problems, but machine learning can handle only fixed problems.
3(2) · For each situation, which term applies?
Match each description with the choice that fits it.
There are large amounts of news article texts and their categories, and you want to automatically determine the category of new articles.
You have records of products purchased by users of an online shop and want to find groups of users with similar purchasing tendencies.
You want a computer to play a game and learn the operations that lead to high scores through trial and error.
3(3) · Which is NOT an appropriate description of the characteristics and limitations of machine learning?
Mark ○ for the accurate descriptions, and × for the one that is not.
Machine learning is used for problems where it is difficult for humans to express the rules in words.
Machine learning models are affected in their results by the quality and bias of the training data.
A machine learning model’s basis for judgment is always shown to humans in an easy-to-understand way.
It is important to use machine learning not as a replacement for human judgment, but as a tool that supports human judgment.
Key takeaway
Machine learning finds rules from data: supervised (labelled → classification with features), unsupervised (unlabelled → clustering), reinforcement (rewards). Mind its limits — bias and the black-box problem — and keep it supporting human judgment.
Take turns naming a task out loud — “sorting photos of your family”, “working out which of your friends have similar taste in music”, “learning to beat a level in a game” — and the other must say which of the three types it is, and why. The “why” is always about what data you would have.
Sign In to Keep Going
You've reached the end of the free preview. Sign in — and upgrade to Plus or Pro — to keep going with Programming and Artificial Intelligence.
Full Access
Unlock all 30 lessons