umap-learn
它能做什么
UMAP-learn 是一个能简化复杂数据的工具,让数据更容易可视化或用于其他分析。它能帮你发现特征众多的数据中隐藏的规律。
适用场景
- ✓绘制图表,展示数据的结构。
- ✓为聚类算法准备数据。
- ✓在把数据用于机器学习模型之前,减少数据的特征数量。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/umap-learn/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把这些客户数据转换成二维可视化图,让我看看它们是如何聚类的。”
每周 5 个新技能,1 分钟读完。
工作原理
UMAP-learn 会分析数据点之间的邻近关系,并把它们重新排列到一个低维空间中,尽可能保留这些关系。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
UMAP-Learn
Overview
UMAP (Uniform Manifold Approximation and Projection) is a dimensionality reduction technique for visualization and general non-linear dimensionality reduction. Apply this skill for fast, scalable embeddings that approximate neighborhood structure, supervised learning, and clustering preprocessing.
Before interpreting an embedding, check finite coordinates, neighborhood retention, sensitivity to seeds/parameters, and domain evidence in the original space. UMAP axes, island areas, and gaps between clusters have no calibrated physical or probabilistic meaning. Keep predictive test data outside preprocessing and embedding fits.
Quick Start
Installation
Verified on 2026-10-01: umap-learn 0.5.12 is the current stable release (April 2026). Requires Python 3.9+ and depends on scikit-learn>=1.6, numba, pynndescent, numpy, and scipy. Pin to a verified release:
uv pip install umap-learn==0.5.12
Basic Usage
UMAP uses the scikit-learn estimator interface, but its geometry and supervised behavior differ from PCA and t-SNE. Core examples were exercised on small synthetic data with Python 3.13, scikit-learn 1.9.1, NumPy 2.5.3, and Numba 0.68.0. Parametric examples are source-checked illustrations, not executed TensorFlow tests. In snippets below, data is a finite samples-by-features array and labels must follow the same row order.
import umap
from sklearn.preprocessing import StandardScaler
# Scale continuous features when their units should carry equal weight
scaled_data = StandardScaler().fit_transform(data)
# Method 1: Single step (fit and transform)
embedding = umap.UMAP(random_state=42, n_jobs=1).fit_transform(scaled_data)
# Method 2: Separate steps (for reusing trained model)
reducer = umap.UMAP(random_state=42)
reducer.fit(scaled_data)
embedding = reducer.embedding_ # Access the trained embedding
Preprocessing requirement: Match preprocessing to the metric. For numeric Euclidean-style metrics, decide whether scaling is scientifically appropriate; it changes the feature weighting. Fit preprocessing on training data only for predictive work. Use StandardScaler(with_mean=False) for sparse matrices to avoid densifying them. For cosine, binary, precomputed-distance, or mixed-feature workflows, choose preprocessing that matches the metric instead of blindly standardizing every column.
Typical Workflow
import umap
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
# 1. Preprocess data
scaler = StandardScaler()
scaled_data = scaler.fit_transform(raw_data)
# 2. Create and fit UMAP
reducer = umap.UMAP(
n_neighbors=15,
min_dist=0.1,
n_components=2,
metric='euclidean',
random_state=42
)
embedding = reducer.fit_transform(scaled_data)
# 3. Visualize
plt.scatter(embedding[:, 0], embedding[:, 1], c=labels, cmap='Spectral', s=5)
plt.colorbar()
plt.title('UMAP Embedding')
plt.show()
Parameter Tuning Guide
UMAP has four primary parameters that control the embedding behavior. Understanding these is crucial for effective usage.
n_neighbors (default: 15)
Purpose: Balances local versus global structure in the embedding.
How it works: Controls the size of the local neighborhood UMAP examines when learning manifold structure.
Effects by value:
- Low values (2-5): Emphasizes fine local detail but may fragment data into disconnected components
- Medium values (15-20): Balanced view of both local structure and global relationships (recommended starting point)
- High values (50-200): Prioritizes broad topological structure at the expense of fine-grained details
Recommendation: Start with 15, keep it below the number of fitted samples, and compare several values. Larger neighborhoods do not make inter-cluster distances quantitatively reliable.
min_dist (default: 0.1)
Purpose: Controls how tightly points cluster in the low-dimensional space.
How it works: Adjusts the attraction curve and typical packing in the embedding; it is not a hard lower bound on pairwise distances. Require 0 <= min_dist <= spread.
Effects by value:
- Low values (0.0-0.1): Creates clumped embeddings useful for clustering; reveals fine topological details
- High values (0.5-0.99): Encourages looser packing; does not certify preservation of global distances
…
常见问题
我可以调整哪些主要设置?
你可以调整 'n_neighbors'(考虑多少个邻居)、'min_dist'(点与点之间可以多近)和 'n_components'(输出结果的最终维度)。
我需要对数据做预处理吗?
通常需要。在使用 UMAP 之前对数据进行“缩放”(让所有特征的权重相当)是个好习惯,尤其是当各特征的单位不同时。
生成的图的坐标轴代表什么?
UMAP 生成的图的坐标轴没有直接的物理或概率意义,它们只是用来展示所发现的结构。
详情
作者的原始描述
Applies UMAP-learn to nonlinear dimensionality reduction, 2D/3D embeddings, clustering preprocessing, supervised or semi-supervised UMAP, DensMAP, AlignedUMAP, and Parametric UMAP workflows.
热度
- GitHub 星标
- 51k
- 排名
- #3588
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …