What is Machine Learning?
Instead of writing every rule by hand, you let a program learn the rule from examples.
What you will learn
- Define machine learning in plain words
- Tell learning from data apart from writing rules
- Spot ML you already use every day
Two ways to make a computer smart
Normally you program a computer by writing rules yourself: if this, then that. Machine learning (ML) flips that around. You show the computer lots of examples, and it figures out the rule on its own.
Think of a spam filter. The old way is to hand-write rules like if the email says “free money”, mark it as spam — but spammers just change the words. The ML way is to show the computer thousands of emails already labelled spam or not spam, and let it learn what spam looks like by itself.
Rules vs learning, side by side
| Writing rules | Machine learning | |
|---|---|---|
| Who makes the rule | You, by hand | The computer, from data |
| Needs examples? | No | Yes — lots of them |
| Handles messy real data | Badly | Well |
| Improves over time | Only if you edit it | Yes, with more data |
Seeing it as code
Here is the same job — is this email spam? — written both ways, so the difference is clear.
# The old way: a rule YOU write
def is_spam(email):
return 'free money' in email.lower()
# The ML way (in spirit): the computer learns the rule from examples
# emails -> ['win cash now', 'lunch at 1pm', 'free money here', ...]
# labels -> ['spam', 'not spam', 'spam', ...]
# A model studies these and predicts the label for a NEW email.
print(is_spam('Claim your FREE MONEY now'))
print(is_spam('Are we still on for lunch?'))Note: Output: True False The hand-written rule only catches the exact words you thought of. A trained model learns the broader pattern from many labelled emails — including tricks you never anticipated.
You already learn from data
Here is the key idea in a tiny table. Look at how many hours some students studied and whether they passed. Do not write a rule — just look for the pattern.
| Hours studied | Result |
|---|---|
| 1 | Fail |
| 2 | Fail |
| 3 | Fail |
| 5 | Pass |
| 6 | Pass |
| 8 | Pass |
Your brain instantly guessed something like “study more than about 4 hours and you pass.” Nobody gave you that rule — you learned it from the examples. That is exactly what a machine-learning model does, only with thousands of rows and numbers instead of six. Notice you also did not need any maths to spot it; the computer just does the same thing at a bigger scale.
ML you already use
- Netflix and YouTube recommending what to watch next.
- Your email sorting spam from real mail.
- Banks spotting a fraudulent card payment.
- Your phone recognising faces in photos.
- Shops predicting how much stock to order next month.
Tip: You do not need heavy maths to start. A library (a ready-made bundle of code other people wrote that you can reuse) called scikit-learn does the hard maths for you. It is a free Python toolkit for machine learning — and in code you import it under the short name sklearn, so scikit-learn and sklearn mean the same thing. Your job is to prepare good data and pick the right tool.
Watch out: ML is not magic. If you feed it bad or too little data, it learns the wrong thing. Good data matters more than a fancy algorithm.
Q. What is the key difference between machine learning and ordinary programming?
✍️ Practice
- List five apps you used today and guess where each one uses machine learning.
- Write a hand-written
is_spam()rule, then explain one email it would get wrong.
🏠 Homework
- In 3–4 sentences, explain to a non-technical friend what machine learning is, using your own everyday example.