💡The Big Idea: Rules vs. Examples

Traditional software follows a recipe you write: "IF the email contains 'free money' AND 'click here', mark it spam." That works fine — until the spammers swap "free money" for "complimentary funds." You'd have to keep updating your rules forever.

Machine learning flips the script. Instead of writing rules, you hand the computer thousands of labelled examples (spam / not-spam) and let it figure out the rules itself by looking for patterns.

🐱 Analogy — Learning to recognise a cat You didn't learn what a cat is from a dictionary definition ("four legs, pointy ears, fur, meows…"). A parent just showed you pictures — "cat… cat… not a cat… cat…" — and your brain extracted the pattern. Machine learning works the same way: show enough labelled examples, and the algorithm learns the pattern on its own.
Traditional ProgrammingMachine Learning
You write the rulesThe machine discovers the rules
Input + Rules → OutputInput + Output → Rules
Breaks when rules changeAdapts with new data
Great for simple logicGreat for complex patterns

🍦Three Flavours of Machine Learning

"Machine learning" isn't one thing — it's a family of approaches that differ in how much guidance the algorithm gets from humans.

🃏

Supervised Learning

Learning from labelled examples — like practising with flashcards that have the answer on the back. Every training example comes with the right answer.

Everyday example: Email spam filter, house price prediction, image recognition.

🗄️

Unsupervised Learning

Finding patterns and groups in data that has no labels — like sorting a jumbled drawer into piles that feel similar, without anyone telling you the categories.

Everyday example: Customer segmentation, topic detection in news, anomaly detection.

🐕

Reinforcement Learning

Learning through trial, reward and punishment — exactly like training a dog with treats. The agent tries actions; good outcomes give a reward; bad ones give a penalty.

Everyday example: Game-playing AIs (Chess, Go), robot locomotion, recommendation feeds.

💡 Quick memory hook Supervised = teacher provides answers. Unsupervised = no teacher, find your own groups. Reinforcement = no teacher, but you get a score after each attempt.

🔄The Training → Prediction Loop

Every supervised ML system goes through two distinct phases: training (learning from data) and prediction / inference (applying what was learned to brand-new inputs).

Step 1

Collect Data

Gather labelled examples — the raw material of learning.

Step 2

Train

Feed examples to the algorithm; it adjusts its internal rules to minimise mistakes.

Step 3

Evaluate

Test on unseen examples to measure how well it generalises.

Step 4

Predict

Deploy: give the model a new input and let it produce an answer.

The key challenge is generalisation: the model must work well on examples it has never seen, not just the ones it trained on.

⚠️ Overfitting — the classic trap Imagine a student who memorises every past exam paper word-for-word but doesn't understand the underlying concepts. They'll ace a repeat of those exact questions — but fail any rephrased version. A model that overfits does the same: it memorises the training data instead of learning the real pattern, and falls apart on new data. The cure is more diverse data, simpler models, or techniques like regularisation and cross-validation.
Train Your Own Classifier PLAYGROUND

Imagine a 2-D world where every fruit has a size (x-axis) and a sweetness (y-axis). Pick a label, click on the canvas to drop labelled training examples, and watch the decision boundary emerge in real time.

🍎 Apples: 0 🍊 Oranges: 0 Add at least 1 of each class to see the decision boundary.
Sweetness ↑
Size →
🔗 What you just built The coloured dots are your training data (labelled examples, i.e. supervised learning). The faint background regions form the learned model — a 1-Nearest-Neighbour classifier that predicts "whichever class is closest." The mystery fruit is prediction on unseen data. Try clustering all your apples in one corner and oranges in another — the boundary will be crisp. Then mix them up and see what happens!