Sub topic 15
t-SNE versus UMAP: differences that matter
This chapter assumes you have read the earlier chapters on t-SNE affinities, perplexity, the Student-t kernel, and UMAP's graph construction and parameters. You should also be comfortable with scikit-learn's fit and fit_transform interface.
Both methods are neighbour embeddings. Each builds a description of local neighbourhoods in the original space, then moves points in 2-D until the layout matches that description. The differences lie in how each method writes down the neighbourhoods, how it scores the layout, and how it searches for a solution. These choices explain most of the practical differences you see on screen.
The two pipelines side by side
Where the methods differ
Input weights
t-SNE gives every point a Gaussian bandwidth, chosen by binary search so the neighbourhood has the requested perplexity. It then symmetrises the conditional probabilities. Every pair of points gets a weight, though most weights are tiny. In practice, implementations compute only the nearest roughly 3 * perplexity neighbours per point and treat the rest as zero.
UMAP starts from an explicit k-nearest-neighbour graph with n_neighbors neighbours per point. It sets each point's nearest-neighbour distance to weight 1 (the local connectivity step), and it scales the remaining distances so the neighbourhood has a fixed total weight. Edges from the two directions are combined with a fuzzy union, a + b - a*b. The result is a sparse graph by construction.
Output kernel and objective
t-SNE uses a Student-t kernel with one degree of freedom, 1 / (1 + d^2), in the low-dimensional space. It minimises the KL divergence between two normalised distributions. Because each distribution sums to one over all pairs, moving one point changes every pair's probability. This global normalisation is one reason t-SNE is expensive.
UMAP uses a kernel of the form 1 / (1 + a * d^(2b)). It fits a and b from min_dist and spread. A small min_dist makes the curve fall off sharply, so connected points can sit close together. UMAP minimises a cross-entropy between fuzzy edge memberships. This loss has an attractive term for graph edges and a repulsive term for non-edges. Neither term needs a normalising constant over all pairs.
Optimisation
t-SNE runs gradient descent with momentum. It uses early exaggeration, which multiplies the input probabilities by a constant (12 in scikit-learn) for the first iterations. This lets clusters move freely before they settle. Barnes-Hut or FFT-accelerated approximations compute the repulsive forces.
UMAP uses stochastic gradient descent over edges. For each sampled edge it applies an attractive update, and it also samples a few random points as negatives to push away. Edge sampling is proportional to weight, and the learning rate decays linearly over the epochs. Skipping the global normalisation makes each epoch cheap.
Initialisation
scikit-learn's TSNE defaults to init="random" in older versions and "pca" in current ones. PCA is the better choice. UMAP defaults to a spectral embedding of the graph, which falls back to random initialisation when the graph has many components or the spectral step fails.
Initialisation matters more than the method names suggest. Kobak and Linderman (2021) showed that t-SNE with PCA initialisation preserves global layout about as well as UMAP does. Much of the folk claim that "UMAP keeps global structure and t-SNE does not" comes from comparing a random-start t-SNE with a spectral-start UMAP.
Summary table
| Aspect | t-SNE | UMAP |
|---|---|---|
| Neighbourhood control | `perplexity` | `n_neighbors` |
| Input weights | Gaussian, calibrated per point, symmetrised | Fuzzy kNN graph, fuzzy union |
| Low-D kernel | Student-t (fixed) | Tunable curve via `min_dist` |
| Loss | KL divergence on normalised pairs | Cross-entropy on edges, with sampled negatives |
| Default init | PCA (current scikit-learn) | Spectral |
| New points | No `transform` in scikit-learn | `transform` available |
| Cluster tightness | Controlled indirectly by perplexity and exaggeration | Controlled directly by `min_dist` |
| Typical speed | Slower, especially on large data | Faster, scales better |
Comparing them on one dataset
This script runs both methods on the digits data, then times each one and scores it with trustworthiness.
import time
import umap # installed as the umap-learn package
from sklearn.datasets import load_digits
from sklearn.manifold import TSNE, trustworthiness
X, y = load_digits(return_X_y=True)
models = [
("t-SNE", TSNE(perplexity=30, init="pca", learning_rate="auto",
random_state=0)),
("UMAP", umap.UMAP(n_neighbors=15, min_dist=0.1, random_state=0)),
]
for name, model in models:
start = time.perf_counter()
Z = model.fit_transform(X)
elapsed = time.perf_counter() - start
score = trustworthiness(X, Z, n_neighbors=10)
print(f"{name}: {elapsed:.1f} s, trustworthiness = {score:.3f}")On a dataset this small, expect both scores to be high and close together. Runtime on 1,797 points says little about behaviour at 1,000,000. The gap grows with data size, and your hardware will change the absolute numbers.
Practical consequences
Out-of-sample points
UMAP learns a mapping that can place unseen points with transform. It does this by finding their neighbours in the training set and optimising their position against the fixed training embedding. scikit-learn's TSNE has only fit_transform, so new data needs a full refit and gives a different layout. Treat UMAP's transform as an approximation. Test points that lie far from the training data can land in misleading places.
Controlling tightness
Tight, well-separated clusters in UMAP are partly a choice. A small min_dist makes groups look compact. Raising it to 0.5 or more spreads points inside each cluster and can reveal internal structure. t-SNE has no direct equivalent, so cluster appearance depends on perplexity and on how long you optimise.
Instability and seeds
Neither method gives a unique answer. Rerun with several seeds. If a feature appears in only one run, do not interpret it.
Decision criteria
Choose by the constraints of your task, not by reputation.
- Dataset size. Below about 50,000 points, both are fast enough, so pick on other criteria. At hundreds of thousands of points or more, UMAP is usually the practical choice, though FFT-based t-SNE implementations can also handle that scale.
- New data arriving. If you must embed future samples consistently, use UMAP.
- Local detail. For fine within-cluster structure, t-SNE with a moderate perplexity is often cleaner.
- Layout you can tune. If you want to trade compactness against spread, UMAP gives you
min_dist. - Downstream use. If the embedding feeds clustering or another model, UMAP can use more than 2 dimensions with the same code. Distances in a 2-D t-SNE plot are rarely meaningful enough for that.
Exercise
You embed 2,000 customer records with t-SNE, and next month you receive 200 new records that you want on the same map. Why is this a problem, and what are two ways to handle it?
Show answer
scikit-learn's TSNE has no transform method, so it cannot place new points in the existing layout. Refitting on all 2,200 points gives a different map, with positions and orientation that may change. Option 1: fit UMAP on the original 2,000 and call transform on the new 200, then check that the new points land near similar records. Option 2: keep t-SNE, refit on all 2,200 with the same PCA initialisation and seed to reduce the drift, and accept that the map is new.
Exercise
A colleague says UMAP is better than t-SNE because UMAP plots show the relative positions of clusters, but t-SNE plots do not. Name one confound in this claim and one experiment that tests it.
Show answer
The confound is initialisation. UMAP defaults to a spectral start and t-SNE is often run from a random start, so the two differ in more than the algorithm. To test it, run t-SNE with init="pca" and UMAP with init="random" on the same data across several seeds. Then compare how stable the cluster arrangement is between runs.