AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Supervised vs Unsupervised Learning: Two Approaches

📚 Introduction to Machine Learning⏱️ 25 min read🎓 Grade 9
✍️ AI Computer Institute Editorial Team Updated: August 2026 CBSE-aligned · Peer-reviewed · 25 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

Every year, your school's physical training (PT) teacher fills a register. For every student who has ever taken the fitness test, the register has two things side by side: the numbers measured that day (100-metre run time, number of push-ups in one minute) and a final word written in the last column — "Fit" or "Needs Improvement." That last column exists because a human being, in the past, already looked at the student and decided. The answer is already sitting there in the data, waiting to be learned.

Now imagine a different situation. This year, 60 new students join Class 9 from different schools across the state. The PT teacher measures all 60 of them — run time and push-up count — but has never seen any of them before and has no idea which ones are naturally the athletic types, the strength types, or the ones who need extra attention. There is no last column. Nobody has written "Fit" or "Needs Improvement" anywhere. The teacher just has 60 pairs of numbers and a genuine question: do these 60 students naturally fall into a small number of groups based on how similar their numbers are to each other?

These two situations look almost identical — same kind of data, same PT teacher, same measurements — but they are two fundamentally different machine learning problems. The first is supervised learning: you have inputs and you already know the correct output for each one, and the goal is to learn the pattern well enough to predict the output for a brand-new input. The second is unsupervised learning: you only have inputs, there is no known "correct answer" anywhere in the data, and the goal is to discover whatever structure or grouping already exists inside the numbers. This chapter builds both ideas from the ground up, with numbers you can trace by hand, code you can trace line by line, and a diagram that shows the two problems side by side using the exact same dataset.

Building the Idea: The Same Data, Two Different Questions

Let us use one small dataset for the rest of this chapter so the contrast is completely concrete. Six students have been measured on two things: how many hours a week they study, and their attendance percentage (written here divided by 10, so 85% becomes 8.5, purely to keep the two numbers on a similar scale for the arithmetic later).

StudentStudy hours/weekAttendance (scaled)Result label
A26.0Fail
B35.5Fail
C78.5Pass
D89.0Pass
E57.0Fail
F99.5Pass

If this table is handed to you exactly as written — with the "Result label" column included — you have a supervised problem: given a new student's study hours and attendance, predict whether they will Pass or Fail, using the six known examples as your guide. If instead the "Result label" column is deleted and you are handed only the first three columns for all six students, with no idea that "Pass" and "Fail" even exist as categories, you have an unsupervised problem: just look at the six pairs of numbers and see if they naturally cluster into groups. We will solve both problems, using the same six students, so you can see exactly where the two approaches diverge.

Formal Definitions

In supervised learning, the training data is a set of pairs — an input and its known, correct output, written commonly as (x, y). Here x is called a feature (or a set of features, like the two numbers per student above) and y is called a label. The learning algorithm's job is to build a function f so that f(x) is a good approximation of y, and the real test of success is how well f(x) predicts the label for inputs it has never seen during training. Supervised learning splits further into two kinds based on what y looks like:

  • Classification — y is a category from a fixed set, like "Pass"/"Fail," or "Spam"/"Not Spam," or a digit from 0 to 9. The PT register example above is classification.
  • Regression — y is a number that can take a continuous range of values, like a marks score or a price in rupees.

In unsupervised learning, the training data is only a set of inputs x — there is no y at all, known or unknown. There is no "correct answer" for the algorithm to check itself against during training. The algorithm's job is to find structure that already exists in the x values themselves. The most common form of this, and the one we will trace by hand, is clustering: grouping data points so that points inside the same group are close to each other and points in different groups are far apart. A second common form is anomaly detection — flagging a data point that does not fit any of the natural groups at all. When the National Payments Corporation of India's fraud-detection systems flag a UPI transaction as suspicious, one common technique behind that flag is exactly this: the transaction's pattern (time of day, amount, location, frequency) does not resemble any of the normal clusters formed by that user's past transactions, so it stands out as an outlier, without anyone having pre-labeled that specific transaction as "fraud" beforehand.

Worked Example 1: Supervised Classification with k-Nearest Neighbours

Let's solve the supervised version of our student problem using one of the simplest classification algorithms that exists: k-Nearest Neighbours (k-NN). The idea is almost embarrassingly simple, and that is exactly why it's the right first algorithm to learn by hand: to predict the label of a new point, find the k training points that are closest to it (measured by ordinary distance), and let them vote. Whichever label is in the majority among those k neighbours becomes the prediction.

"Closest" needs a precise meaning. We use the same distance formula you already know from the Pythagorean theorem: for two points (x₁, y₁) and (x₂, y₂), the distance between them is

distance = square_root( (x1 - x2)^2 + (y1 - y2)^2 )

