Unsupervised Learning
Time limit: 90 minutes
Total marks: 60
Instructions: Answer all three questions. Show all derivations. Partial credit awarded for correct method. Calculators/derivations by hand; code answers may be pseudocode or NumPy-style.
Question 1 — K-Means, PCA and their hidden equivalence (24 marks)
(a) Prove that the Lloyd (K-Means) update rule is a coordinate-descent minimization of the within-cluster sum of squares objective where is a one-hot assignment. Specifically, show that (i) with fixed, the optimal assignment is nearest-centroid, and (ii) with assignments fixed, the optimal is the cluster mean. Argue that is monotonically non-increasing and the algorithm terminates. (8)
(b) Consider the following 1-D dataset (already mean-centered): . Run K-Means with starting from centroids . Show every iteration (assignment + update) until convergence, and give the final centroids and the final value of . (6)
(c) PCA on the same data: treat as four samples of a single feature. Compute the sample variance (using divisor ) and state the first principal component's explained-variance ratio. Then explain, with reference to the "spectral relaxation" of K-Means, why the top principal component provides a continuous relaxation of the optimal 2-cluster indicator vector. (6)
(d) State one dataset geometry where K-Means provably fails but DBSCAN succeeds, and justify in one or two sentences using each algorithm's objective/assumptions. (4)
Question 2 — Gaussian Mixtures, EM, and the physics of soft assignment (22 marks)
(a) Write the complete-data log-likelihood for a -component GMM and derive the E-step responsibility Then derive the M-step update for by maximizing the expected complete-data log-likelihood. (8)
(b) Show that in the limit with (and equal priors), the GMM responsibilities become hard 0/1 nearest-centroid assignments, recovering K-Means. Use the softmax form of to justify this. Draw the thermodynamic analogy: identify as a "temperature." (8)
(c) A 1-D two-component GMM has , both , equal priors. Compute the responsibility (probability of component 1) for a point at . Give the numeric value. (6)
Question 3 — Build & analyze: DBSCAN + anomaly scoring (14 marks)
(a) Write clean pseudocode for DBSCAN given parameters and minPts. Clearly distinguish core, border, and noise points, and ensure each point is visited once. State the time complexity with and without a spatial index. (7)
(b) For the 1-D points with and minPts, list the resulting clusters and noise points, identifying which points are core. (4)
(c) Briefly contrast DBSCAN-based anomaly detection with a Gaussian (parametric) anomaly detector for a dataset consisting of two dense elongated bands plus scattered outliers — which is more appropriate and why? (3)
Answer keyMark scheme & solutions
Question 1
(a) [8]
- (i) Fixed : decouples per point ; minimizing subject to one-hot picks . (2) Hence nearest-centroid assignment is optimal. (1)
- (ii) Fixed assignments: , the cluster mean. (3) Second derivative ⇒ minimum. (1)
- Each step is exact minimization over one block ⇒ non-increasing; bounded below and finite number of assignment configurations ⇒ convergence in finite steps. (1)
(b) [6]
- Iter 1 assign: distances to . (dist 4<2? no: |1-(-3)|=4,|1-(-1)|=2 →); (|3+3|=6,|3+1|=4). Clusters: . (2)
- Update: . (1)
- Iter 2 assign: . ; : |−1+3|=2,|−1−1|=2 tie → assign (or ); resolving to nearest with tie-break to lower index: ; ;. Clusters . (1)
- Update: . Reassign confirms stable. Final centroids . (1)
- . (1)
(c) [6]
- Mean ; variance . (2)
- Single feature ⇒ PC1 explains 100% of variance, ratio . (2)
- Spectral relaxation: relaxing the discrete cluster indicator to be real-valued and orthogonal to , the optimal continuous solution maximizing between-cluster variance is the top eigenvector of the (centered) covariance/Gram matrix = PC1. Sign of PC1 projection then gives a natural 2-cluster split; thus PCA relaxes the NP-hard K-Means assignment. (2)
(d) [4]
- Non-convex / concentric-ring (or two-moons) geometry. (2) K-Means minimizes squared distance to a single centroid ⇒ assumes convex isotropic (spherical) clusters and will slice rings incorrectly; DBSCAN groups by density-connectivity so it follows arbitrary shapes and labels sparse points as noise. (2)
Question 2
(a) [8]
- Complete-data LL: . (2)
- E-step: posterior via Bayes = stated formula. (2)
- M-step : maximize ; of gives . (4)
(b) [8]
- With , equal : . (3) As the softmax sharpens: the term with smallest dominates → for nearest centroid, 0 else = hard assignment = K-Means. (3) Analogy: temperature ; is the zero-temperature limit where the Boltzmann/softmax distribution collapses to the ground state (nearest centroid). (2)
(c) [6]
- , (both distance 1). (3) Equal priors ⇒ . (3)
Question 3
(a) [7]
DBSCAN(D, eps, minPts):
label = {} (undefined for all)
C = 0
for p in D:
if label[p] defined: continue
N = rangeQuery(D, p, eps) # neighbors within eps (incl p)
if |N| < minPts:
label[p] = NOISE; continue # may become border later
C += 1; label[p] = C
Seed = N \ {p}
while Seed not empty:
q = Seed.pop()
if label[q]==NOISE: label[q]=C # border point
if label[q] defined: continue
label[q]=C
Nq = rangeQuery(D,q,eps)
if |Nq| >= minPts: Seed += Nq # q is core, expand
return label
- Core: minPts neighbors in . Border: non-core but in a core's neighborhood. Noise: neither. (3 correctness, 2 core/border/noise distinction)
- Complexity: naive; with a spatial index (kd-tree/ball-tree) for low dimensions. (2)
(b) [4]
- , neighbors: 1↔2, 2↔3, 3↔2 → each of 1,2,3 has ≥2 pts incl self ⇒ all core; cluster A={1,2,3}. (1.5)
- 10↔11 within 1.5 ⇒ each core; cluster B={10,11}. (1.5)
- 50 isolated ⇒ noise. (1)
(c) [3]
- Two elongated (non-spherical) bands ⇒ a single Gaussian per band mismatches shape and a global Gaussian anomaly detector flags band tails as anomalies. DBSCAN (density) captures arbitrary band shapes and cleanly labels scattered points as noise/outliers ⇒ more appropriate. (3)
[
{"claim":"Q1b final J = 4 with centroids -2,2","code":"pts=[-3,-1,1,3]; c1=[-3,-1]; c2=[1,3]; m1=sum(c1)/2; m2=sum(c2)/2; J=sum((x-m1)**2 for x in c1)+sum((x-m2)**2 for x in c2); result = (m1==-2 and m2==2 and J==4)"},
{"claim":"Q1c variance (divisor n) = 5","code":"x=[-3,-1,1,3]; n=len(x); mu=sum(x)/n; var=sum((xi-mu)**2 for xi in x)/n; result = (var==5)"},
{"claim":"Q2c responsibility gamma=0.5 for x=1","code":"import sympy as sp; f=lambda x,mu: sp.exp(-(x-mu)**2/2); g=f(1,0)/(f(1,0)+f(1,2)); result = (sp.simplify(g)==sp.Rational(1,2))"},
{"claim":"Q3b cluster A={1,2,3} all core with eps=1.5 minPts=2","code":"P=[1,2,3,10,11,50]; eps=1.5; A=[p for p in P if abs(p-1)<=eps or abs(p-2)<=eps or abs(p-3)<=eps]; core1=len([q for q in P if abs(q-1)<=eps])>=2; core2=len([q for q in P if abs(q-2)<=eps])>=2; result = (core1 and core2 and set([1,2,3]).issubset(set(A)))"}
]