Clustering (K-Means) & Dimensionality Reduction (PCA)
Master unsupervised manifold discovery. K-Means WCSS objective minimization, the Elbow method vs Silhouette score, handling the $p \gg n$ high-dimensional regime via Dual SVD, and translating abstract principal components into actionable biological driver biomarkers.
01. Intuition & Concept Contrast
Unsupervised learning operates without ground-truth target labels ($y$). Clustering groups similar samples together in feature space, while dimensionality reduction compresses thousands of correlated features into a few orthogonal axes.
Clustering vs Dimensionality Reduction
Clustering (Grouping Samples): Finds natural discrete groupings among rows ($\mathbf{x}_i \in \mathbb{R}^p$). Assigns each observation to one of $K$ distinct clusters (e.g. disease subtypes).
Dimensionality Reduction (Compressing Columns): Finds a continuous lower-dimensional subspace ($k \ll p$) that preserves maximum sample variance, eliminating redundant assay noise.
Covariance Eigendecomposition vs Dual SVD
Full Covariance Method: Computes $p \times p$ covariance matrix $\mathbf{\Sigma} = \frac{1}{n-1}\mathbf{X}^T\mathbf{X}$. Requires $O(p^3)$ time ($1.25 \times 10^{11}$ operations for $5,000$ genes) $\implies$ Computationally Intractable.
Dual SVD Method: Decomposes centered data matrix $\tilde{\mathbf{X}} \in \mathbb{R}^{n \times p}$ directly into $\mathbf{U}\mathbf{S}\mathbf{V}^T$ in $O(n^2 p)$ time ($10^8$ operations) $\implies$ Instant & Numerically Stable.
02. K-Means Clustering Mathematical Formulation
Jan 2025 (Q7) Core Theory (20 Marks). Minimizing Within-Cluster Sum of Squares (WCSS).
Lloyd's 2-Step Iterative Algorithm:
- Step 1: Assignment Step
Assign each data vector $\mathbf{x}_i$ to its nearest cluster centroid in Euclidean distance: $$c_i^{(t)} = \arg\min_{k \in \{1, \dots, K\}} \|\mathbf{x}_i - \boldsymbol{\mu}_k^{(t)}\|^2$$ - Step 2: Update Step
Recompute the centroid of each cluster as the center of mass of all assigned points: $$\boldsymbol{\mu}_k^{(t+1)} = \frac{1}{|C_k^{(t)}|} \sum_{\mathbf{x}_i \in C_k^{(t)}} \mathbf{x}_i$$ - Convergence: Repeat Steps 1 and 2 until centroid coordinates stop changing ($\|\boldsymbol{\mu}^{(t+1)} - \boldsymbol{\mu}^{(t)}\| < \epsilon$) or maximum iterations are reached.
Selecting Optimal $K$: The Elbow Method vs Silhouette Coefficient
1. The Elbow Method: Plot $\operatorname{WCSS}$ against candidate cluster counts $K \in [1, 10]$. As $K$ increases, WCSS monotonically decreases. Select the "Elbow" inflection point where adding another cluster yields diminishing returns in variance reduction.
2. Silhouette Coefficient ($s(i)$): Evaluates cluster compactness vs separation:
$$s(i) = \frac{b(i) - a(i)}{\max(a(i), b(i))} \in [-1, +1]$$- $a(i)$: Mean distance from point $i$ to all other points in its own cluster (intra-cluster compactness).
- $b(i)$: Mean distance from point $i$ to points in the nearest neighboring cluster (inter-cluster separation).
- $s \approx +1 \implies$ Excellent clustering; $s \approx 0 \implies$ Borderline overlap; $s < 0 \implies$ Assigned to wrong cluster.
Standard random initialization can strand centroids in poor local minima. K-Means++ seeds the first centroid uniformly at random, and selects each subsequent centroid with probability proportional to squared distance from the closest existing centroid: $$P(\mathbf{x}) = \frac{D(\mathbf{x})^2}{\sum_{\mathbf{x}'} D(\mathbf{x}')^2}$$ This spreads initial centroids far apart across feature space, guaranteeing $O(\log K)$ competitive solutions.
03. Principal Component Analysis via Dual SVD ($p \gg n$)
Nov 2025 (Q5) Bioinformatics Exam Problem (20 Marks). Gene expression dataset with $p = 5,000$ genes and $n = 100$ patient samples.
1. Distance Metric Concentration (Curse of Dimensionality): As dimensions $p \to \infty$, the relative contrast between the nearest and farthest neighbors vanishes: $$\lim_{p \to \infty} \frac{\operatorname{dist}_{\max} - \operatorname{dist}_{\min}}{\operatorname{dist}_{\min}} \to 0$$ Every patient becomes equidistant from every other patient in $\mathbb{R}^{5000}$, rendering Euclidean clustering ineffective.
2. Rank Deficiency: Data matrix $\mathbf{X} \in \mathbb{R}^{100 \times 5000}$ has maximum rank $\min(n-1, p) = 99$. The data lies entirely within a 99-dimensional hyperplane; the remaining 4,901 dimensions represent empty assay noise.
Mathematical Derivation of the Dual SVD Shortcut:
1. Center the data matrix: $\tilde{\mathbf{X}} = \mathbf{X} - \mathbf{1}\boldsymbol{\mu}^T \in \mathbb{R}^{100 \times 5000}$.
2. The sample covariance matrix is $\mathbf{\Sigma} = \frac{1}{n-1}\tilde{\mathbf{X}}^T\tilde{\mathbf{X}} \in \mathbb{R}^{5000 \times 5000}$. Computing its eigenvalues directly requires $O(p^3) = 5000^3 = 1.25 \times 10^{11}$ operations.
3. Instead, apply SVD directly to $\tilde{\mathbf{X}}$ or eigendecompose the smaller Gram matrix $\mathbf{K} = \frac{1}{n-1}\tilde{\mathbf{X}}\tilde{\mathbf{X}}^T \in \mathbb{R}^{100 \times 100}$ in $O(n^2 p) = 100^2 \times 5000 = 5 \times 10^7$ operations ($2500\times$ faster!).
4. The singular values $s_j$ relate directly to the covariance eigenvalues $\lambda_j$:
$$\lambda_j = \frac{s_j^2}{n - 1}$$5. Project the 100 patient samples into the reduced $k$-dimensional principal subspace ($k \ll 100$):
$$\mathbf{Z}_k = \tilde{\mathbf{X}}\mathbf{V}_k = \mathbf{U}_k \mathbf{S}_k \in \mathbb{R}^{100 \times k}$$We select $k$ using the cumulative explained variance ratio ($\ge 85\%$):
$$\frac{\sum_{j=1}^k \lambda_j}{\sum_{m=1}^{n-1}\lambda_m} \ge 0.85$$04. Translating Latent Clusters to Biological Biomarkers
Nov 2025 (Q5) Part (iii) Challenge & Solution (6 Marks).
The Interpretation Barrier:
K-Means identifies patient clusters in reduced space $\mathbf{Z}_k$ (e.g. $[\text{PC}_1, \text{PC}_2]$). However, principal components are mathematical linear combinations of all 5,000 genes: $\text{PC}_1 = v_{1,1}\text{Gene}_1 + \dots + v_{5000,1}\text{Gene}_{5000}$. Oncologists cannot treat patients based on eigenvectors; they need specific mutated driver genes.
The 3-Step Methodological Solution:
- 1. Factor Loading Deconvolution:
Inspect the right singular vectors (gene loadings) $\mathbf{V}_k$. Genes with the highest absolute loading coefficients $|v_{j, k}|$ contribute most to separating the patient cohorts. - 2. Differential Expression Analysis (DEA):
Map cluster labels back to the original 5,000-gene space. Conduct two-sample Welch's $t$-tests comparing cluster samples against the remaining cohort with Benjamini-Hochberg False Discovery Rate (FDR) correction: $$q_j = P_j \times \frac{p}{\operatorname{rank}(P_j)} \le 0.05$$ Construct Volcano plots ($-\log_{10}(q)$ vs Fold Change) to isolate statistically significant up- and down-regulated biomarkers. - 3. Gene Ontology (GO) & Pathway Enrichment (GSEA):
Feed identified biomarker genes into KEGG or Gene Ontology pathway databases to translate mathematical clusters into biological disease mechanisms (e.g. *"Subtype 2 shows upregulation in DNA mismatch repair pathways"*).
05. Notation Decoding Matrix
| Symbol | Formal Name | Plain-English Meaning | Bioinformatics Value |
|---|---|---|---|
| $n, p$ | Samples & Features | Number of patients ($n$) and genes ($p$) | $n = 100$ patients, $p = 5,000$ genes |
| $\operatorname{WCSS}$ | Within-Cluster Sum of Squares | Total compactness of points around their centroid | Minimized by K-Means algorithm |
| $s(i)$ | Silhouette Coefficient | Score measuring balance of cohesion vs separation | $s \in [-1, +1]$ (Higher is better) |
| $\mathbf{U}$ | Left Singular Vectors | Orthonormal eigenvectors of patient Gram matrix | $\mathbf{U} \in \mathbb{R}^{100 \times 100}$ |
| $\mathbf{S}$ | Singular Values | Square roots of eigenvalues scaled by $n-1$ | $\lambda_j = s_j^2 / (n-1)$ |
| $\mathbf{V}$ | Right Singular Vectors (Loadings) | Weights of each gene in forming principal components | $\mathbf{V} \in \mathbb{R}^{5000 \times 100}$ |
06. Repeatable Step-by-Step Solving Protocol
State distance metric concentration ($\operatorname{dist}_{\max} \approx \operatorname{dist}_{\min}$) and rank deficiency ($\text{rank} \le 99$).
Iterate assignment and centroid update steps until WCSS reaches local minimum.
Inspect loadings $\mathbf{V}_k$, perform Differential Expression Analysis (FDR $q \le 0.05$), and pathway enrichment.
07. 6 Deadly Exam Traps & Common Student Mistakes
Writing $\mathbf{\Sigma} = \mathbf{X}^T\mathbf{X} \in \mathbb{R}^{5000 \times 5000}$
Eigendecomposing a $5000 \times 5000$ matrix requires $O(p^3) = 1.25 \times 10^{11}$ operations. Always specify Dual SVD or $\mathbf{X}\mathbf{X}^T \in \mathbb{R}^{100 \times 100}$ in $O(n^2 p)$ operations.
Applying SVD to Raw Data Matrix
PCA maximizes sample variance around the mean. If $\mathbf{X}$ is not centered ($\tilde{\mathbf{X}} = \mathbf{X} - \bar{\mathbf{X}}$), the first principal component points directly toward the dataset mean rather than direction of maximum variance.
Claiming K-Means Solves Convex Minimization
WCSS has multiple local minima depending on initial seeds. K-Means is non-convex; you must mention K-Means++ initialization or multiple restarts (`n_init=10`).
Mixing Up $\mathbf{V}$ and $\mathbf{Z}$
$\mathbf{Z} \in \mathbb{R}^{n \times k}$ are the Principal Component Scores (patient coordinates). $\mathbf{V} \in \mathbb{R}^{p \times k}$ are the Factor Loadings (gene weights). Biologists inspect loadings $\mathbf{V}$ to identify biomarkers.
Clustering Unstandardized Features
Features with huge numerical ranges completely dominate the Euclidean distance metric. Z-score scaling is mandatory.
Selecting $K$ where WCSS is Zero
Setting $K = N$ makes every point its own centroid ($\text{WCSS} = 0$), which provides zero clustering value. Choose $K$ at the inflection elbow or peak Silhouette score.
08. Complete University Question Bank (All Past PYQs Solved)
Nov 2025 · Question 5 Bioinformatics Gene Expression PCA & K-Means (20 Marks)
A bioinformatics dataset has 5,000 genes ($p$) and 100 samples ($n$). Goal is to discover disease subtypes.
i) Justify need for dimensionality reduction in this specific scenario. (6 Marks)
ii) Propose a suitable technique and explain its working principle. (8 Marks)
iii) You apply K-Means to identify subtypes. Explain a key challenge when interpreting clusters and how to address it. (6 Marks)
Solution:
(i) Justification for Dimensionality Reduction ($p \gg n$) (6 Marks)
- Distance Metric Degeneration (Loss of Contrast): Pairwise Euclidean distances converge to a uniform scalar: $\lim_{p \to \infty} \frac{\text{dist}_{\max} - \text{dist}_{\min}}{\text{dist}_{\min}} \to 0$. In 5,000 dimensions, every patient becomes equidistant from every other patient.
- Rank Deficiency: The $100 \times 5000$ matrix has rank at most $\min(n-1, p) = 99$. The data lies entirely on a 99-dimensional manifold; the remaining 4,901 dimensions represent noise.
- Multicollinearity: Co-regulated genes contain massive redundancy that destabilizes distance calculations.
(ii) Proposed Technique: PCA via Dual SVD (8 Marks)
1. Center the matrix: $\tilde{\mathbf{X}} = \mathbf{X} - \mathbf{1}\boldsymbol{\mu}^T \in \mathbb{R}^{100 \times 5000}$.
2. Avoid computing the $5000 \times 5000$ covariance matrix ($O(p^3) = 1.25 \times 10^{11}$ operations). Instead apply SVD directly to $\tilde{\mathbf{X}}$ in $O(n^2 p) = 5 \times 10^7$ operations:
$$\tilde{\mathbf{X}} = \mathbf{U} \mathbf{S} \mathbf{V}^T$$3. Relate singular values to covariance eigenvalues: $\lambda_j = \frac{s_j^2}{n - 1}$.
4. Project samples to $k$ components based on cumulative explained variance: $\mathbf{Z}_k = \tilde{\mathbf{X}}\mathbf{V}_k \in \mathbb{R}^{100 \times k}$ with $\sum_{j=1}^k \lambda_j / \sum \lambda_m \ge 0.85$.
(iii) Cluster Interpretation Challenge & Solution (6 Marks)
The Challenge: Principal components are abstract linear mixtures of all 5,000 genes ("Latent Space Barrier"). Clinicians cannot prescribe medicine based on eigenvalues; they need specific mutated driver genes.
Methodological Solutions:
- Factor Loading Inspection: Identify genes with largest absolute weights $|v_{j,k}|$ in the right singular vectors $\mathbf{V}_k$.
- Differential Expression Analysis (DEA): Map clusters back to 5,000-gene space. Perform Welch's $t$-tests with Benjamini-Hochberg FDR correction ($q \le 0.05$) to isolate statistically significant driver biomarkers.
- Gene Ontology Enrichment: Match biomarkers against KEGG biological pathways to reveal treatable disease mechanisms.
Jan 2025 · Question 7 K-Means Clustering Mechanics, WCSS & Elbow Method (20 Marks)
Explain the working principle of the K-Means clustering algorithm. Formulate its mathematical objective function. Describe how the optimal number of clusters ($K$) is determined using the Elbow Method and Silhouette analysis. Discuss sensitivity to initialization and feature scaling. (20 Marks)
Solution:
1. Objective Formulation (6 Marks)
$$\arg\min_{\mathcal{C}} \operatorname{WCSS}(\mathcal{C}) = \sum_{k=1}^K \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2$$Iterates between Assignment Step ($c_i = \arg\min_k \|\mathbf{x}_i - \boldsymbol{\mu}_k\|^2$) and Update Step ($\boldsymbol{\mu}_k = \frac{1}{|C_k|}\sum \mathbf{x}_i$).
2. Determining Optimal $K$ (6 Marks)
- Elbow Method: Plot WCSS vs $K$. Identify the sharp inflection "elbow" point where marginal variance explained decreases.
- Silhouette Analysis: $s(i) = \frac{b(i) - a(i)}{\max(a(i), b(i))}$. Choose $K$ that maximizes mean silhouette coefficient across all points.
3. Initialization & Scaling (8 Marks)
- K-Means++: Prevents poor local minima by selecting initial seeds with probability $P(\mathbf{x}) \propto D(\mathbf{x})^2$, spreading centroids across data space.
- Feature Scaling: Mandatory. Without Z-score standardization, features with larger magnitudes dominate the Euclidean distance calculation.
09. Interactive Offline WCSS Calculator
Test your understanding of Within-Cluster Sum of Squares. Calculate Euclidean distances from 1D points to candidate centroids.
10. Active Recall Self-Test Quiz
11. Exam Hall Answer Sheet Presentation Checklist
State: (1) Distance metric concentration, (2) Rank deficiency ($\le 99$), (3) High collinearity and visual intractability.
Always write $\tilde{\mathbf{X}} = \mathbf{X} - \mathbf{1}\boldsymbol{\mu}^T$. Mention that uncentered PCA distorts variance.
Highlight: $O(n^2 p) = 5 \times 10^7$ vs $O(p^3) = 1.25 \times 10^{11}$ operations ($2500\times$ speedup). Write $\lambda_j = \frac{s_j^2}{n-1}$.
Write $\arg\min \sum_{k=1}^K \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2$. Detail assignment and update steps.
Cite: (1) Factor loadings $\mathbf{V}$, (2) Differential Expression Analysis with Benjamini-Hochberg FDR $q \le 0.05$, (3) Gene Ontology (GO) enrichment.