CS 460G Midterm Hub / Lectures / Week 6 Lecture 1
Week 6 · Lecture 1

Dimensionality Reduction

Curse of dimensionality, the six PCA steps, and autoencoders as non-linear PCA.

short answercoding Q

Unsupervised learning, part one. Two methods, one goal: keep the information, drop the dimensions.

The taxonomy you should be able to draw

The decision tree of learning methods
The decision tree of learning methods · slide 26

> Do you have labeled data? Yes → supervised → what to predict? category → classification (kNN, logistic regression, SVM, decision trees); numeric → regression. No → unsupervised → group the data? yes → clustering (k-means, hierarchical); no → dimensionality reduction (PCA, autoencoder).

Unsupervised learning splits three ways: clustering (homogeneous subgroups), dimensionality reduction (a lower-dimensional representation that characterises and visualises the data), density estimation (approximates the true data distribution).

The three unsupervised approaches
The three unsupervised approaches · slide 25

Why unsupervised is hard: the goal is not clearly defined, performance is difficult to assess, and the data is high-dimensional.

The curse of dimensionality

Four consequences, each with its own bullet:

  1. With more features $d$, more samples $N$ are required → overfitting.
  2. High-dimensional data is difficult to visualise → loss of interpretability of the underlying structure.
  3. It is computationally expensive to analyse and process.
  4. It can be sparse, with many features having little or no variation → uninformative features.
Four consequences of high dimensionality
Four consequences of high dimensionality · slide 37

The scale of the problem on the deck's examples: a $2400\times2400$ image is 5.76 million dimensions; a 3-D CT volume of $512\times512\times700$ is 183 million.

A 3-D CT scan as a 512x512x700 tensor
A 3-D CT scan as a 512x512x700 tensor · slide 31
A single 2400x2400 image
A single 2400x2400 image · slide 30

The "more features is better" belief is the misconception being attacked, and the performance-versus-number-of-features curve (rise, peak, decline) is the reason dimensionality reduction exists at all.

Model performance peaks at an optimal number of features
Model performance peaks at an optimal number of features · slide 39

What reduction buys you

  • Reduction of features retaining as much information as possible
  • Fewer dimensions → fewer parameters → simpler models
  • Data compression keeping maximum information
  • Visualisation — understanding data in 2-D
  • Noise reduction — discovering the intrinsic dimensionality

PCA

> Assumption: the data lies on a lower-dimensional space. PCA is an unsupervised linear transformation that finds the direction of maximum variance in the reduced space, producing a smaller number of highly uncorrelated features.

PCA — maximum variance, uncorrelated components
PCA — maximum variance, uncorrelated components · slide 45

It constructs a $d\times k$ transformation matrix $W$ and projects:

$$Z = XW, \qquad X \in \mathbb{R}^{N\times d},\; W\in\mathbb{R}^{d\times k},\; Z\in\mathbb{R}^{N\times k}$$

The dxk projection matrix
The dxk projection matrix · slide 46

The six steps — reproduce this list

  1. Standardise the $d$-dimensional dataset (zero mean, unit variance).
  2. Construct the $d\times d$ covariance matrix.
  3. Decompose it into eigenvectors and eigenvalues.
  4. Select the $k$ eigenvectors corresponding to the $k$ largest eigenvalues ($k \ll d$).
  5. Construct the projection matrix $W$ from those top $k$ eigenvectors.
  6. Transform $X$ with $W$ to obtain the new $k$-dimensional feature subspace.
The PCA algorithm
The PCA algorithm · slide 47

Step 1 is not optional. PCA maximises variance, and variance is scale-dependent: a feature in dollars has variance $10^6$ times a feature in metres, so un-standardised PCA simply returns that one feature as PC1. The notebook's StandardScaler().fit_transform(...) before PCA(...) is the code counterpart of this step.

Choosing $k$ — cumulative explained variance. Each eigenvalue divided by the sum of eigenvalues is the proportion of variance carried by that component; take the smallest $k$ whose cumulative sum crosses your threshold (90% in the assignment).

$$\text{explained variance ratio}_j = \frac{\lambda_j}{\sum_{i=1}^{d}\lambda_i}$$

Where PCA is used in the course

  • Breast cancer Wisconsin, 569×30 → 5 components carry ~90% of the variance, and KNN accuracy actually improves from 0.93 to 0.97.
  • 8×8 digits, 1797×64 → 2 components and KNN still reaches ~61%.
  • MRI compression: a 128×96 slice compressed to 16 components and reconstructed, with an error map to show what was lost.
90% of the variance in 5 components
90% of the variance in 5 components · slide 50
MRI — input, reconstruction from the latent, error map
MRI — input, reconstruction from the latent, error map · slide 56

Autoencoders

> A special form of neural network whose input and output are the same; the goal is to minimise reconstruction error.

The 64 → 10 → 64 autoencoder
The 64 → 10 → 64 autoencoder · slide 58

Two components:

  • Encoder $E$ — maps the input to a lower-dimensional latent code
  • Decoder $D$ — reconstructs the input from the latent code

$$z = E(x) = f_E(W_1x), \qquad y = D(z) = f_D(W_2z)$$

$$ \min_{W_1,W_2}\; \frac{1}{2N}\sum_{n=1}^{N}\big\|x^{(n)} - y^{(n)}\big\|^2 $$

The autoencoder objective
The autoencoder objective · slide 63

"PCA vs autoencoder?" PCA is a linear projection: it finds the $k$ orthogonal directions of maximum variance via the eigendecomposition of the covariance matrix, and the encoder/decoder are a single fixed matrix pair with a closed-form solution. An autoencoder is a neural network trained by gradient descent to minimise reconstruction error; the encoder and decoder are learned non-linear maps. If both $f_E$ and $f_D$ are linear, the autoencoder's optimum coincides with PCA — the slide states this explicitly — so the autoencoder is best understood as non-linear PCA. Consequences: the autoencoder can capture curved manifolds that PCA cannot, but it needs more data, a training procedure and hyperparameters, and its latent dimensions are not ordered by explained variance nor guaranteed orthogonal.

The slide's own probe — "Is it supervised or unsupervised?" — has a precise answer worth giving: self-supervised. There are no external labels, but there are targets, namely the inputs themselves. That is why it sits in the unsupervised half of the taxonomy while still being trained with a supervised-style loss.