Skip to content
GATEiit

GATE DA · Machine Learning

Dimensionality reduction: principal component analysis (PCA)

Principal component analysis: centring data, finding principal components as eigenvectors of the covariance matrix, explained variance, choosing k, projection and reconstruction error, and the link with SVD.

Before you start

This topic comes before: Data types; data transformation: normalization, discretization, sampling and compression

Concept notes

1. The goal and the set-up

Dimensionality reduction replaces d features by k<d new features while keeping as much information as possible. PCA does this with a linear map chosen to keep the most variance. It is unsupervised: it never looks at labels.

Set-up for n points x1,…,xn∈Rd:

  1. Centre the data: subtract the mean μ from every point. Stack the centred points as rows of X (n×d).
  2. Form the covariance matrix S=1nXTX (d×d, symmetric, positive semidefinite). Some books divide by n−1; the directions do not change, only the eigenvalues scale.
  3. For a unit vector w, the projections wTxi have variance wTSw.

PCA picks w to maximise wTSw subject to ∥w∥=1. With a Lagrange multiplier this gives Sw=λw: the best w is the eigenvector with the largest eigenvalue, and the variance captured is that eigenvalue λ1.

The second component is the best direction orthogonal to the first; it is the eigenvector for λ2, and so on. Because S is symmetric, its eigenvectors can always be chosen orthonormal and its eigenvalues are real and ≥0.

2. Principal components and explained variance

Write S=WΛWT with eigenvalues sorted λ1≥λ2≥⋯≥λd≥0 and orthonormal eigenvectors w1,…,wd as the columns of W.

  • wj is the j-th principal component (a direction, also called the loading vector).
  • The score of a point on it is zj=wjT(x−μ). The variance of the scores is λj.
  • Scores on different components are uncorrelated.
  • Total variance =tr⁡(S)=∑jλj = sum of the variances of the original features.
  • Explained variance ratio of the first k components: λ1+⋯+λkλ1+⋯+λd.

Choosing k: take the smallest k whose cumulative ratio reaches a target (say 90% or 95%), or look for the "elbow" in a scree plot of λj against j.

A zero eigenvalue means the centred data has no spread in that direction: the points lie in a lower-dimensional subspace. With n points there are at most min⁡(n−1,d) non-zero eigenvalues.

x1x2PC1: largest variancePC2 (orthogonal)mean
PC1 points along the direction of greatest spread; PC2 is orthogonal to it and captures the remaining variance.

3. Projection and reconstruction error

Keep the top k components as the columns of Wk (d×k).

  • Reduce: z=WkT(x−μ), a k-dimensional vector.
  • Reconstruct: x^=μ+Wkz=μ+WkWkT(x−μ). The matrix WkWkT is the orthogonal projection onto the span of the top k components.

The mean squared reconstruction error equals the variance thrown away:

1n∑i∥xi−x^i∥2=λk+1+⋯+λd

(with S defined using 1n). So PCA has two equivalent views: it maximises the variance kept and minimises the squared reconstruction error among all k-dimensional linear projections.

When k=d nothing is lost: WWT=I and x^=x.

4. PCA through SVD, scaling and limits

SVD route. Write the centred data as X=UΣVT. Then XTX=VΣ2VT, so:

  • the columns of V are the principal components;
  • λj=σj2/n (or σj2/(n−1) with that convention);
  • the scores are the columns of UΣ.

The explained variance ratio is σ12/∑jσj2, so the 1/n factor cancels.

Scaling. PCA is not scale invariant. A feature measured in larger units has larger variance and dominates PC1. When features have different units, standardise each to mean 0 and variance 1 first; PCA then works on the correlation matrix.

Limits.

PCA does PCA does not
find linear directions of maximum variance use class labels (LDA does)
give uncorrelated features guarantee the kept directions help classification
reduce noise by dropping small-variance directions capture curved (non-linear) structure

Outliers can pull PC1 towards themselves, because variance squares the distances.

Formulas to remember

Covariance of centred dataX is the n×d centred data matrix
S=1nXTX
Principal componentsOrthonormal eigenvectors of S
S wj=λj wj,λ1≥λ2≥⋯≥λd
Variance along a unit vectorMaximised by w1, with value λ1
Var⁡(wTx)=wTS w
Explained variance ratio
λ1+⋯+λkλ1+⋯+λd
Score and reconstruction
z=WkT(x−μ),x^=μ+Wkz
Mean squared reconstruction error
1n∑i∥xi−x^i∥2=∑j=k+1dλj
Link with SVD
X=UΣVT,λj=σj2n

Common mistakes

  • Forgetting to centre the data before forming XTX; without centring the top direction may just point at the mean.
  • Using the eigenvector with the smallest eigenvalue as PC1. Sort eigenvalues in decreasing order.
  • Computing explained variance from singular values directly instead of their squares.
  • Running PCA on raw features in different units; the large-unit feature dominates. Standardise first.
  • Thinking PCA picks a subset of original features. Each component is a linear combination of all features.
  • Treating PCA as a supervised method; it ignores labels, so the kept directions need not separate classes.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Principal components of four points

numerical

Find the principal components of the points (0,0), (2,2), (1,3), (3,1), the fraction of variance explained by PC1, and the PC1 score of (0,0). Use S=1nXTX.

  1. Step 1: Centre the data.

    Try it on paper first.

Example 2: How many components to keep

numerical

The covariance matrix of a 5-feature data set has eigenvalues 5, 3, 1.2, 0.5, 0.3. Find the smallest k that keeps at least 90% of the variance, and the mean squared reconstruction error for that k.

  1. Step 1: Find the total variance.

    Try it on paper first.

Example 3: Why the top eigenvector gives the most variance

numerical

For , compare the variance of projections along u=(1,0) and w=12(1,1).

  1. Step 1: Compute $u^{T}Su$.

    Try it on paper first.

Example 4: Should you standardise first?

conceptual

A data set has two features: annual income in rupees (values in lakhs) and age in years. PCA is run on the raw covariance matrix. What will PC1 look like, and what should be done?

  1. Step 1: Compare the variances of the raw features.

    Try it on paper first.

Previous year questions

3 official GATE DA questions on this topic, newest first.

Practise these 3 PYQs →

Topic test

10 questions: up to 3 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.