One-sentence summary
Machine learning is when a computer finds patterns by itself by looking at many examples, instead of us writing out every rule.
Why it matters
In the previous lesson we said that artificial intelligence is a tool that finds patterns in data — not magic. But how does it find those patterns? The most common way is machine learning.
This matters because many systems around you work this way: the camera that draws a box around faces in a photo, the email app that moves spam out of your inbox, the assistant that turns your speech into text. None of these work because they are “clever.” They work because they learned patterns from a large number of examples.
There is a second important point. These systems are only as good as the examples they learned from. If the examples are incomplete or wrong, the results will be wrong too. Understanding how machine learning works helps us know when to trust it and when to check it.
Writing rules vs. learning from examples
First: we write the rule
Most of what we did in the coding modules was this. To solve a problem, we thought out the steps and rules and wrote them ourselves. Deciding whether a number is odd or even is easy, because we know the rule:
If the number divides exactly by 2
say "even"
Otherwise
say "odd"
For problems like this we do not need machine learning. The rule is clear, we write it, and the computer follows it.
The problem: some rules cannot be written
Now try this: write, in words, the rule that separates a cat from a dog. If you say “a cat has whiskers,” a dog has them too. If you say “a cat is small,” some dogs are smaller than a cat. Ear shape, fur, tail — every rule has an exception.
Telling whether a photo contains a cat is very easy for you, but you cannot write down, step by step, the rule you used to decide. This is exactly where we change our approach.
Then: we give examples, and the machine finds the rule
In machine learning we do not write the rule ourselves. Instead we show the computer many examples and say, “find the shared pattern for me.”
For cats and dogs it works like this: we show the computer thousands of photos, and under each one we write the correct answer — “this is a cat,” “this is a dog,” “this is a cat.” By looking at these examples, the computer slowly picks up the patterns that appear often in cat photos. Then, when a brand-new photo it has never seen arrives, it makes a guess based on the pattern it learned.
Notice that word: guess. Machine learning does not produce a certain answer; it produces a prediction. It is often right, but it can also be wrong.
Supervised learning: labelled examples
What is a label?
The correct answer we wrote under each photo is called a label. “This is a cat” is a label; “this is a dog” is another label.
Learning where each example comes with its correct label is called supervised learning. The name comes from a nice comparison: it is as if a teacher (a supervisor) guides the learner by showing the correct answer for every example.
Everyday example: telling fruit apart
Suppose we want to sort fruit by weight. Apples are usually lighter, oranges usually heavier. Instead of writing an exact rule, we can learn from fruit we have already weighed and named.
The code below does not train a real model; it is a small, honest experiment. From labelled examples it learns the average weight of each class, then matches a new fruit to whichever average it is closer to:
# Labelled examples: (weight_grams, label)
examples = [
(120, "apple"), (130, "apple"), (110, "apple"),
(150, "orange"), (170, "orange"), (160, "orange"),
]
# "Learn" the average weight of each class from the examples
apples = [w for w, label in examples if label == "apple"]
oranges = [w for w, label in examples if label == "orange"]
apple_avg = sum(apples) / len(apples)
orange_avg = sum(oranges) / len(oranges)
# Predict a new fruit by the average it is closer to
def predict(weight):
if abs(weight - apple_avg) < abs(weight - orange_avg):
return "apple"
return "orange"
print(predict(125)) # apple
print(predict(165)) # orange
We did not write the rule by hand; we never set a threshold like “an apple is under 130 grams.” The program worked out the threshold itself from the averages in the examples. Real machine learning is far more complex, but the core idea is exactly this: find a pattern from examples, then use it on new data.
Change the examples, and the result changes
This experiment lets you see something surprising very easily. If you accidentally add a 300-gram “apple” to the examples, the apple average rises and the program starts making mistakes on later predictions. We did not change the code; we only changed the data, and the behaviour broke.
This is the most important lesson in machine learning: the result depends on the examples you give. If the examples are unbalanced, incomplete or biased, the learned pattern will be biased too.
Mini practice
No computer needed; pencil and paper are enough.
- Write 8 small labelled examples in a box. Each example is an animal and carries two pieces of information: its rough weight and its label (“cat” or “dog”).
- Now think like the code: work out the average weight of the cats and the average weight of the dogs.
- Ask a friend to name a new weight (say 6 kg). Your prediction is whichever average that weight is closer to.
- Now add a “trap” example: a 40 kg “cat.” Recalculate the average and make the same prediction again. Did the result change?
- Finish with one short sentence: did you change the code, or the data? Why did the result break?
This activity shows both the power and the fragile side of supervised learning at the same time.
Common mistakes
Confusing machine learning with programming
In programming you write the rule. In machine learning you provide examples and the machine works out the pattern. Not every problem needs machine learning; where you can easily write the rule, plain code is better.
Thinking it “knows the right answer”
Machine learning produces a prediction, not certain knowledge. For an important decision, check the output instead of trusting it blindly.
Teaching with too few or biased examples
If you only show photos of black cats, the system may struggle to recognise an orange one. The more varied and balanced the examples, the fairer the learned pattern.
Not noticing a wrong example
Even a single mislabelled example (writing “cat” instead of “dog” by mistake) can break the learned pattern. Preparing the examples carefully is as important as writing the code.
Safety note
- Use machine learning tools together with an adult and follow the platform’s age rules.
- Do not upload your own or anyone else’s personal information (name, address, phone, school, face photo) into online AI tools or datasets. Information you upload once can be used by others.
- Machine learning systems can be wrong and can learn the unfairness in their data. Never leave an important result — a diagnosis, a grade, a decision — to the machine alone; a human must always check it.
- Responsibility always stays with people. Who trained a system, with what data, and for what purpose — and whether the result is fair and correct — is a human responsibility.
Lesson summary
- Machine learning means finding patterns from examples instead of writing every rule by hand.
- It helps with problems where the rule is hard to write, like telling cats from dogs.
- Learning from labelled examples is called supervised learning.
- The result is a prediction; it may not always be right and it depends on the data we give.
- Incomplete or biased data leads to biased results, and responsibility always stays with people.
Check questions
- What is the main difference between machine learning and ordinary programming?
- What is a “label,” and why is it needed in supervised learning?
- In the cat–dog example, do we write the rules for the computer, or do we give it examples?
- In the fruit experiment, what is one way to break the result without changing the code?
- Why should you be careful before uploading a personal photo to an AI tool?
Answers
- In programming a human writes the rules; in machine learning a human provides examples, and the machine works out the pattern (the rule) from those examples itself.
- A label is the correct answer for an example (like “this is a cat”). It is needed because in supervised learning the machine learns the pattern by seeing the correct answers.
- We give examples. The machine finds the pattern by looking at many labelled photos, because the rule that separates a cat from a dog is very hard to write in words.
- Change the data. For example, adding a very heavy, wrong “apple” to the examples spoils the average and the program starts predicting incorrectly.
- Because personal information you upload once can be seen and used by others; that is why you should ask an adult and follow the platform’s rules before uploading anything.
Source and verification note
For “What Is Machine Learning?”, verification focuses on whether the relationship between Writing rules vs. learning from examples and The problem: some rules cannot be written remains consistent across examples. Datasets in this module are small and educational; real personal data should not be used. An AI result should be evaluated not only for accuracy but also for data balance, error distribution and explainability.
Next lesson
Training Data and Test Data: How we teach a machine learning system with examples, and how we fairly test whether it has actually learned.