What is t-SNE, and when should you use it instead of PCA?
Answer
t-SNE (t-distributed stochastic neighbor embedding) is a non-linear visualization method that turns pairwise distances in high-dimensional space into neighborhood probabilities, then arranges low-dimensional points so their own neighborhood probabilities, computed with a heavy-tailed Student-t kernel, match them by minimizing the KL divergence between the two distributions. Use it instead of PCA when the goal is a 2D map that reveals cluster structure: PCA preserves global variance along linear axes, while t-SNE sacrifices global geometry to keep close neighbors close. Do not use it as a preprocessing step for a downstream model: it is transductive (no transform for new points), stochastic across runs, and its cluster sizes and separations are not quantitative.
(1) What It Optimizes: match high-dimensional affinities (Gaussian, calibrated per point) with low-dimensional affinities
(Student-t) via KL divergence; the heavy t-tails let dissimilar points sit far apart without penalty, solving the crowding problem.
(2) Perplexity Is the Knob: it acts as the effective neighbor count per point. Too small fragments clusters, too large merges them; 5 to 50 is the usual range, and results vary with the random seed.
(3) Production Pattern: PCA first, neighbor embedding second. 10x Genomics’ Cell Ranger pipeline runs PCA on gene expression, then computes t-SNE or UMAP projections for its Loupe Browser; UMAP scales better than t-SNE on large cell counts, which is why it has become the default projection at that scale.

Figure 1: The same clustered data two ways: PCA (left) preserves global spread but overlaps clusters that are not linearly separable; t-SNE (right) separates them cleanly. The t-SNE panel’s axes and inter-cluster gaps carry no units and no meaning.
Mathematical Formulation:
Where:
is the probability that
picks
as a neighbor; the per-point
is set so the perplexity matches the chosen value, and the conditionals are symmetrized into
.
is the same affinity computed on the map points
with a Student-t kernel (1 degree of freedom), whose heavy tails prevent crowding.
is the KL divergence between the two affinity matrices, minimized by gradient descent directly on the map coordinates.
| Feature | t-SNE | PCA |
|---|---|---|
| Type | Non-linear, neighbor-graph based | Linear orthogonal projection |
| Preserves | Local neighborhoods | Global variance and large-scale structure (projection can only shrink distances) |
| Output | 2-3D coordinates only, no transform | Reusable projection, any |
| Determinism | Stochastic; reruns differ | Deterministic up to sign flips |
| Right Use | Final-step cluster visualization | Preprocessing, compression, de-correlation |

Figure 2: Perplexity sweeps the effective neighborhood size: at 5 the clusters fragment into fake sub-clusters, at 30 the structure is clean, at 100 distinct clusters merge. Always check a second perplexity before trusting a t-SNE picture.
Leave a Reply