umap-learn – skill Khác cho agent AI
Áp dụng UMAP-learn cho giảm chiều phi tuyến, nhúng 2D/3D, tiền xử lý phân cụm, UMAP có giám sát hoặc bán giám sát, DensMAP, AlignedUMAP và quy trình Parametric UMAP.
Cài skill umap-learn bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/umap-learn-3e991.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /umap-learn – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/umap-learn-3e991.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $umap-learn – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/umap-learn-3e991.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /umap-learn – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/umap-learn-3e991.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /umap-learn – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
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.12Basic 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 embeddingPreprocessing 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
Recommendation: Use 0.0 for clustering applications, 0.1-0.3 for visualization, 0.5+ for loose structure.
n_components (default: 2)
Purpose: Determines the dimensionality of the embedded output space.
Key feature: Unlike t-SNE, UMAP scales well in the embedding dimension, enabling use beyond visualization.
Common uses:
- 2-3 dimensions: Visualization
- 5-10 dimensions: Clustering preprocessing (may retain more useful structure than 2D; does not guarantee density preservation)
- 10-50 dimensions: Feature engineering for downstream ML models
Recommendation: Use 2 for visualization, 5-10 for clustering, higher for ML pipelines.
metric (default: 'euclidean')
Purpose: Specifies how distance is calculated between input data points.
Supported metrics:
- Minkowski variants: euclidean, manhattan, chebyshev
- Spatial metrics: canberra, braycurtis, haversine
- Correlation metrics: cosine, correlation (good for text/document embeddings)
- Binary data metrics: hamming, jaccard, dice, russellrao, kulsinski, rogerstanimoto, sokalmichener, sokalsneath, yule
- Custom metrics: User-defined distance functions via Numba
Recommendation: Use euclidean for numeric data, cosine for text/document vectors, hamming for binary data.
Parameter Tuning Example
# For visualization with emphasis on local structure
umap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='euclidean')
# For clustering preprocessing
umap.UMAP(n_neighbors=30, min_dist=0.0, n_components=10, metric='euclidean')
# For document embeddings
umap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='cosine')
# For emphasizing broader neighborhoods
umap.UMAP(n_neighbors=100, min_dist=0.5, n_components=2, metric='euclidean')Supervised and Semi-Supervised Dimension Reduction
UMAP supports incorporating label information to guide the embedding process, encouraging class separation while retaining parts of the feature-neighborhood graph.
Supervised UMAP
Pass target labels via the y parameter when fitting:
# Supervised dimension reduction
embedding = umap.UMAP().fit_transform(data, y=labels)Interpretation: Label-guided separation is part of the objective, not independent evidence of discovered classes. Tune using training folds and evaluate on held-out samples. To obtain an unsupervised fit, omit y; target_weight=0 with categorical labels still modifies graph edges in 0.5.12.
Semi-Supervised UMAP
For target_metric="categorical", encode known classes as nonnegative integers and unlabeled points as -1. This sentinel does not extend to arbitrary regression targets:
# Create semi-supervised labels
semi_labels = labels.copy()
semi_labels[unlabeled_indices] = -1
# Fit with partial labels
embedding = umap.UMAP().fit_transform(data, y=semi_labels)When to use: When labeling is expensive or you have more data than labels available.
UMAP for Clustering
UMAP can help HDBSCAN on high-dimensional data, but reduction can create or erase clusters. Compare against clustering in the original or PCA space.
Best Practices for Clustering
Key principle: Configure UMAP differently for clustering than for visualization.
Starting candidates, to validate on the actual data:
- n_neighbors: Compare 15, 30, and larger valid values; there is no universally correct neighborhood size
- min_dist: Set to 0.0 (pack points densely within clusters for clearer boundaries)
- n_components: Try 5-10 dimensions and compare cluster stability; standard UMAP does not preserve density
Clustering Workflow
Install HDBSCAN separately for density-based clustering:
uv pip install hdbscan==0.8.44import umap
import hdbscan
from sklearn.preprocessing import StandardScaler
# 1. Preprocess data
scaled_data = StandardScaler().fit_transform(data)
# 2. Candidate UMAP settings for clustering
reducer = umap.UMAP(
n_neighbors=30,
min_dist=0.0,
n_components=10, # Evaluate stability against other dimensions
metric='euclidean',
random_state=42
)
embedding = reducer.fit_transform(scaled_data)
# 3. Apply HDBSCAN clustering
clusterer = hdbscan.HDBSCAN(
min_cluster_size=15,
min_samples=5,
metric='euclidean'
)
labels = clusterer.fit_predict(embedding)
# 4. Evaluate
from sklearn.metrics import adjusted_rand_score
# Only when independently known labels are available; ARI here includes noise as -1.
score = adjusted_rand_score(true_labels, labels)
print(f"Adjust… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- emergency-card – Tạo thẻ tóm tắt thông tin y tế để truy cập nhanh trong trường hợp khẩn cấp. Dùng khi…
- employee-suggestion-hub – Sổ ghi góp ý: người gửi hoặc cờ ẩn danh, danh mục, số phiếu bình chọn, người review…
- energy-procurement – Kiến thức chuyên môn về mua sắm điện và khí đốt, tối ưu biểu giá, quản lý phí nhu cầu…
- enterprise-vpn-attack – Ma trận tấn công thiết bị truy cập từ xa / SSL VPN bên ngoài
- entropy-box – Entropy Box, bộ biên dịch tri thức cho embodied-AI: biến yêu cầu có giới hạn thành quy…
- environment-setup-guide – Hướng dẫn lập trình viên thiết lập môi trường phát triển với công cụ, dependencies và…
- eol-resistor-calculator – Tính toán và kiểm tra mạch điện trở cuối đường (EOL, SEOL, DEOL, TEOL) cho bảng báo động…
- telephony – Cung cấp số Twilio, SMS/MMS và cuộc gọi AI outbound.