ML Systems Lab Open interactive version →
Advanced 40 min read t-SNEUMAPvisualisationmanifold

t-SNE & UMAP

Perplexity, why t-SNE clusters mislead, UMAP vs t-SNE tradeoffs

You have 50,000 single-cell RNA sequences, each described by 20,000 gene expression values. You want a 2D visualization to see whether cell types cluster naturally. PCA gives a blurry projection where all cells overlap. t-SNE produces a crisp 2D visualization where distinct cell types form separated islands — and that visualization guided the discovery of a previously unknown rare cell population, 0.1% of cells with a distinct gene expression profile invisible in PCA.

t-SNE: computes pairwise similarities in high dimensions (Gaussian distribution of distances, perplexity parameter controls effective neighborhood size). Computes pairwise similarities in low dimensions (Student t-distribution — heavier tails prevent crowding). Minimizes KL divergence between the two similarity distributions via gradient descent. The heavy tails in low dimensions mean that moderate distances in high dimensions map to large distances in low dimensions — this creates the well-separated clusters that make t-SNE visualizations visually striking.

UMAP (Uniform Manifold Approximation and Projection): grounded in Riemannian geometry and topological data analysis. Preserves more global structure than t-SNE, faster (O(n log n) vs O(n²)), supports out-of-sample transformation (new points can be projected without refitting). Default choice over t-SNE for most use cases.

NOT-this: "t-SNE cluster distances are interpretable." The distances between clusters in a t-SNE plot are meaningless — a cell type that appears far from another in t-SNE might be close in the actual high-dimensional space. t-SNE preserves local neighborhoods but distorts global distances. Never interpret inter-cluster distances in a t-SNE plot. UMAP preserves more global structure but still warps distances.

Key points

Takeaway

t-SNE and UMAP are for looking at data, not for generating features — inter-cluster distances in t-SNE are deliberately distorted, UMAP's are approximate, and clustering on either's 2D output will mislead you at exactly the boundaries that matter most.

Recap

Check your understanding

Q1. You run t-SNE with perplexity=5 and see 50 tiny, tight clusters. You run with perplexity=100 and see 3 blobs. Which two of the following are correct ways to figure out the "true" structure?

Q2. A team visualises 50,000 single-cell RNA-seq measurements with t-SNE, sees 12 distinct clusters, and runs k-means on the 2D t-SNE embedding. Explain two problems with this approach.

Q3. Your t-SNE plot shows two large clusters that are completely separated. Does this mean these two groups are very different from each other in the original space?

Q4. You need to compress 768-dimensional BERT embeddings to 2D for visualisation and downstream k-means clustering. What is your pipeline and why?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →