Skip to content
datarekha

What's the difference between t-SNE and UMAP, and what are the pitfalls of interpreting their plots?

The short answer

t-SNE and UMAP are nonlinear dimensionality-reduction methods for visualizing local neighborhoods. t-SNE is more aggressively local, while UMAP is usually faster and may preserve more coarse structure, but neither plot makes cluster size, density, gaps, or global distances reliably interpretable.

How to think about it

The crisp answer

t-SNE and UMAP are nonlinear dimensionality-reduction methods: they turn data with dozens or thousands of features into a two- or three-dimensional map for visual exploration. t-SNE prioritizes local neighbors and often creates compact islands; UMAP, or Uniform Manifold Approximation and Projection, is usually faster, scales better, and can retain more coarse structure, but neither plot is a faithful map of all distances, densities, or cluster sizes.

The mental model an interviewer wants

Suppose I have 10,000 customer-support tickets represented by 768-number embeddings. Tickets about password resets may be near one another in that 768-dimensional space, even though nobody can draw that space. I want a picture to ask useful exploratory questions: are outage tickets mixed into billing tickets, or did a new release create a strange pocket of tickets?

A neighbor means a point with high similarity under a chosen metric, not necessarily a point that looks close on the page. A dimensionality-reduction method must throw information away: 10,000 points cannot preserve every 768-dimensional relationship in two coordinates. The important difference is which relationships each method spends its limited visual budget preserving.

Why t-SNE makes tight local groups

t-SNE starts with pairwise similarities in the original space. For each point, it chooses a local scale so that nearby points become probabilities; these probabilities are then symmetrized into a high-dimensional distribution called P.

Perplexity controls that local scale. A perplexity of 30 means roughly “consider a neighborhood with 30 effective points,” not “use exactly the 30 nearest points.” The exact neighborhood width adapts to the data. A dense region gets a narrower scale; a sparse region gets a wider one.

t-SNE then places the points in two dimensions and creates another probability distribution, Q, using a heavy-tailed Student-t distribution. The heavy tails give moderately distant points more room than a Gaussian would, helping with the crowding problem: many high-dimensional neighbors are trying to fit around each point in only two dimensions.

The algorithm minimizes KL(P || Q), the Kullback–Leibler divergence between the two distributions. This divergence is asymmetric. Failing to place a true high-dimensional neighbor nearby is penalized much more strongly than placing an extra point nearby. That is why t-SNE is good at exposing local neighborhoods and poor at promising a trustworthy world map.

Perplexity changes the question. With a small value such as 5, t-SNE asks about very local friendships and may split a continuous population into several small islands. With 100, it considers broader neighborhoods and may merge those islands. Initialization, early exaggeration, metric, and random seed also affect the layout. A cluster that appears only with one setting is a hypothesis to investigate, not a finding to announce.

Why UMAP often gives a different picture

UMAP first builds a weighted nearest-neighbor graph. Each point connects to nearby points, and the edge weight represents how strongly the algorithm believes that connection. It combines those local graphs into a fuzzy topological representation, then optimizes a low-dimensional graph to preserve it.

Its main controls have fairly intuitive meanings:

  • n_neighbors=15 makes the graph focus on fairly local structure. A larger value such as 100 includes broader relationships and often makes the map feel more global.
  • min_dist=0.1 controls how tightly points may pack in the final map. Lower values encourage denser-looking groups.
  • metric="cosine" or metric="euclidean" determines what “nearby” means before the graph is built.

Neither parameter changes the original data. Both change the question the picture answers.

UMAP is generally faster and more scalable because it works with a sparse neighbor graph and approximate neighbor-search machinery rather than treating every pair as equally important. That is a practical tendency, not a speed guarantee; the result depends on the metric, implementation, hardware, and sample count.

UMAP may preserve coarse arrangement better than t-SNE, especially with a larger n_neighbors, but its objective still focuses on graph relationships. A large gap in a UMAP plot is not automatically a large distance in the source space.

A concrete, checkable comparison

For the ticket example, I might reduce the embeddings to 50 dimensions first. That often removes weak noise and makes both algorithms cheaper; it is not mandatory. For text embeddings, I would usually consider cosine distance rather than silently accepting Euclidean distance.

from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import umap

X50 = PCA(n_components=50, random_state=42).fit_transform(X)

Z_tsne = TSNE(
    n_components=2,
    perplexity=30,
    init="pca",
    metric="cosine",
    random_state=42,
).fit_transform(X50)

Z_umap = umap.UMAP(
    n_neighbors=15,
    min_dist=0.1,
    n_components=2,
    metric="cosine",
    random_state=42,
).fit_transform(X50)

If X has shape 10,000 by 768, X50 has shape 10,000 by 50, and each result has shape 10,000 by 2.

