pip install umap-learn★Notpip install umap— that's a different package.conda install -c conda-forge umap-learnConda-forge build.import umap★Then useumap.UMAP(...).import umap.plotPlot helpers (needs extra deps).pip install umap-learn[plot]Pulls datashader, bokeh, holoviews…
reducer = umap.UMAP()★All sensible defaults.emb = reducer.fit_transform(X)★Fit + return the (n, 2) embedding.emb = umap.UMAP(random_state=42).fit_transform(X)★Reproducible layout.
n_neighbors=15★Local ↔ global balance of the graph.min_dist=0.1★How tightly points may pack together.n_components=2Output dims — 2/3 to view, more for ML.metric="euclidean"★Distance in the input space.random_state=42★Reproducible (but single-threaded — slower).
n_neighbors=15★Default; a good all-round balance.n_neighbors=2..5Very local — fine detail, may fragment.n_neighbors=50..200Big-picture global structure, less detail.# how large a neighborhood UMAP looks atUsual range 5–50; sensible default 10–15.
min_dist=0.1★Default; good for general visualization.min_dist=0.0Tight clumps — best before clustering.min_dist=0.5..0.99Even, spread-out points for a clean view.# min gap between points in the mapRange 0.0–0.99; keep it < spread.
metric="euclidean"★Default; general numeric data.metric="cosine"★Text / embeddings / word vectors.metric="correlation"Shape over magnitude (e.g. genomics).metric="manhattan", "chebyshev"Other numeric metrics.metric="hamming", "jaccard"Binary / set-valued features.metric="precomputed"Pass your own distance matrix as X.metric=my_numba_fnCustom — a@numba.njitfunction.
n_components=2★2 or 3 to visualize.n_components=10..50Scales in dim — feed downstream ML.init="spectral"Default; global-structure-aware start.init="pca"PCA start (deterministic).init="random"Random start (faster, less stable).spread=1.0Scale of the map; pairs withmin_dist.
reducer.fit(X)★Train & keep the model.reducer.fit_transform(X)★Fit + return the embedding array.pickle.dump(reducer, f)Persist the fitted model; reload to reuse.
min_dist=0.0★Let clusters pack tightly.n_components=5..10Cluster in a few dims — not the 2-D view.n_neighbors=15..30Enough context to keep clusters honest.HDBSCAN().fit(reducer.embedding_)★Cluster the reduced representation.densmap=TruePreserve local density (densMAP).
n_jobs=-1★All cores (default) — unlessrandom_stateset.low_memory=TrueDefault; trims kNN memory use.# first fit = numba JIT warmupSlow once, then fast; scales to millions.force_approximation_algorithm=TrueApprox kNN even on small data.precomputed_knn=(idx, dists, idx2)Reuse a kNN you already computed.
umap.UMAP(densmap=True, dens_lambda=2.0)densMAP — keeps relative densities.
StandardScaler().fit_transform(X)Scale features before UMAP.n_neighbors=15Then sweep 5 → 50 to taste.min_dist=0.10.1to view ·0.0to cluster.metric="cosine"For text & learned embeddings.random_state=42Reproducible (accept the speed hit).n_components=2 → 10+2 to look; higher to feed a model.
cluster sizes mean littlemythUMAP expands sparse, shrinks dense regions.gaps aren't exact distancescareGlobal layout beats t-SNE, but isn't literal.random_state ⇒ single-threadcareReproducible but noticeably slower.low n_neighbors ⇒ false shredscareAnd highmin_distcan merge real clusters.don't cluster the 2-D viewcareReduce to more dims +min_dist=0first.