Suppose a new student, G, studies 6 hours a week with a scaled attendance of 8.0, and we want to predict Pass or Fail using k = 3. We compute the distance from G(6, 8.0) to each of the six known students:

To A(2, 6.0):  dx=4,   dy=2.0  ->  16 + 4.00  = 20.00  -> distance = 4.47
To B(3, 5.5):  dx=3,   dy=2.5  ->   9 + 6.25  = 15.25  -> distance = 3.91
To C(7, 8.5):  dx=1,   dy=0.5  ->   1 + 0.25  =  1.25  -> distance = 1.12
To D(8, 9.0):  dx=2,   dy=1.0  ->   4 + 1.00  =  5.00  -> distance = 2.24
To E(5, 7.0):  dx=1,   dy=1.0  ->   1 + 1.00  =  2.00  -> distance = 1.41
To F(9, 9.5):  dx=3,   dy=1.5  ->   9 + 2.25  = 11.25  -> distance = 3.35

Now sort by distance, smallest first: C (1.12, Pass), E (1.41, Fail), D (2.24, Pass), F (3.35, Pass), B (3.91, Fail), A (4.47, Fail). With k = 3, the three nearest neighbours are C, E, and D — their labels are Pass, Fail, Pass. Two votes for Pass, one for Fail. The algorithm predicts Pass for student G. Notice something important: the algorithm never calculated anything like "average marks" or applied a rule someone wrote down about how many hours count as "enough." It only ever measured distance to points where the answer was already known, and let those known answers vote. That is the entire mechanism of supervised learning in its simplest form: lean on labelled history to answer a new question.

Here is the same computation as runnable Python, so you can check the trace above by executing it yourself:

def distance(p, q):
    return ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5

data = [
    ((2, 6.0), "Fail"),
    ((3, 5.5), "Fail"),
    ((7, 8.5), "Pass"),
    ((8, 9.0), "Pass"),
    ((5, 7.0), "Fail"),
    ((9, 9.5), "Pass"),
]

new_point = (6, 8.0)
k = 3

ranked = sorted(data, key=lambda row: distance(row[0], new_point))
nearest = ranked[:k]
labels = [label for _, label in nearest]
prediction = max(set(labels), key=labels.count)

print(nearest)
print("Prediction:", prediction)

Running this prints [((7, 8.5), 'Pass'), ((5, 7.0), 'Fail'), ((8, 9.0), 'Pass')] followed by Prediction: Pass — matching the hand calculation exactly, because sorted() orders the six rows by distance and slicing [:3] keeps the three smallest, which are C, E, and D in that order.

A Quick Second Example: Regression

Classification predicts a category. When the label is a number instead, the same "learn from known answers" idea becomes regression. Suppose five students report hours studied for a unit test and the marks they scored out of 100:

Hours: 1   2   3   4   5
Marks: 35  45  55  65  75

Look at the pattern: every extra hour adds exactly 10 marks, and at 0 hours the line would sit at 25. So marks ≈ 25 + 10 × hours. This is a supervised regression model — found here by eye, but in practice found by an algorithm called linear regression that searches for the straight line minimising the total error across all training points. For a student who studied 6 hours, the model predicts 25 + 10 × 6 = 85 marks. Just like k-NN, this only works because every training example already carried its true marks — the known answer is what made "learning" possible at all.

Worked Example 2: Unsupervised Clustering with k-Means

Now delete the "Result label" column entirely. We are handed the same six (study hours, attendance) pairs with no idea that Pass/Fail even exists as a concept. The question changes from "what is the answer for this point?" to "do these points naturally fall into groups?" We'll use k-means clustering, the most widely taught unsupervised algorithm, and we will deliberately pick k = 2 groups to see what the algorithm finds on its own.

K-means works in repeating rounds. First, choose a starting position for each of the k centroids (the "centre point" of each group) — a common simple strategy is to just pick k of the actual data points as the starting centroids. Then repeat two steps until nothing changes: (1) assign every point to whichever centroid it is currently closest to, and (2) move each centroid to the average position of the points now assigned to it.

Let's start with centroid 1 at A(2, 6.0) and centroid 2 at F(9, 9.5) — two of our actual data points, chosen simply because they look far apart. Step 1: Assign. Using the same distance formula as before, we measure every point against both centroids:

Point A(2,6.0):  to C1(A itself) = 0.00   to C2(F) = 7.83   -> Cluster 1
Point B(3,5.5):  to C1 = 1.12             to C2 = 7.21      -> Cluster 1
Point C(7,8.5):  to C1 = 5.59             to C2 = 2.24      -> Cluster 2
Point D(8,9.0):  to C1 = 6.71             to C2 = 1.12      -> Cluster 2
Point E(5,7.0):  to C1 = 3.16             to C2 = 4.72      -> Cluster 1
Point F(9,9.5):  to C1 = 7.83             to C2(itself)=0.00 -> Cluster 2

