Skip to content
AI.info

Unsupervised learning

UMAP: Graph-Based Embeddings and Tradeoffs

Learn UMAP’s graph construction, key parameters, supervised variants, transform behavior, and limits as a clustering or visualization tool.

By the end you can

Example

Parameter changes that alter the question

UMAP's parameters are modeling choices, not cosmetic controls. The clearest statements of what the resulting picture does not carry come from the people who maintain the tools. A whole second package exists because of one of them. The Bioconductor package densvis ships a density-preserving objective, and it gives its reason for existing plainly: “These embeddings may not accurately represent the local density of data in the original space, resulting in misleading visualisations where the space given to clusters of data does not represent the fraction of the high dimensional space that they occupy.”

  • n_neighbors: Smaller values emphasize fine local neighborhoods; larger values pull in broader connectivity and can merge local detail. umap-learn defaults to 15. Seurat's RunUMAP defaults to 30. One parameter, two standard settings.
  • min_dist: Lower values permit tighter packing in the embedding. They do not prove higher density in the original space. The umap-learn documentation says so itself, in “Using UMAP for Clustering”: “The most notable is that UMAP, like t-SNE, does not completely preserve density. UMAP, like t-SNE, can also create false tears in clusters, resulting in a finer clustering than is necessarily present in the data.” Tighter packing and extra tears are both properties of the drawing.
  • metric: Cosine, Euclidean, correlation or a domain metric define different neighbor graphs before optimization begins. umap-learn defaults to euclidean, Seurat's RunUMAP to cosine. Neither choice is neutral.
  • n_components: Two dimensions favor visualization, while a larger embedding may retain more information for downstream modeling. The umap-learn maintainers' own MNIST run used two, and Seurat's RunUMAP defaults to n.components = 2L.
  • random_state and initialization: Reproducibility improves with fixed settings. But in umap-learn a fixed seed is only exact when the multi-threading is turned off, and stability should still be tested across plausible alternatives.

Key idea

UMAP before clustering changes the clustering problem

Clustering a UMAP embedding can be useful, and the size of the effect is easy to underrate in both directions. The umap-learn maintainers ran the experiment on 70,000 MNIST images and published the numbers. HDBSCAN on a 50-dimensional PCA recovered an adjusted Rand index of 0.0538, and assigned only 17.08% of the points to any cluster at all. On a two-dimensional UMAP embedding fitted with n_neighbors=30 and min_dist=0.0, the same clusterer reached an adjusted Rand index of 0.9239, an adjusted mutual information of 0.9030, and 99.16% of points clustered. K-Means on the same data scored 0.3668. The reducer did not tidy the clustering. It decided it.

The structure it exposes is not arbitrary either. Two-dimensional embeddings have been compared against two-dimensional PCA and against a deliberately meaningless “Picasso elephant” layout. Lause and two colleagues did that comparison in 2024, and reported: “In both metrics, UMAP and t-SNE consistently and strongly outperformed PCA and Picasso elephant embeddings (Fig 2C–2D, >90% vs. <62% accuracy, >15% vs. <5% recall for all datasets).”

Both results hold at once. The reducer has already transformed distance, density and connectivity. A cluster found afterward is a cluster in the learned embedding, not automatically in the original representation. And what it exposes still beats an arbitrary layout by a wide margin. So treat reducer parameters as clustering hyperparameters. Compare with clustering in the original or PCA space, and test stability across refits. A vivid two-dimensional partition should not override contradictory evidence.

A clustering pipeline that includes UMAP must validate the reducer and the clusterer together.

Two standard tools, one word, two different neighbour graphs

“A UMAP plot” names a picture, not a procedure. The reference implementation, umap-learn 0.5.12, documents its defaults as “n_neighbors: float (optional, default 15)”, “min_dist: float (optional, default 0.1)” and “metric: string or function (optional, default 'euclidean')”. The Seurat R package reaches UMAP through a different engine. The Usage block of RunUMAP in Seurat 5.5.1 reads “umap.method = "uwot", n.neighbors = 30L, n.components = 2L, metric = "cosine", n.epochs = NULL, learning.rate = 1, min.dist = 0.3”, and the Satija lab's own documentation site gives the same defaults.

Thirty neighbours instead of fifteen. A minimum distance of 0.3 instead of 0.1. Cosine instead of euclidean. A different implementation underneath. None of that is a tuning disagreement downstream of a shared object: the same data handed to the two standard tools is turned into two different neighbour graphs before any optimisation begins. Both outputs are called UMAP in the caption. So a team refits its map with new data, or moves between tools, and expects the regions to stay where they were. It has treated a fitted, stochastic graph embedding as a coordinate system, without versioning or alignment. A permanent customer atlas is the wrong idea of what it owns.

