Unsupervised Learning and Clustering Explained: K-Means Worked Example and Exam Traps

Build intuition for unlabelled data, then follow k-means from assignment to updated centroids and SSE. Compare medoids, hierarchical clustering, DBSCAN and neural representations.

KnowledgeGate Team

Exam prep & CS education

Updated 15 Sep 20265 min read

Unlabelled data supplies no correct groups. A learner must choose a representation, similarity rule and objective before clusters mean anything. A k-means calculation distinguishes algorithms that students often mix up.

Unsupervised learning: what the model learns without labels

A sample is a feature vector x, such as a student's practice time, accuracy and topic coverage. An unsupervised dataset supplies inputs but no target y. Supervised classification instead uses labelled examples to define the prediction task.

Unsupervised learning includes several task families:

  • Clustering groups observations judged similar under a chosen rule.

  • Dimensionality reduction keeps useful structure in fewer variables.

  • Representation or density learning models the data itself.

Six points may include (1,1) and (8,9) but no group labels. Their grouping depends on the features and distance selected, so a cluster is a model result, not a revealed class. For neighbouring revision, use the Artificial Intelligence for GATE: syllabus and weightage as a concept hub.

Clustering basics: representation, distance and the objective

A sound pipeline is ordered: encode each item, scale incomparable features, choose a distance, select an algorithm, then evaluate stability and usefulness.

Euclidean distance is the square root of summed squared coordinate differences. Squared Euclidean distance omits that root. Manhattan distance adds absolute coordinate differences. The k-means objective and assignments use squared Euclidean distance.

Scaling matters. Let two sensor records be S1=(20 degrees C, 1000 rpm) and S2=(22 degrees C, 1100 rpm). Their raw squared Euclidean distance is:

(22-20)^2 + (1100-1000)^2 = 2^2 + 100^2 = 4 + 10000 = 10004

The rpm coordinate dominates because its numerical scale is larger, not necessarily because it matters more. Put such features on comparable scales before clustering.

Term

Meaning

Hard membership

Each point is assigned to one cluster

Soft or probabilistic membership

A point receives degrees or probabilities of belonging

Centroid

Coordinate-wise mean, which need not be an observed point

Medoid

An actual observed point chosen as representative

Compactness

Points within a cluster are close

Separation

Different clusters are well apart

Neither compactness nor separation alone proves that a grouping serves the real task.

K-means clustering: assignment and centroid-update steps

For a fixed number of clusters k, k-means minimises the within-cluster sum of squared Euclidean distances:

J = sum_i ||x_i - mu_(c_i)||^2

Here, mu_(c_i) is the mean of point i's assigned cluster. Choose k initial centroids, assign every point to the nearest one, replace each centroid with its assigned points' coordinate-wise mean, and repeat until assignments or movement stop changing.

An iteration cannot increase J, but the result may be a local optimum and depend on initialisation. K-means needs k in advance, suits compact numeric clusters, and is sensitive to scale and outliers. Feature choice, scaling and k remain modelling choices.

K-means worked example: two clusters, one complete iteration

Take A=(1,1), B=(1,2), C=(2,1), D=(8,8), E=(9,8) and F=(8,9). Set k=2, with initial centroids mu1=(1,1) and mu2=(8,8).

The squared distances to (mu1, mu2) are A:(0,98), B:(1,85), C:(1,85), D:(98,0), E:(113,1) and F:(113,1). Thus A,B,C join cluster 1 and D,E,F join cluster 2.

Update both centroids by calculating each coordinate-wise mean:

  • mu1=((1+1+2)/3,(1+2+1)/3)=(4/3,4/3)

  • mu2=((8+9+8)/3,(8+8+9)/3)=(25/3,25/3)

Reassignment is unchanged. Cluster 1's updated squared distances are 2/9, 5/9 and 5/9, totalling 12/9 = 4/3. Cluster 2 has the same values and contributes 4/3. Updated total SSE is 4/3 + 4/3 = 8/3, approximately 2.67.