Cluster 1 now contains A, B, E. Cluster 2 contains C, D, F. Step 2: Update. Move each centroid to the average of its members:

New centroid 1 = average of A(2,6.0), B(3,5.5), E(5,7.0)
              = ( (2+3+5)/3 , (6.0+5.5+7.0)/3 ) = (3.33, 6.17)

New centroid 2 = average of C(7,8.5), D(8,9.0), F(9,9.5)
              = ( (7+8+9)/3 , (8.5+9.0+9.5)/3 ) = (8.00, 9.00)

Now repeat Step 1 with the updated centroids to check for changes. Re-measuring all six points against (3.33, 6.17) and (8.00, 9.00) shows every point is still closer to the same centroid it already belonged to — A, B, and E remain closest to centroid 1; C, D, and F remain closest to centroid 2. Since no point switched groups, the algorithm has converged: it stops here. The final answer is two clusters — {A, B, E} and {C, D, F} — discovered purely from how close the numbers are to each other, with no label ever consulted.

Here is the same logic in Python, tracing to the identical clusters:

def distance(p, q):
    return ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5

points = [(2, 6.0), (3, 5.5), (7, 8.5), (8, 9.0), (5, 7.0), (9, 9.5)]
c1, c2 = (2, 6.0), (9, 9.5)   # start from two actual points, no labels used

def assign(points, c1, c2):
    cluster1, cluster2 = [], []
    for p in points:
        if distance(p, c1) <= distance(p, c2):
            cluster1.append(p)
        else:
            cluster2.append(p)
    return cluster1, cluster2

def centroid(cluster):
    xs = [p[0] for p in cluster]
    ys = [p[1] for p in cluster]
    return (sum(xs) / len(xs), sum(ys) / len(ys))

cluster1, cluster2 = assign(points, c1, c2)
print(cluster1, cluster2)

new_c1, new_c2 = centroid(cluster1), centroid(cluster2)
print(new_c1, new_c2)

This prints [(2, 6.0), (3, 5.5), (5, 7.0)] [(7, 8.5), (8, 9.0), (9, 9.5)] and then (3.333..., 6.166...) (8.0, 9.0), matching the hand trace exactly.

Now here is the genuinely interesting part. Once the two clusters are found, a human being can look at them and notice they line up almost exactly with the "Fail" and "Pass" labels we deleted at the start of this section. But that alignment was never told to the algorithm — k-means had no idea "Pass" and "Fail" existed. It only grouped points that were numerically close together. The interpretation ("Cluster 1 looks like it corresponds to lower performers") is added afterward, by a human looking at the result. This is the single most important structural difference between the two approaches: supervised learning is handed the meaning of the groups in advance and learns to predict it; unsupervised learning finds the groups first, and any meaning is assigned afterward by a person examining what fell together.

Correcting a Common Misconception

Many students hear the word "supervised" and imagine a person sitting at a computer in real time, watching the algorithm make each prediction and correcting it on the spot — as if "supervision" means active human babysitting while the model runs. That is not what the word refers to. The "supervision" happens entirely before training, when humans (teachers filling in the PT register, doctors labelling X-rays as "tumour" or "no tumour," a shopkeeper labelling past transactions as genuine or fraudulent) recorded the correct answer for each historical example. Once training begins, the algorithm runs on its own, comparing its guesses against those pre-recorded answers to improve itself — no one is watching over its shoulder in real time. The "supervisor" is the historical answer key, not a live human operator.

A second misconception, just as common: students assume unsupervised algorithms decide the number of groups by themselves, as if k-means "figures out" that there should be exactly two clusters. It does not. In basic k-means, you must choose k yourself before the algorithm starts — we chose k = 2 above because we already suspected two natural groups existed. Had we chosen k = 3, the algorithm would have obediently split the same six points into three groups whether or not three genuinely distinct groups exist in reality. Choosing a sensible k is itself a skill (often done by trying several values of k and checking which one produces the tightest, most sensible-looking clusters), not something the algorithm decides on its own.

How to Tell Them Apart in an Exam Question

CBSE Artificial Intelligence and Computer Science questions frequently describe a real scenario and ask you to identify whether it is supervised or unsupervised learning. The reliable test is this: does the training data already contain a column with the known, correct answer for every example? If a dataset of emails already has each one marked "Spam" or "Not Spam," and the goal is to predict that label for new emails, that is supervised classification. If a retailer like a Kirana store's billing software has years of purchase records with no marked categories at all, and the goal is simply to find which products tend to get bought together or which customers behave similarly, that is unsupervised clustering (or, more specifically, a related technique called association). If the scenario instead describes an agent learning through trial, error, and reward — like a program learning to play a game by winning or losing points — that is a third category, reinforcement learning, which is outside the scope of this chapter but worth knowing by name so you don't misclassify it as either of the two approaches covered here.