A reusable UMAP map is a model artifact, not a timeless coordinate plane.

Analogy

Rebuilding a transit network in a smaller city

Redrawing a large transit network inside a smaller city keeps its important connections and loses its geography, so stations linked by strong routes should remain easy to reach, even if compass direction and absolute distance change.

How much geography has to go is not a matter of taste, and it is not UMAP's fault. Chari and Pachter work it out from the Johnson–Lindenstrauss lemma in 2023: “The Johnson–Lindenstrauss lemma on the optimality of linear embedding [45–47] shows that preservation of pairwise distances with a margin of error of at most 20% for a modestly sized dataset of 10,000 cells would require at least 1,842 dimensions [48].” Their reference [48] is the elementary bound proved by Dasgupta and Gupta, whose Theorem 2.1 gives k ≥ 4(ε²/2 − ε³/3)⁻¹ ln n. Evaluated at the same n = 10,000 and ε = 0.2, it asks for 2,126 dimensions. A UMAP plot has two. Chari and Pachter add that for n points embedded in two dimensions the distortion of the max/min distance ratio grows as O(n), and they measure 4- to 200-fold increases empirically.

So the compression is forced by the dimension budget, not chosen by the algorithm. What UMAP still owns is the network. It has to estimate that from noisy feature-space neighbors before it optimizes a stochastic layout, and missing or false edges can matter more than the drawing algorithm.

Graph quality precedes layout quality.

Visual

How UMAP turns neighborhoods into coordinates

UMAP builds a weighted graph in the original space, then looks for a low-dimensional graph with similar fuzzy connectivity. A metric and a neighbor count identify local candidate relationships. Distances become directed membership strengths adapted to each observation. Those local relations are symmetrized into one weighted fuzzy graph. Attractive and repulsive updates optimize a layout. The artifact is then validated for neighborhood retention, stability, transform quality and downstream behavior. The reference implementation ships defaults for all of it, and they are choices rather than neutral settings: n_neighbors, “the size of local neighborhood (in terms of number of neighboring sample points) used for manifold approximation”, defaults to 15, min_dist defaults to 0.1, and the documentation adds that “in general values should be in the range 2 to 100”.

The fourth step is where that description and the shipped code separate. In 2021 Damrich and Hamprecht took the sampling-based optimiser UMAP actually runs and worked out what it minimises: “We derive UMAP’s true loss function in closed form and find that it differs from the published one in a dataset size dependent way.” The paper gives the direction of the difference: “The weight of the loss function's repulsive term is drastically reduced.” The effective target, they find, encodes little beyond the shared k-nearest-neighbour graph. A different group, in Tübingen, arrived at the same conclusion from the other side in 2022: “We find that UMAP embeddings correspond to t-SNE with increased attraction; mathematical analysis shows that this is because the negative sampling optimization strategy employed by UMAP strongly lowers the effective repulsion.”

The objective in the paper and the objective the process descends are therefore not the same object, and the gap depends on the size of the dataset. A reader who reasons about a layout from the published loss is reasoning about a function the code does not minimise.

FigureProcess · 5 steps
  1. 1. Find neighbors

    A metric and neighbor count identify local candidate relationships.

  2. 2. Calibrate local scale

    Distances become directed membership strengths adapted to each observation.

  3. 3. Combine memberships

    Local relations are symmetrized into a weighted fuzzy graph.

  4. 4. Optimize a layout

    Attractive and repulsive updates seek a low-dimensional graph with similar edge structure.

  5. 5. Validate the artifact

    Neighborhood retention, stability, transform quality, and downstream behavior are tested.

The visual coordinates are consequences of a graph objective and its parameters.

Steps

Evaluate UMAP as a model rather than a plotting command

The workflow changes slightly with the intended use. State the use — exploration, downstream transformation, retrieval, clustering, or label-guided visualization. Define the source metric and document scaling, embeddings, approximate-neighbor settings, and duplicate handling. Sweep neighborhood size, min_dist, dimension, initialization, and seed within plausible ranges. Test transform quality, neighbor retention, downstream metrics, and outlier placement on unseen data. Store the fitted reducer and monitor for drift, unsupported inputs, and coordinate incompatibility. It always preserves the training boundary.

