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
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
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:
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…