Initially, the cluster contributions were 0+1+1=2 each, giving SSE 4. The update reduces it to 8/3. Stable assignments show convergence here, not a global optimum guarantee for every dataset and initialisation.

Scatter plot of two point clusters with k-means centroids updating to (4/3,4/3) and (25/3,25/3) as total SSE falls from 4 to about 2.67.

Clustering algorithms compared: k-medoids, hierarchical and density-based methods

No algorithm is universally best. Match its assumptions to the data and question.

Method

Representative

Need for k

Shape assumption

Outlier behaviour

Usable distance

K-means

Mean centroid

Yes, in advance

Compact numeric groups

Sensitive

Squared Euclidean

K-medoids

Real data point

Usually yes

Compact under chosen dissimilarity

More robust than a mean

General dissimilarity matrix

Agglomerative hierarchical

Nested cluster tree

Choose a cut later

Depends on metric and linkage

Can distort merges

Many metrics with a linkage rule

DBSCAN

Dense regions, no single representative

No k; uses neighbourhood settings

Can find irregular shapes

Labels sparse points as noise

A metric suitable for neighbourhoods

K-medoids accepts a general dissimilarity matrix and returns an observed representative. Agglomerative clustering repeatedly merges clusters and records a dendrogram. Single linkage uses the minimum cross-cluster pair distance, while complete linkage uses the maximum.

Choose k-means for compact numeric groups, a medoid for a real representative or non-Euclidean dissimilarity, hierarchical clustering for nested structure, and density-based clustering for irregular shapes and explicit noise.

Neural-network approaches to unsupervised learning

An autoencoder maps an input through a lower-dimensional code and reconstructs it. Reconstruction error, not labels, supplies the training signal. A 100-feature record might become 8 learned values that are then clustered. Compression does not guarantee better clusters.

In competitive learning or a self-organising map, units compete for an input. The winner and its neighbourhood update, so nearby units represent similar inputs. This differs from the k-means update although both learn without targets. The Skill Development Courses category connects this foundation to adjacent AI and technical-skills coverage.

Unsupervised learning exam patterns and common traps

The completed GATE 2026 Data Science and Artificial Intelligence syllabus and papers covered unsupervised learning, k-means or k-medoid, and hierarchical clustering. That coverage belongs to the DA paper; the GATE CS syllabus does not list these clustering topics, so check the current cycle's official syllabus for the paper you are writing.

One completed-cycle DA question used P1=[2,3,-1], P2=[3,1,1], P3=[5,-2,3] and P4=[3,3,3]. With Manhattan distance:

  • d12=|2-3|+|3-1|+|-1-1|=1+2+2=5

  • d13=|2-5|+|3-(-2)|+|-1-3|=3+5+4=12

  • d14=|2-3|+|3-3|+|-1-3|=1+0+4=5

  • d23=|3-5|+|1-(-2)|+|1-3|=2+3+2=7

  • d24=|3-3|+|1-3|+|1-3|=0+2+2=4

  • d34=|5-3|+|-2-3|+|3-3|=2+5+0=7

The smallest value is d24=4, so agglomerative clustering merges P2 and P4 first.

Manhattan distance matrix of four points where the smallest value d24 equals 4, marking P2 and P4 as the first agglomerative merge.

Before accepting an answer, check the named distance, distinguish centroid from medoid, and keep single and complete linkage in the correct order. Also check whether labels exist, whether scaling changes the result, and whether a different initialisation is relevant. Lower training SSE alone does not prove useful clustering. For format context, revise MCQ, MSQ or NAT? GATE question types explained. For broader syllabus planning only, see UGC NET Computer Science high-yield topics.

Unsupervised learning and clustering: the short version

Use a five-part decision check: inspect whether labels exist, choose useful features, scale them, match the distance and algorithm to the data, then evaluate stability and practical usefulness. In the worked example, mu1=(4/3,4/3), mu2=(25/3,25/3) and total SSE becomes 8/3.

If you want a structured AI and machine-learning path beyond clustering, continue with AI & ML for Placements. Treat clustering as a modelling decision you must justify, not as an automatic discovery of one true grouping.