AI Compass
Compass

Dimensionality reduction

Turning a thousand columns into two without losing what matters: PCA, UMAP, and why a beautiful map supports few conclusions.

·2 min read·By Fachredaktion Technik
DETAIL
3 sections

The idea

An object casts a shadow. The shadow has two dimensions instead of three and is still often recognisable. Dimensionality reduction looks for the angle from which the shadow reveals most.

What it is good for

  • Condensing a thousand features into fifty so a model trains faster.
  • Drawing a dataset on two axes to get any impression at all.
  • Removing noise by discarding the weakest directions.

Which method when

PurposeMethodWhy
Preprocessing for a modelPCALinear, fast, applies to new data
Removing noisePCA, truncated SVDWeak directions are mostly noise
Display, local structureUMAPPreserves neighbourhoods well
Display, small datasetst-SNESeparates groups clearly, slow
Very sparse matricesTruncated SVDDoes not require centring the matrix
import numpy as np
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

rng = np.random.default_rng(0)
X = StandardScaler().fit_transform(rng.normal(size=(2000, 60)))

p = PCA().fit(X)
cum = np.cumsum(p.explained_variance_ratio_)
print("components for 95 % variance:", int(np.searchsorted(cum, 0.95) + 1))
# Always run PCA on standardised data, otherwise the column with the
# largest unit determines the first principal component.

PCA formally

Principal component analysis

Σ = (1/(n−1)) · XᵀX Σ wₖ = λₖ wₖ explained variance of k = λₖ / Σⱼ λⱼ

Principal components are the eigenvectors of the covariance matrix, ordered by the size of their eigenvalues.

X
the centred data matrix, n by d
Σ
the covariance matrix
wₖ
the k-th eigenvector, that is the k-th principal component
λₖ
its eigenvalue, the explained variance

In practice you compute the singular value decomposition X = U S Vᵀ rather than the eigendecomposition of XᵀX: numerically more stable, and V contains the principal components directly.

The curse of dimensionality, quantified

For uniformly distributed points in the d-dimensional unit cube,

Distance concentration

(d_max − d_min) / d_min → 0 as d → ∞

As dimension grows, the ratio of largest to smallest distance approaches one.

d_max
largest distance to a random point
d_min
smallest distance

At d = 2 that ratio is typically several hundred percent; at d = 100 it is in the single-digit percent range. Practical consequence: nearest-neighbour search on raw high-dimensional features says little. Embeddings escape this because their points are not uniformly distributed but lie on a far lower-dimensional manifold.

Reading UMAP maps properly

  • Neighbourhoods are usually reliable, global distances are not.
  • The size of a group on the map says nothing about its spread in the original space.
  • Two runs with different seeds give different pictures. Always look at several.
  • Never cluster on the map and report the result as a finding, cluster in the original space and use the map only to show it.

Related courses and sources

CourseFree2400 minEN

MIT 18.065 Matrix Methods

Singular value decomposition, principal components and optimisation applied to data. The bridge between linear algebra and what models actually compute.

For the step from pure mathematics to what models actually compute.

MIT OpenCourseWareGo to offer
Was this page helpful?
Dimensionality reduction