umap-learn
UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.
Author
Category
AI Skill DevelopmentInstall
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
UMAP-Learn Dimensionality Reduction Skill
Skill Overview
UMAP-Learn provides a full implementation of the UMAP (Uniform Manifold Approximation and Projection) dimensionality reduction algorithm for fast nonlinear reduction, visualization, and embedding generation of high-dimensional data. It can serve as an alternative to t-SNE for data visualization and machine learning preprocessing.
Applicable Scenarios
1. High-Dimensional Data Visualization
Reduce high-dimensional data (such as gene expression data, text vectors, image features) to 2D or 3D for visual exploration, helping to discover clustering patterns, outliers, and latent structures. Compared to t-SNE, UMAP runs faster and better preserves global structure.
2. Preprocessing for Clustering Analysis
As a preprocessing step for density-based clustering algorithms (such as HDBSCAN), it helps overcome the "curse of dimensionality" in high-dimensional space. By reducing dimensionality, the density distribution of points in low-dimensional space becomes clearer, improving clustering performance.
3. Machine Learning Feature Engineering
Reduce high-dimensional features to 10–50 dimensions as input features for downstream machine learning models, reducing computational cost and the risk of overfitting while retaining the main structural information of the data. Suitable for supervised and semi-supervised learning scenarios.
Core Features
1. Fast Nonlinear Dimensionality Reduction
An efficient manifold-learning-based dimensionality reduction algorithm that supports multiple distance metrics (Euclidean distance, cosine similarity, etc.) and allows flexible control of the embedding via parameters such as n_neighbors, min_dist, and n_components. Compatible with the scikit-learn API, supporting fit_transform and transform methods.
2. Supervised and Semi-Supervised Dimensionality Reduction
Supports using label information during dimensionality reduction (supervised UMAP) to achieve separation between classes while preserving within-class structure. Suitable for feature extraction with labeled data and semi-supervised learning scenarios; labels can be passed via the y parameter to guide the embedding.
3. Parametric UMAP Extension
Provides a Parametric UMAP variant that uses neural networks to learn encoder-decoder mapping functions, supporting efficient transformation and inverse transformation of new data. Suitable for applications that require frequent processing of new data or data reconstruction.
Frequently Asked Questions
What is the difference between UMAP and t-SNE? Which should I choose?
UMAP and t-SNE are both nonlinear dimensionality reduction algorithms, but there are several key differences: Speed — UMAP is typically much faster than t-SNE, especially on large datasets; Global structure — UMAP better preserves the global topology of the data, while t-SNE focuses more on local neighborhood relations; Scalability — UMAP supports transforming new data (transform method), whereas t-SNE usually requires re-running; Parameter control — UMAP offers more tunable parameters (n_neighbors, min_dist) to control the output.
Recommendation: choose UMAP if you need to process large datasets quickly or preserve global structure; choose t-SNE if you mainly care about local clustering detail and the dataset is small. In most cases, UMAP is the better default choice.
How should UMAP's n_neighbors and min_dist parameters be set?
n_neighbors controls the balance between local and global structure: small values (2–5) emphasize local detail but may lead to fragmentation; large values (50–200) emphasize global structure but lose detail. The default value of 15 is a balanced starting point. min_dist controls how tightly points are packed in the output space: small values (0.0–0.1) produce tight clusters, suitable for clustering analysis; large values (0.5–0.99) make points more dispersed, suitable for visual exploration.
Recommended settings for different tasks: Visualization — n_neighbors=15, min_dist=0.1; Clustering preprocessing — n_neighbors=30, min_dist=0.0, n_components=5–10; Preserving global structure — n_neighbors=100, min_dist=0.5; Document embeddings — n_neighbors=15, min_dist=0.1, metric='cosine'.
Do I need to preprocess data before using UMAP?
It is strongly recommended to standardize your data (StandardScaler or a similar method) before using UMAP. Because UMAP uses distance metrics to compute similarity, if feature scales vary widely, large-scale features will dominate the distance calculation and distort the embedding. Standardization ensures all features contribute equally to the distance computation.
Additionally, note: ensure there are no missing values or outliers in the data; for categorical variables, consider appropriate encoding; for text data, typically vectorize first (e.g., TF-IDF or embedding models); when using supervised UMAP, ensure labels are encoded correctly (-1 indicates unlabeled samples). Proper preprocessing is key to obtaining good dimensionality reduction results.