Comparing the Two Approaches

AspectSupervised LearningUnsupervised Learning
Training dataInputs paired with known correct outputs (labels)Inputs only, no labels
GoalLearn a function to predict the output for new inputsDiscover hidden structure or groupings in the inputs
Typical outputA category (classification) or a number (regression)Groups/clusters, or a flagged outlier
Example algorithmk-Nearest Neighbours, Linear Regressionk-Means Clustering
How correctness is checkedCompare prediction to the true labelNo true answer to check against; judged by how tight/sensible the groups look
Indian examplePredicting loan approval from an applicant's past-labelled recordsGrouping UPI transactions to flag one that doesn't match a user's usual pattern

Visualising Both Approaches on the Same Data

SUPERVISED LEARNING training data already has labels Study hours → Attendance (scaled) → ? predicted: Pass k=3 vote: Pass,Fail,Pass Fail (label) Pass (label) new/unknown point UNSUPERVISED LEARNING same data, no labels at all Study hours → Attendance (scaled) → unlabeled point cluster found (Group 1) centroid (cluster centre)

The left panel is exactly Worked Example 1: red points are the "Fail" training examples, green points are "Pass," and the gray point at (6, 8.0) is the new student whose label we don't know yet. The arrow shows the k-NN prediction landing on Pass because two of its three nearest neighbours were green. The right panel is exactly Worked Example 2: the same six positions, now drawn as identical slate-grey dots because no label information is available to the algorithm at all. The dashed ellipses and cross-shaped centroids show what k-means found purely by measuring distances — and you can see the boundary between the two discovered groups falls almost exactly where the "Fail" and "Pass" colours were in the left panel, even though the right-hand algorithm was never shown those colours.

Active Recall: Check Yourself

  1. A hospital has years of X-ray images, each one already marked by a radiologist as "Tumour" or "No Tumour." A new algorithm is trained on these to flag new X-rays automatically. Is this supervised or unsupervised? Which of the two subtypes (classification or regression) is it, and why?
  2. An e-commerce site has millions of purchase records with no categories attached, and wants to automatically discover natural customer segments (e.g., "festival bulk-buyers," "single-item browsers") to target with different offers. Which approach applies, and what would "k" represent if k-means were used here?
  3. Using the six-student dataset from this chapter, compute by hand (showing the distance formula) whether a new student with 4 study hours and scaled attendance 6.5 would be predicted Pass or Fail using k-NN with k = 1. Then redo it with k = 5 and check whether the prediction changes. What does the fact that it might change tell you about how the choice of k affects a k-NN prediction?
  4. Explain, in your own words, why it is incorrect to say "unsupervised learning has no human involvement at all." At which point in the unsupervised workflow described in this chapter does a human's judgement actually enter?
  5. A weather station records temperature and humidity every day for a year, with no labels of any kind. A student claims this can only ever be an unsupervised learning problem. Explain why this claim is not quite right — describe one way the very same raw data could be turned into a supervised learning problem instead.

(For question 5: the same temperature/humidity readings become supervised the moment you decide on a target to predict from them and have historical ground truth for it — for example, using today's temperature and humidity to predict tomorrow's rainfall, where "did it rain tomorrow" is a known, recorded fact for every past day in the dataset. The raw measurements don't force a problem to be supervised or unsupervised; how you frame the question, and whether a true label exists for that question, decides it.)

Summary

Supervised and unsupervised learning are not two different algorithms — they are two entirely different kinds of problem, defined by one fact: does your training data already contain the correct answer for each example, or not? When it does, you're doing supervised learning, and your job is to build a function that reproduces those correct answers on new inputs — classification when the answer is a category (like Pass/Fail, solved above with k-Nearest Neighbours by letting the closest known examples vote), and regression when the answer is a number (like predicted marks, solved above by spotting a straight-line pattern). When your data has no correct answers attached at all, you're doing unsupervised learning, and your job shifts to finding whatever structure the data already contains on its own — most commonly clustering, solved above with k-means by repeatedly assigning points to the nearest centroid and recentring, until nothing changes. The two misconceptions worth remembering are that "supervised" refers to labelled history, not a live human watching every prediction, and that basic unsupervised algorithms like k-means need you to choose the number of groups in advance — they don't discover that number by themselves. The fastest way to classify any real-world scenario correctly, for an exam or otherwise, is to ask one question: is there already a column of known correct answers in the data, or not?

← What is Machine Learning? Teaching Computers to LearnData Collection and Cleaning: Garbage In, Garbage Out →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn