∑GATE DA Atlas

Dimensionality Reduction and Principal Component Analysis

Why reduce dimensions, feature selection vs feature extraction, PCA from two viewpoints (maximum variance and minimum reconstruction error), the algorithm via the covariance eigendecomposition or the SVD, a fully worked 2-D example, explained variance and choosing the number of components, scores and reconstruction, standardisation, and limitations with non-linear alternatives.

Section 610 practice questions

Why reduce dimensionality?

High-dimensional data is expensive to store and process, hard to visualise, prone to overfitting, and suffers from the curse of dimensionality (see k-NN). Often the data actually lies near a lower-dimensional subspace because features are correlated.

ApproachIdeaExamples
Feature selectionkeep a subset of the original featuresfilter (correlation, mutual information), wrapper (forward/backward selection), embedded (lasso, tree importance)
Feature extractionbuild new features as combinations of the oldPCA, LDA, autoencoders, random projections

PCA: the idea

Find new orthogonal axes — principal components — ordered so that the first captures as much variance as possible, the second as much of the remaining variance as possible, and so on. Keep the first kk and discard the rest.

PC1 (large variance) PC2
PC1 points along the long axis of the cloud; PC2 is perpendicular to it.

Two equivalent views

  1. Maximum variance: the first direction v1\mathbf v_1 maximises the variance of the projections, max⁡∥v∥=1v⊤Σv\max_{\lVert\mathbf v\rVert = 1}\mathbf v^\top\Sigma\mathbf v. By the Rayleigh quotient (see quadratic forms) the answer is the top eigenvector, with variance λ1\lambda_1.
  2. Minimum reconstruction error: the kk-dimensional subspace minimising ∑i∥xi−x^i∥2\sum_i\lVert\mathbf x_i - \hat{\mathbf x}_i\rVert^2 (squared perpendicular distances) is spanned by the top kk eigenvectors; the error equals the sum of the discarded eigenvalues.

The algorithm

  1. Centre the data: xi←xi−xˉ\mathbf x_i \leftarrow \mathbf x_i - \bar{\mathbf x} (and standardise if features have different units).
  2. Compute the covariance matrix Σ=1n−1X⊤X\Sigma = \frac{1}{n-1}X^\top X (p×pp \times p).
  3. Eigendecompose Σ=VΛV⊤\Sigma = V\Lambda V^\top with λ1≥λ2≥⋯≥λp≥0\lambda_1 \ge \lambda_2 \ge \dots \ge \lambda_p \ge 0.
  4. Keep the first kk eigenvectors Vk=[v1⋯vk]V_k = [\mathbf v_1 \cdots \mathbf v_k].
  5. Scores (new coordinates): Z=XVkZ = XV_k (n×kn\times k). Reconstruction: X^=ZVk⊤\hat X = ZV_k^\top (+ mean).

Equivalently, take the SVD X=UΣV⊤X = U\Sigma V^\top of the centred data: principal directions are the columns of VV, variances σj2/(n−1)\sigma_j^2/(n - 1), scores UΣU\Sigma. The SVD route is numerically preferred.

Python
import numpy as np

def pca(X, k):
    Xc = X - X.mean(axis=0)
    U, s, Vt = np.linalg.svd(Xc, full_matrices=False)
    var = s ** 2 / (len(X) - 1)
    return Xc @ Vt[:k].T, Vt[:k], var / var.sum()     # scores, directions, explained ratios

Worked example

Take the points (2,0),(0,2),(3,3),(−1,−1)(2, 0), (0, 2), (3, 3), (-1, -1). Their mean is (1,1)(1, 1), so the centred points are (1,−1),(−1,1),(2,2),(−2,−2)(1, -1), (-1, 1), (2, 2), (-2, -2).

  • Covariance (n−1=3n - 1 = 3): Σ=13(1+1+4+4−1−1+4+4⋅1+1+4+4)=13(106610)\Sigma = \frac13\begin{pmatrix}1+1+4+4 & -1-1+4+4\\ \cdot & 1+1+4+4\end{pmatrix} = \frac13\begin{pmatrix}10 & 6\\6 & 10\end{pmatrix}.
  • Eigenvalues: 163\frac{16}{3} along 12(1,1)\frac{1}{\sqrt2}(1, 1) and 43\frac43 along 12(1,−1)\frac{1}{\sqrt2}(1, -1).
  • PC1 explains 16/320/3=80%\frac{16/3}{20/3} = 80\% of the variance.
  • Scores on PC1: (1,−1)→0(1, -1) \to 0, (−1,1)→0(-1, 1) \to 0, (2,2)→22(2, 2) \to 2\sqrt2, (−2,−2)→−22(-2, -2) \to -2\sqrt2.

How many components?

  • Explained variance ratio λj∑iλi\frac{\lambda_j}{\sum_i\lambda_i}; keep enough components for a cumulative threshold (e.g. 90–95%).
  • Scree plot: plot eigenvalues against index and look for the elbow.
  • Kaiser rule (standardised data): keep components with λ>1\lambda > 1.
  • Or choose kk by downstream cross-validated performance.

Practical points

PointDetail
Centringessential — otherwise PC1 just points towards the mean
Scalingstandardise when units differ (PCA on the correlation matrix)
Rankat most min⁡(n−1,p)\min(n - 1, p) non-zero components
Interpretationloadings (entries of vj\mathbf v_j) show which original features drive each component
Usesvisualisation (2-D/3-D), compression, denoising, decorrelating features before regression (principal component regression), speeding up other algorithms

Limitations

  • Linear only — curved manifolds need kernel PCA, Isomap, t-SNE, UMAP or autoencoders.
  • Maximises variance, which need not align with class separation (use LDA when labels exist).
  • Sensitive to outliers and to feature scaling; components can be hard to interpret.

Quick revision

Practice questions

GATE-style questions: 3 one-mark and 7 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

Centred data has covariance matrix (5222)\begin{pmatrix}5 & 2\\2 & 2\end{pmatrix}. The fraction of total variance explained by the first principal component is ______ (round to two decimals).

Q2NAT2 marks

The eigenvalues of a covariance matrix are 5,3,1,0.5,0.55, 3, 1, 0.5, 0.5. The minimum number of principal components needed to retain at least 90% of the total variance is ______.

Q3MCQ1 mark

The principal component directions of a data set are

Q4MSQ2 marks

Which statements about PCA are correct?

One or more options are correct.

Q5NAT2 marks

The first principal direction is v1=(0.6,0.8)\mathbf v_1 = (0.6, 0.8). A centred data point (3,4)(3, 4) has PC1 score z1=v1⊤x=z_1 = \mathbf v_1^\top\mathbf x = ______.

Q6NAT2 marks

A data set has covariance eigenvalues 5,3,1,0.5,0.55, 3, 1, 0.5, 0.5. Projecting onto the first 2 principal components and reconstructing, the average squared reconstruction error per (centred) data point (using the same normalisation as the covariance) is ______.

Q7MCQ2 marks

If the centred data matrix XX (n×pn \times p) has SVD X=UΣV⊤X = U\Sigma V^\top, then

Q8NAT1 mark

The total variance of data with covariance matrix (5222)\begin{pmatrix}5 & 2\\2 & 2\end{pmatrix} — which equals the sum of the variances of all its principal components — is ______.

Q9MCQ1 mark

Data lies on a curved, one-dimensional "Swiss-roll" manifold in 3-D. Standard PCA

Q10NAT2 marks

Three data points in R10\mathbb R^{10} are centred by subtracting their mean. The maximum number of principal components with non-zero variance is ______.