Learning LabExplorable explanations
← All artifacts
Machine Learning

PCA vs t-SNE: What Each One Lies About

Both flatten high-dimensional data into a picture, and both lie. PCA keeps the global shape but cannot unbend a curve; t-SNE draws clean clusters whose sizes and spacing mean nothing. Run both and see where each one cheats.

pcat-snedimensionality-reductionembeddings
LiveInteractive · drag, toggle, run it
Machine Learning · Dimensionality Reduction

PCA vs t-SNE: What Each One Lies About

High-dimensional data has to be squashed to two dimensions before you can see it, and every method distorts something on the way down. PCA finds the directions of greatest variance and projects onto them: linear, global, honest about distance, but unable to bend. t-SNE matches the neighbourhood structure instead, drawing crisp clusters that look definitive while quietly throwing away cluster size and the distances between groups. Run both on the same data below and you can see exactly where each one cheats.

The dataset

Points sampled along a curved 1D path (an S laid out in 3D) then embedded in 10D with small noise. The data is intrinsically a line that has been bent. PCA can only rotate and flatten, so the two ends of the S collapse on top of each other; t-SNE follows neighbors along the curve and unrolls it.

points
150
dimensions
10
true clusters
3
seed
7
Side by side

The same points, two projections

t-SNE idle
PCA
PC1 + PC2 hold 98% of total variance. Distances here are real projected distances.
t-SNE
Press Run. The embedding starts as a tiny random cloud and is pulled into shape by the KL gradient.
PC1 variance
78.0%
PC2 variance
20.1%
t-SNE iter
0
KL divergence
PCA trustworthiness
t-SNE trustworthiness
run to ≥200

Trustworthiness (k = 8 neighbours, higher is better) asks: of the points that look like near neighbours in the 2D picture, how many were genuinely close in the original space. It rewards t-SNE for preserving local structure, which is exactly what t-SNE optimises for.

The perplexity knob

t-SNE has a free parameter that reshapes the answer

30

Perplexity sets roughly how many neighbours each point tries to stay close to. It picks the Gaussian bandwidth per point through a binary search so the effective neighbour count matches this target. Changing it rebuilds the embedding from scratch (watch the plot above reset). Low perplexity fractures the data into many tiny islands; high perplexity blurs real clusters together. There is no single correct value, which is the point: the same data yields different pictures depending on a knob you set by hand. PCA has no such knob.

The seed

t-SNE is random; PCA is not

Press Reset embedding a few times. The PCA panel never moves: it is a deterministic eigen decomposition of the covariance matrix, so the projection is fixed by the data alone. The t-SNE panel lands differently each time because it starts from a random initial cloud and descends a non-convex objective. Cluster shapes, orientations, and which side each group ends up on are artifacts of that random start, not facts about the data. Reseed data + init draws a fresh dataset too, so you can confirm the structure is stable while the t-SNE rendering of it is not.

How to read each plot honestly
PCA

The 2D axes are the top two eigenvectors of the covariance matrix, the directions along which the data varies most. Distances and the overall layout are trustworthy projections of the real geometry. The cost: anything that lives along a low-variance direction gets squashed, and a curved manifold cannot be unbent by a linear map, so the S-curve folds onto itself and clusters that separate only along a thin direction can hide.

t-SNE

It minimises the KL divergence between high-D affinities p and low-D Student-t affinities q, so near neighbours stay near and everything else is free to move. That gives clean, well-separated clusters. The caveats are firm: cluster size is meaningless (dense and diffuse groups are inflated to similar blobs), the distance between two clusters is not proportional to their real separation, and the result depends on perplexity and the random seed. Read membership, never geometry.

What is real here: PCA is the exact top-2 eigenvectors of the data covariance via Jacobi rotation, with the genuine explained-variance ratios. t-SNE is the real algorithm: per-point sigma found by binary search to the target perplexity, symmetrised affinities, Student-t low-D kernel, KL gradient with momentum, adaptive gains, and early exaggeration. Point counts are kept near 150 so the O(n squared) gradient runs at interactive speed in the browser.