Supervised vs Unsupervised Learning
What if there is no answer to check?
In the last lesson, every flat came with its real rent. That rent was what made learning possible. The machine guessed, compared its guess with the real rent, saw how wrong it was, and adjusted.
Now picture a different job. A supermarket owner hands you two years of customer bills and says: "Tell me what kinds of customers I have." There is no column saying "this one is a family shopper" or "this one is a student". Nobody ever wrote that down. There is nothing to compare a guess against.
Can a machine still learn anything here? Yes. But it learns in a completely different way. That difference is what this lesson is about, and it is the first thing to figure out about any ML problem.
The one question that decides it
Look at your data and ask: does it already contain the answer I want the machine to give?
Key Points
- If yes, it is supervised learning. The machine learns to reproduce the answers it has seen.
- If no, it is unsupervised learning. The machine looks for patterns and groups on its own.
Supervised
The answer is in the data
A human produced that right-hand column. The model learns to reproduce it.
Unsupervised
Nobody wrote the answer down
No column to copy, so the model is asked for the shape of the data instead.
Supervised learning: learning with an answer key
Think of practising maths with a guide book that has answers at the back. You solve a question, check the back, see where you went wrong, and fix your method. Someone already did the hard work of writing the right answers. You learn by checking against them.
That is supervised learning. The answers act like a teacher supervising the machine, telling it after every guess whether it was right. It is exactly the loop from lesson 1.2, where the compare step only works because the real answer is sitting right there.
Two words you will see constantly from here on:
Key Points
- Features: the information you give the machine to base its guess on. For a flat, that is size, area, floor and so on.
- Label: the answer you want it to predict. For a flat, that is the rent.
A few more supervised problems, with the label pointed out:
Key Points
- Spam filter. Features: the words in a message. Label: spam or not spam.
- Loan approval. Features: income, existing loans, repayment history. Label: did this person repay or not?
- Delivery time. Features: distance, restaurant, time of day, rain. Label: how many minutes the order actually took.
- Crop disease. Features: a photo of a leaf. Label: which disease an expert said it has.
Tip:Notice that every label had to come from somewhere. Someone marked the spam, the bank recorded who repaid, the app timed the delivery, an expert looked at the leaf. If nobody recorded the answer, you cannot do supervised learning.
Two flavours of supervised learning
Look at the labels above again. Some are numbers, like rent or delivery minutes. Others are categories, like spam or not spam. That difference splits supervised learning into two kinds:
Key Points
- Regression: the answer is a number. "This flat will rent for ₹18,000." "This order will take 32 minutes."
- Classification: the answer is a category. "This message is spam." "This leaf has rust disease."
You do not need more than that for now. Chapter 4 is all about regression and Chapter 6 is all about classification.
Unsupervised learning: finding patterns nobody labelled
Now take the answers away. Someone hands you a box of 500 old family photos and says "sort these". Nobody tells you the categories. You might end up with piles for weddings, school trips and festivals, just because the photos in each pile look alike. You found the structure yourself.
That is unsupervised learning. The machine only gets features, no labels. Since there is no right answer to check against, it cannot do the compare step from lesson 1.2. So it does something else: it looks for what is similar to what.
Back to the supermarket. Say you only look at two things per customer: how often they visit, and how big their bill usually is. Once you look at it that way, groups start to show up by themselves:
Key Points
- People who come almost every day and spend ₹150. Probably picking up milk and bread on the way home.
- People who come twice a month and spend ₹4,500. Probably doing a big monthly stock-up for a family.
- People who come once in a while and spend ₹800. Probably topping up something they ran out of.
The machine finds those three groups because the customers inside each one are close to each other and far from everyone else. But notice the "probably" in each line. The machine finds the groups. It does not name them. A human looks at each group and decides what it means.
What unsupervised learning is used for
Grouping is the most common use, but there are three main jobs worth knowing:
Key Points
- Clustering: putting similar things into groups, like the supermarket customers. Also used to group news articles by topic or songs by style.
- Anomaly detection: spotting the one thing that does not fit. If you always pay small amounts on UPI in Pune, a ₹90,000 payment from another country at 3 am stands out, even if nobody ever labelled it as fraud.
- Dimensionality reduction: simplifying data that has too many columns. If a survey asks 40 questions, many of them are really measuring the same few things, like "does this person like the product" or "is the price a problem". This squeezes 40 columns down to a handful that still tell most of the story.
Tip:Clustering is so common that people sometimes use it as another name for unsupervised learning. It is not. It is one type of unsupervised learning among several.
Why not always use supervised learning?
Supervised learning is usually easier to trust, because you can check the machine against real answers. So why would anyone go without them?
Because labels are expensive. To label 10,000 X-rays, a doctor has to look at every single one. To label a million customer messages by topic, people have to read them all. That takes months and costs a lot of money.
And sometimes you do not even know what the labels should be. The supermarket owner did not know their customer types in advance. You cannot label data with categories nobody has thought of yet.
Real projects often use both
Say a company has 10,000 support tickets and no categories. A smart way to handle it uses both kinds of learning, one after the other:
Key Points
- First, unsupervised: cluster the tickets to see what kinds exist. Maybe refunds, login problems, late deliveries.
- Then a human reads a few tickets from each cluster and gives the groups proper names.
- Then someone labels a few hundred tickets using those names.
- Finally, supervised: train a model on those few hundred, and let it label the other 9,000+ automatically.
Unsupervised, to discover
01
Cluster them
Find candidate groups in the raw tickets.
02
Read a sample
Clusters are a hypothesis, not a result.
Supervised, to scale
03
Label a few hundred
Now you know what the categories are.
04
Train a classifier
It labels the other nine thousand.
In code
Here are both kinds side by side, using scikit-learn, the most popular library for classic ML. (Chapter 2 introduces it properly.) This runs as-is in Google Colab.
1from sklearn.linear_model import LinearRegression
2from sklearn.cluster import KMeans
3
4# --- Supervised: every flat comes with its rent (the answer) ---
5sizes = [[500], [800], [1000], [700]]
6rents = [10000, 16000, 20000, 15000]
7
8model = LinearRegression()
9model.fit(sizes, rents) # features AND answers
10print("Predicted rent for 900 sq ft:", round(model.predict([[900]])[0]))
11
12# --- Unsupervised: customers with no answer column at all ---
13# [visits per month, average bill in ₹]
14customers = [
15 [25, 150], [28, 120], [22, 180], [26, 140], # ?
16 [2, 4500], [1, 4700], [3, 4400], [2, 4600], # ?
17 [1, 800], [2, 700], [1, 900], # ?
18]
19
20kmeans = KMeans(n_clusters=3, n_init=10, random_state=0)
21kmeans.fit(customers) # features only, no answers
22print("Group for each customer:", kmeans.labels_)Predicted rent for 900 sq ft: 18192 Group for each customer: [1 1 1 1 0 0 0 0 2 2 2]
Look at the two fit lines. The supervised model gets fit(sizes, rents): features and answers. The unsupervised model gets fit(customers): features only. That one difference in the code is the whole difference between the two.
The rent prediction, ₹18,192, is close to what our hand-made loop found in lesson 1.2. And KMeans, which is a clustering method, put the four daily shoppers in one group, the four monthly shoppers in another, and the three occasional ones in a third, without ever being told those groups exist.
Tip:The group numbers 0, 1 and 2 mean nothing on their own. They are just names the machine gave the groups. Run it with different settings and the monthly shoppers might become group 2 instead of group 0. It is still up to you to look inside each group and decide what it is.
Two more you will hear about
Key Points
- Semi-supervised learning: a small amount of labelled data used together with a lot of unlabelled data. Useful when labels are expensive, which is often.
- Reinforcement learning: a program learns by trying actions and getting rewards or penalties, like a player learning a game by playing it thousands of times. It is a different family from the two in this lesson, and it is not covered in this course.
Where people get confused
Key Points
- "Supervised means a human watches the machine while it learns." No. The supervision comes from the labels in the data, not from someone watching.
- "Unsupervised learning tells you what the groups are." It only tells you which things belong together. Naming and understanding the groups is still a human job.
- "Clustering and unsupervised learning are the same thing." Clustering is one type. Anomaly detection and dimensionality reduction are unsupervised too.
- "Unsupervised is more advanced, so it is better." Neither is better. The data decides: if you have the answers, supervised is usually the right call.
Quick check
A hospital has 5,000 past patient records, each marked with whether the patient developed diabetes. They want to predict it for new patients. Supervised or unsupervised?
Supervised. The data already contains the answer (developed diabetes or not), so the machine can learn to reproduce it. And since the answer is a category, it is classification.
A music app wants to group its songs into "moods", but nobody has decided what the moods are. Supervised or unsupervised?
Unsupervised, specifically clustering. There are no labels, and the categories do not even exist yet. The app groups similar songs first, then people decide what each group should be called.
Predicting tomorrow's temperature from past weather data. Regression or classification?
Regression. The answer is a number (like 31°C), not a category. If the question were "will it rain tomorrow, yes or no", that would be classification.
Recap
Key Points
- The deciding question: does your data already contain the answer you want to predict?
- Supervised learning has answers (labels). The machine learns to reproduce them. It splits into regression (numbers) and classification (categories).
- Unsupervised learning has no labels. The machine finds structure on its own: groups, oddities, or simpler versions of the data.
- Labels cost time and money, which is why unsupervised learning matters.
- Real projects often use both: unsupervised to explore, supervised to scale.
Next up: where machine learning already shows up in your day. You will be surprised how many times you used it before breakfast.
Theia
Can you explain this concept?
Practise Supervised vs Unsupervised Learning with realistic interview questions. Choose spoken or typed answers, get feedback on your reasoning, then return to the material that needs work.
Sign in to practise this conceptThe session stays focused on this lesson. Your selected interview level sets the bar.