Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 47

UMAP

Build a neighbor graph and lay it out in fewer dimensions so local neighborhoods stay intact. One example is on this page.

Intermediate12 min
UMAP MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

UMAP starts from a nearest-neighbor graph. Each point keeps a small set of nearby points, and the layout tries to preserve those local links in fewer dimensions. The example below is that first graph. A UMAP library then turns the same kind of graph into a 2D embedding.

Example

python
import numpy as np
from sklearn.neighbors import NearestNeighbors

X = np.array([[0, 0], [0.1, 0.2], [5, 5], [5.2, 4.7]], dtype=float)
idx = NearestNeighbors(n_neighbors=2).fit(X).kneighbors(return_distance=False)
print("neighbors:", idx.tolist())

Output:

text
neighbors: [[1, 3], [0, 3], [3, 1], [2, 1]]

When to use it

  • Use it to visualize large tables when t-SNE is too slow.
  • The neighbor list is the structure UMAP keeps. It is not the final 2D picture.
  • Like t-SNE, treat the layout as a view. Check a later model on the original columns.

Loading playground…