The sweep step and the versioning step run into the same wall. Fixing a seed is not by itself reproducibility. The umap-learn documentation states it under “UMAP Reproducibility”: “Unfortunately this means that the randomness in UMAP outputs for the multi-threaded case depends not only on the random seed input, but also on race conditions between threads during optimization, over which no control can be had. This means that multi-threaded UMAP results cannot be explicitly reproduced.” Setting random_state restores exact reproducibility, at the cost of turning off the multi-threading. The uwot R package documents the same trade for its own stochastic gradient descent. It is the engine behind Seurat's RunUMAP, and James Melville maintains it independently of umap-learn: “Number of threads to use during stochastic gradient descent. If set to > 1, then be aware that if batch = FALSE, results will not be reproducible, even if set.seed is called with a fixed seed before running.”

Two independently authored implementations, the same limitation. So the seed setting is a throughput decision as well as a reproducibility one. A run that has to be reproduced exactly must record the threading configuration next to the seed.

FigureProcess · 5 steps
  1. 1. State the use

    Choose exploration, downstream transformation, retrieval, clustering, or label-guided visualization.

  2. 2. Define the source metric

    Document scaling, embeddings, metric, approximate-neighbor settings, and duplicate handling.

  3. 3. Sweep structural parameters

    Vary neighborhood size, min_dist, dimension, initialization, and seed within plausible ranges.

  4. 4. Test held-out behavior

    Measure transform quality, neighbor retention, downstream metrics, and outlier placement on unseen data.

  5. 5. Version and monitor

    Store the fitted reducer and detect drift, unsupported inputs, and coordinate incompatibility.

Comparison

Three ways UMAP enters a system

A single library call can serve very different purposes, and each purpose requires different evidence. An exploratory map is a temporary layout for inspecting examples and nuisance structure. It prioritizes local interpretability, allows several parameter sweeps, and can be refit for each investigation. It should not define permanent IDs. A feature transformation is a fitted reducer supplying coordinates to a downstream model or index. It requires held-out transform evaluation, and versioned preprocessing and model state — including the seed and threading settings. It has to be monitored for out-of-support inputs, and it has to beat simpler reducers on the task. Supervised or target-guided UMAP lets labels influence which relationships the embedding preserves. It can increase class separation. It can also leak label assumptions into the visualization, so it requires target-aware validation. It should never be described as purely unsupervised discovery.

FigureComparison · 3 columns

Exploratory map

A temporary layout for inspecting examples and nuisance structure.

  • Prioritizes local interpretability
  • Allows several parameter sweeps
  • Can be refit for each investigation
  • Should not define permanent IDs

Feature transformation

A fitted reducer supplies coordinates to a downstream model or index.

  • Requires held-out transform evaluation
  • Needs versioned preprocessing and model state
  • Must monitor out-of-support inputs
  • Should beat simpler reducers on the task

Supervised or target-guided UMAP

Labels influence which relationships the embedding preserves.

  • Can increase class separation
  • Can leak label assumptions into visualization
  • Requires target-aware validation
  • Should not be described as purely unsupervised discovery

UMAP is powerful when its graph contract matches the job

UMAP can provide informative visual neighborhoods, compact nonlinear features, or an interface for inspecting high-dimensional representations. Those benefits come from explicit assumptions about local connectivity and optimization. The size of what the contract gives up has been measured twice, by different groups. Chari and Pachter compared each cell's 30 nearest neighbours in ambient space with its neighbours in the two-dimensional layout, across six single-cell datasets: “The 2D t-SNE/UMAP embeddings (e.g., “PCA-50D→UMAP” in Fig 2A) displayed large Jaccard distances with respect to the neighbors in ambient dimension, with an average consistently above 0.7 (70%).” Measured against the intermediate PCA space the average was above 0.8. The group that reproduced the analysis on the same datasets reported kNN recall at k=10 that “was below 40% for all methods”.

Most of a point's nearest neighbours are therefore not its neighbours in the picture. And on the same datasets, in the same paper, kNN accuracy stayed above 90% for UMAP and t-SNE, against below 62% for two-dimensional PCA and the Picasso elephant. Both facts belong in the caption. A responsible analysis reports the source metric, graph parameters, stochastic variability, and validation target. It never treats the default two-dimensional layout as ground truth.

The embedding is useful evidence only within a declared preservation contract.

Case

The global-structure advantage that sat in the initialisation

The claim was that UMAP “is preferable to t-SNE because it better preserves the global structure of the data”. Kobak and Linderman tested it, in Nature Biotechnology. UMAP with random initialisation, they report, “preserves global structure as poorly as t-SNE with random initialization”. Run the other way, “t-SNE with informative initialization performs as well as UMAP with informative initialization”. The difference sat in the initialisation, not in the algorithm.

Key takeaways