t-SNE and UMAP for Visualization
Nonlinear embeddings that reveal clusters and manifolds in 2D, and how to avoid over-reading their pictures.
Intermediate · about 3 hours · difficulty 3/5
Learn first: Principal Component Analysis
t-SNE and UMAP map high-dimensional points (embeddings, images, gene expression) into 2D while trying to keep neighbours close. They produce striking plots that often reveal structure PCA misses.
Differences
- t-SNE focuses on local neighbourhoods;
perplexityroughly sets neighbourhood size. Slow on large data and has no simple transform for new points. - UMAP is faster, tends to preserve more global structure and can transform new data.
n_neighborsandmin_distare the main knobs.
Reading the plots honestly
- Cluster sizes and distances between clusters are not meaningful in t-SNE plots.
- Different random seeds and hyperparameters give different pictures; try several.
- Apparent clusters can appear in pure noise with poor settings.
- Common practice: PCA to around 50 dimensions first, then t-SNE or UMAP.
Uses
Inspecting learned embeddings, spotting mislabelled examples, and exploring data before clustering. Use them as exploration tools, not as features for final models without careful validation.
Good enough to move on when you can produce t-SNE and UMAP plots of the same data, vary their hyperparameters and explain what conclusions are and are not justified.
Key concepts
- t-SNE and perplexity
- UMAP parameters
- Interpretation caveats
- PCA preprocessing
Mini project
Embed Fashion-MNIST with PCA, t-SNE and UMAP, color by label, and write three observations plus one conclusion you deliberately refuse to draw.
Check yourself
In a t-SNE plot, one cluster is twice as large and far from the others. What can you actually conclude?
Free resources
- How to Use t-SNE Effectively (Distill)
- UMAP documentation (umap-learn)
- scikit-learn: Manifold learning (scikit-learn)