I would color the dots by an already-known ticket label only after fitting. Then I would inspect several settings: t-SNE perplexities 5, 30, and 100; UMAP neighbor counts 15 and 100. The point is not to pick the prettiest plot. It is to see which neighborhoods survive reasonable choices.

The pitfalls that matter in an interview

A visible cluster is not proof of a real class

Both methods can turn a continuous gradient into apparent islands. t-SNE’s per-point bandwidth adapts to local density, which can make dense and sparse regions look more alike than they were. UMAP’s min_dist and graph construction also affect packing. Five compact islands do not prove that the data-generating process has five categories.

Use labels, domain checks, and a quantitative neighbor-preservation measure to test the story. If the plot suggests that new-release tickets form a cluster, inspect their nearest neighbors in the original space and read the underlying ticket text. The picture is a lead.

Area, density, and gaps are dangerous measurements

A 500-point island occupying the same visual area as a 5,000-point island does not mean the groups have equal density or importance. A broad cloud is not necessarily more variable. An isolated point may be a genuine outlier, or it may be a point whose useful neighbors could not all fit in two dimensions.

In t-SNE especially, distances between well-separated clusters are usually not interpretable. UMAP can make the global arrangement more plausible, particularly with larger n_neighbors, but it does not guarantee that the gap between clusters A and B means twice the dissimilarity of the gap between B and C.

Hyperparameters and metrics are part of the conclusion

For 10,000 observations, perplexity 30 and n_neighbors=15 are reasonable starting points, not laws of nature. The right neighborhood scale depends on the question and the data.

Preprocessing matters just as much. In tabular data, failing to standardize a feature measured in dollars alongside one measured in percentages can make the dollar feature dominate distance. In text, Euclidean and cosine distance can produce different neighborhoods. If the input neighborhoods are wrong, the visualization can be perfectly optimized and still be useless.

Stochasticity can masquerade as discovery

Different seeds can rotate or reflect a map harmlessly, but they can also change local arrangements. A practical failure symptom is a “new cluster” that appears in one run, or a bridge between two groups that disappears in the next.

Fix a seed for a reproducible report, then run several seeds anyway. Compare neighbor membership or cluster stability in the original space. Do not compare raw x and y coordinates between runs: rotations and reflections make those coordinates arbitrary.

The senior answer: when I would use each

I use t-SNE when the immediate question is local: “Do these examples have distinct neighborhoods, and what do those neighborhoods contain?” I use UMAP when I need a faster exploratory map, have more observations, want to vary the local-to-global scale, or may need to map new observations with an implementation that supports transform.

For compression, stable preprocessing, or a downstream model, I would start with PCA, truncated SVD, or a task-specific learned representation. Standard t-SNE is fundamentally a fit-for-this-dataset visualization and has no ordinary out-of-sample transform in the usual scikit-learn workflow.

UMAP implementations such as umap-learn do provide a transform for new observations, so UMAP can sometimes be evaluated as a feature transformer. That is a different claim from saying its two-dimensional plot is meaningful. Fit the transformer on training data only, transform validation and test data, and compare it with the original features and a PCA baseline.

The production pattern is simple: preserve the raw features and preprocessing version, record the metric, parameters, seed, library version, and sample-selection rule, and treat the plot as an analysis artifact. Never let a visually pleasing map become an undocumented data filter.

What they’ll ask next

“Why not just use PCA?”

PCA is linear: it finds directions that explain as much variance as possible and gives a stable mapping for new rows. Use it for compression or as a preprocessing baseline. Use t-SNE or UMAP when the goal is to inspect nonlinear neighborhood structure. PCA may miss a curved manifold; t-SNE or UMAP may hide global geometry.

“Which parameters should I choose?”

Choose them from the question, not from the plot that looks most dramatic. Sweep several perplexities or neighbor counts, use an appropriate metric, keep preprocessing fixed, and check whether the substantive neighborhood survives different seeds and settings. There is no universally correct perplexity or n_neighbors.

“Can I feed the embedding into a classifier?”

Do not feed a two-dimensional t-SNE plot into production. It is optimized for visualization, not a stable predictive coordinate system. UMAP can sometimes be used as a learned transformer, but only with train-only fitting, an out-of-sample transform, cross-validation, and comparison with the original features or PCA. If the model wins because evaluation data leaked into the embedding, the win is fiction.

Say this in the interview

“t-SNE and UMAP preserve local neighborhoods for visualization; t-SNE is more aggressively local, UMAP is usually faster and more tunable for broader structure, and I would validate any apparent cluster across metrics, hyperparameters, and seeds rather than interpret distance, density, or area literally.”

Learn it properly t-SNE & UMAP

Keep practising

All Machine Learning questions

Explore further