Sub topic 1
Why High-Dimensional Data Is Hard to See
Prerequisites
This chapter assumes basic Python and NumPy, scikit-learn's fit and transform pattern, Euclidean distance, feature vectors, probability normalisation, and the basic idea of gradient descent.
Why high-dimensional data is hard to see
A data point with many measurements is a vector in a high-dimensional space. An image with 64 pixel values is a point in 64 dimensions. A table with 1,000 measured features has 1,000 dimensions.
Screens and human vision provide only two or three useful spatial dimensions. A direct plot must therefore discard or combine information. High-dimensional distance can also become less informative: as dimensions increase, many pairwise distances become similar. Noise and irrelevant features can hide meaningful structure.
Dimensionality reduction and what it costs
Dimensionality reduction maps points from a high-dimensional space into a smaller one, often two dimensions:
from sklearn.datasets import load_digits
from sklearn.decomposition import PCA
X, y = load_digits(return_X_y=True)
Z = PCA(n_components=2, random_state=0).fit_transform(X)
print(X.shape, Z.shape)The output has two coordinates per sample, so it can be plotted. The map preserves some relationships and loses others. A visible cluster may reflect real similarity, preprocessing choices, or the method's objective. A two-dimensional embedding is evidence to investigate, not a complete model of the data.
PCA: the linear baseline
Principal component analysis (PCA) finds directions that explain the greatest variance. It then projects every point onto the selected directions. Because this mapping is linear, PCA is fast, reproducible, and easy to interpret.
PCA can miss curved or disconnected structure. Still, it is an essential baseline. If a nonlinear method shows a pattern that PCA cannot show, compare the patterns against the original features before trusting the nonlinear result.
The manifold hypothesis and local neighbourhoods
The manifold hypothesis says that high-dimensional observations may lie near a lower-dimensional, possibly curved surface. For example, many pixel combinations may represent variations of the same object.
This motivates preserving local neighbourhoods rather than all global distances. A neighbourhood is the set of points closest to a given point under a chosen distance metric.
Neighbour embedding: keep neighbours close
Neighbour-embedding methods assign importance to pairs of nearby points. During optimisation, they move points in the low-dimensional map so important neighbours stay close. They usually sacrifice exact global geometry to preserve local structure.
A method's distance metric matters. Euclidean distance is reasonable when features are scaled comparably. Standardising features can prevent a large-unit feature from dominating every neighbourhood.
> callout note > A cluster's area, apparent size, and distance from another cluster may not have a direct meaning. Check the method, parameters, and original data.
t-SNE step 1: turning distances into probabilities
t-SNE first converts distances into conditional probabilities. For point \(i\), a nearby point \(j\) receives a larger probability under a Gaussian distribution. The Gaussian width is adjusted for each point so that its neighbourhood has a chosen effective size, called perplexity.
It then symmetrises these probabilities into pairwise affinities. Later steps find two-dimensional coordinates whose affinities resemble the high-dimensional affinities. This separates the task into a neighbourhood definition and an embedding optimisation.
Exercise
Why should PCA be run before interpreting a t-SNE plot?
Show answer
PCA provides a simple linear baseline, helping you distinguish structure also supported by a transparent method from patterns that may depend on nonlinear optimisation or parameter choices.