[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6AFQGEA3HRVKV132D2EAMDF":3,"skill-same:01M6AFQGEA3HRVKV132D2EAMDF":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":50,"repositoryHtmlUrl":51,"repositoryHomepageUrl":52,"ownerHtmlUrl":53,"ownerBlogUrl":54,"ownerDescription":55,"updatedAt":56,"install":57,"resources":70},"01M6AFQGEA3HRVKV132D2EAMDF","umap-learn",null,"UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D\u002F3D visualization, clustering preprocessing (HDBSCAN), supervised\u002Fparametric UMAP, for high-dimensional data.","davila7\u002Fclaude-code-templates","davila7","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6216945?v=4","01M6ADEWWFPS191NFM0Y1EX1JH","Daniel Avila","01M6ADJHGM78PHQRD3XZTFDVKK",33481,"MIT","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000013","分析与可视化","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"learn","umap","umap learn","data","clustering","fast","3D","learning","preprocessing","visualization","dimensionality reduction","manifold","high","for","2d","supervised","parametric","Nonlinear","2026-11-10 10:12:30",false,"---\nname: umap-learn\ndescription: \"UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D\u002F3D visualization, clustering preprocessing (HDBSCAN), supervised\u002Fparametric UMAP, for high-dimensional data.\"\n---\n\n# UMAP-Learn\n\n## Overview\n\nUMAP (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 preserve local and global structure, supervised learning, and clustering preprocessing.\n\n## Quick Start\n\n### Installation\n\n```bash\nuv pip install umap-learn\n```\n\n### Basic Usage\n\nUMAP follows scikit-learn conventions and can be used as a drop-in replacement for t-SNE or PCA.\n\n```python\nimport umap\nfrom sklearn.preprocessing import StandardScaler\n\n# Prepare data (standardization is essential)\nscaled_data = StandardScaler().fit_transform(data)\n\n# Method 1: Single step (fit and transform)\nembedding = umap.UMAP().fit_transform(scaled_data)\n\n# Method 2: Separate steps (for reusing trained model)\nreducer = umap.UMAP(random_state=42)\nreducer.fit(scaled_data)\nembedding = reducer.embedding_  # Access the trained embedding\n```\n\n**Critical preprocessing requirement:** Always standardize features to comparable scales before applying UMAP to ensure equal weighting across dimensions.\n\n### Typical Workflow\n\n```python\nimport umap\nimport matplotlib.pyplot as plt\nfrom sklearn.preprocessing import StandardScaler\n\n# 1. Preprocess data\nscaler = StandardScaler()\nscaled_data = scaler.fit_transform(raw_data)\n\n# 2. Create and fit UMAP\nreducer = umap.UMAP(\n    n_neighbors=15,\n    min_dist=0.1,\n    n_components=2,\n    metric='euclidean',\n    random_state=42\n)\nembedding = reducer.fit_transform(scaled_data)\n\n# 3. Visualize\nplt.scatter(embedding[:, 0], embedding[:, 1], c=labels, cmap='Spectral', s=5)\nplt.colorbar()\nplt.title('UMAP Embedding')\nplt.show()\n```\n\n## Parameter Tuning Guide\n\nUMAP has four primary parameters that control the embedding behavior. Understanding these is crucial for effective usage.\n\n### n_neighbors (default: 15)\n\n**Purpose:** Balances local versus global structure in the embedding.\n\n**How it works:** Controls the size of the local neighborhood UMAP examines when learning manifold structure.\n\n**Effects by value:**\n- **Low values (2-5):** Emphasizes fine local detail but may fragment data into disconnected components\n- **Medium values (15-20):** Balanced view of both local structure and global relationships (recommended starting point)\n- **High values (50-200):** Prioritizes broad topological structure at the expense of fine-grained details\n\n**Recommendation:** Start with 15 and adjust based on results. Increase for more global structure, decrease for more local detail.\n\n### min_dist (default: 0.1)\n\n**Purpose:** Controls how tightly points cluster in the low-dimensional space.\n\n**How it works:** Sets the minimum distance apart that points are allowed to be in the output representation.\n\n**Effects by value:**\n- **Low values (0.0-0.1):** Creates clumped embeddings useful for clustering; reveals fine topological details\n- **High values (0.5-0.99):** Prevents tight packing; emphasizes broad topological preservation over local structure\n\n**Recommendation:** Use 0.0 for clustering applications, 0.1-0.3 for visualization, 0.5+ for loose structure.\n\n### n_components (default: 2)\n\n**Purpose:** Determines the dimensionality of the embedded output space.\n\n**Key feature:** Unlike t-SNE, UMAP scales well in the embedding dimension, enabling use beyond visualization.\n\n**Common uses:**\n- **2-3 dimensions:** Visualization\n- **5-10 dimensions:** Clustering preprocessing (better preserves density than 2D)\n- **10-50 dimensions:** Feature engineering for downstream ML models\n\n**Recommendation:** Use 2 for visualization, 5-10 for clustering, higher for ML pipelines.\n\n### metric (default: 'euclidean')\n\n**Purpose:** Specifies how distance is calculated between input data points.\n\n**Supported metrics:**\n- **Minkowski variants:** euclidean, manhattan, chebyshev\n- **Spatial metrics:** canberra, braycurtis, haversine\n- **Correlation metrics:** cosine, correlation (good for text\u002Fdocument embeddings)\n- **Binary data metrics:** hamming, jaccard, dice, russellrao, kulsinski, rogerstanimoto, sokalmichener, sokalsneath, yule\n- **Custom metrics:** User-defined distance functions via Numba\n\n**Recommendation:** Use euclidean for numeric data, cosine for text\u002Fdocument vectors, hamming for binary data.\n\n### Parameter Tuning Example\n\n```python\n# For visualization with emphasis on local structure\numap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='euclidean')\n\n# For clustering preprocessing\numap.UMAP(n_neighbors=30, min_dist=0.0, n_components=10, metric='euclidean')\n\n# For document embeddings\numap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='cosine')\n\n# For preserving global structure\numap.UMAP(n_neighbors=100, min_dist=0.5, n_components=2, metric='euclidean')\n```\n\n## Supervised and Semi-Supervised Dimension Reduction\n\nUMAP supports incorporating label information to guide the embedding process, enabling class separation while preserving internal structure.\n\n### Supervised UMAP\n\nPass target labels via the `y` parameter when fitting:\n\n```python\n# Supervised dimension reduction\nembedding = umap.UMAP().fit_transform(data, y=labels)\n```\n\n**Key benefits:**\n- Achieves cleanly separated classes\n- Preserves internal structure within each class\n- Maintains global relationships between classes\n\n**When to use:** When you have labeled data and want to separate known classes while keeping meaningful point embeddings.\n\n### Semi-Supervised UMAP\n\nFor partial labels, mark unlabeled points with `-1` following scikit-learn convention:\n\n```python\n# Create semi-supervised labels\nsemi_labels = labels.copy()\nsemi_labels[unlabeled_indices] = -1\n\n# Fit with partial labels\nembedding = umap.UMAP().fit_transform(data, y=semi_labels)\n```\n\n**When to use:** When labeling is expensive or you have more data than labels available.\n\n### Metric Learning with UMAP\n\nTrain a supervised embedding on labeled data, then apply to new unlabeled data:\n\n```python\n# Train on labeled data\nmapper = umap.UMAP().fit(train_data, train_labels)\n\n# Transform unlabeled test data\ntest_embedding = mapper.transform(test_data)\n\n# Use as feature engineering for downstream classifier\nfrom sklearn.svm import SVC\nclf = SVC().fit(mapper.embedding_, train_labels)\npredictions = clf.predict(test_embedding)\n```\n\n**When to use:** For supervised feature engineering in machine learning pipelines.\n\n## UMAP for Clustering\n\nUMAP serves as effective preprocessing for density-based clustering algorithms like HDBSCAN, overcoming the curse of dimensionality.\n\n### Best Practices for Clustering\n\n**Key principle:** Configure UMAP differently for clustering than for visualization.\n\n**Recommended parameters:**\n- **n_neighbors:** Increase to ~30 (default 15 is too local and can create artificial fine-grained clusters)\n- **min_dist:** Set to 0.0 (pack points densely within clusters for clearer boundaries)\n- **n_components:** Use 5-10 dimensions (maintains performance while improving density preservation vs. 2D)\n\n### Clustering Workflow\n\n```python\nimport umap\nimport hdbscan\nfrom sklearn.preprocessing import StandardScaler\n\n# 1. Preprocess data\nscaled_data = StandardScaler().fit_transform(data)\n\n# 2. UMAP with clustering-optimized parameters\nreducer = umap.UMAP(\n    n_neighbors=30,\n    min_dist=0.0,\n    n_components=10,  # Higher than 2 for better density preservation\n    metric='euclidean',\n    random_state=42\n)\nembedding = reducer.fit_transform(scaled_data)\n\n# 3. Apply HDBSCAN clustering\nclusterer = hdbscan.HDBSCAN(\n    min_cluster_size=15,\n    min_samples=5,\n    metric='euclidean'\n)\nlabels = clusterer.fit_predict(embedding)\n\n# 4. Evaluate\nfrom sklearn.metrics import adjusted_rand_score\nscore = adjusted_rand_score(true_labels, labels)\nprint(f\"Adjusted Rand Score: {score:.3f}\")\nprint(f\"Number of clusters: {len(set(labels)) - (1 if -1 in labels else 0)}\")\nprint(f\"Noise points: {sum(labels == -1)}\")\n```\n\n### Visualization After Clustering\n\n```python\n# Create 2D embedding for visualization (separate from clustering)\nvis_reducer = umap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, random_state=42)\nvis_embedding = vis_reducer.fit_transform(scaled_data)\n\n# Plot with cluster labels\nimport matplotlib.pyplot as plt\nplt.scatter(vis_embedding[:, 0], vis_embedding[:, 1], c=labels, cmap='Spectral', s=5)\nplt.colorbar()\nplt.title('UMAP Visualization with HDBSCAN Clusters')\nplt.show()\n```\n\n**Important caveat:** UMAP does not completely preserve density and can create artificial cluster divisions. Always validate and explore resulting clusters.\n\n## Transforming New Data\n\nUMAP enables preprocessing of new data through its `transform()` method, allowing trained models to project unseen data into the learned embedding space.\n\n### Basic Transform Usage\n\n```python\n# Train on training data\ntrans = umap.UMAP(n_neighbors=15, random_state=42).fit(X_train)\n\n# Transform test data\ntest_embedding = trans.transform(X_test)\n```\n\n### Integration with Machine Learning Pipelines\n\n```python\nfrom sklearn.svm import SVC\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nimport umap\n\n# Split data\nX_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2)\n\n# Preprocess\nscaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X_train)\nX_test_scaled = scaler.transform(X_test)\n\n# Train UMAP\nreducer = umap.UMAP(n_components=10, random_state=42)\nX_train_embedded = reducer.fit_transform(X_train_scaled)\nX_test_embedded = reducer.transform(X_test_scaled)\n\n# Train classifier on embeddings\nclf = SVC()\nclf.fit(X_train_embedded, y_train)\naccuracy = clf.score(X_test_embedded, y_test)\nprint(f\"Test accuracy: {accuracy:.3f}\")\n```\n\n### Important Considerations\n\n**Data consistency:** The transform method assumes the overall distribution in the higher-dimensional space is consistent between training and test data. When this assumption fails, consider using Parametric UMAP instead.\n\n**Performance:** Transform operations are efficient (typically \u003C1 second), though initial calls may be slower due to Numba JIT compilation.\n\n**Scikit-learn compatibility:** UMAP follows standard sklearn conventions and works seamlessly in pipelines:\n\n```python\nfrom sklearn.pipeline import Pipeline\n\npipeline = Pipeline([\n    ('scaler', StandardScaler()),\n    ('umap', umap.UMAP(n_components=10)),\n    ('classifier', SVC())\n])\n\npipeline.fit(X_train, y_train)\npredictions = pipeline.predict(X_test)\n```\n\n## Advanced Features\n\n### Parametric UMAP\n\nParametric UMAP replaces direct embedding optimization with a learned neural network mapping function.\n\n**Key differences from standard UMAP:**\n- Uses TensorFlow\u002FKeras to train encoder networks\n- Enables efficient transformation of new data\n- Supports reconstruction via decoder networks (inverse transform)\n- Allows custom architectures (CNNs for images, RNNs for sequences)\n\n**Installation:**\n```bash\nuv pip install umap-learn[parametric_umap]\n# Requires TensorFlow 2.x\n```\n\n**Basic usage:**\n```python\nfrom umap.parametric_umap import ParametricUMAP\n\n# Default architecture (3-layer 100-neuron fully-connected network)\nembedder = ParametricUMAP()\nembedding = embedder.fit_transform(data)\n\n# Transform new data efficiently\nnew_embedding = embedder.transform(new_data)\n```\n\n**Custom architecture:**\n```python\nimport tensorflow as tf\n\n# Define custom encoder\nencoder = tf.keras.Sequential([\n    tf.keras.layers.InputLayer(input_shape=(input_dim,)),\n    tf.keras.layers.Dense(128, activation='relu'),\n    tf.keras.layers.Dense(64, activation='relu'),\n    tf.keras.layers.Dense(2)  # Output dimension\n])\n\nembedder = ParametricUMAP(encoder=encoder, dims=(input_dim,))\nembedding = embedder.fit_transform(data)\n```\n\n**When to use Parametric UMAP:**\n- Need efficient transformation of new data after training\n- Require reconstruction capabilities (inverse transforms)\n- Want to combine UMAP with autoencoders\n- Working with complex data types (images, sequences) benefiting from specialized architectures\n\n**When to use standard UMAP:**\n- Need simplicity and quick prototyping\n- Dataset is small and computational efficiency isn't critical\n- Don't require learned transformations for future data\n\n### Inverse Transforms\n\nInverse transforms enable reconstruction of high-dimensional data from low-dimensional embeddings.\n\n**Basic usage:**\n```python\nreducer = umap.UMAP()\nembedding = reducer.fit_transform(data)\n\n# Reconstruct high-dimensional data from embedding coordinates\nreconstructed = reducer.inverse_transform(embedding)\n```\n\n**Important limitations:**\n- Computationally expensive operation\n- Works poorly outside the convex hull of the embedding\n- Accuracy decreases in regions with gaps between clusters\n\n**Use cases:**\n- Understanding structure of embedded data\n- Visualizing smooth transitions between clusters\n- Exploring interpolations between data points\n- Generating synthetic samples in embedding space\n\n**Example: Exploring embedding space:**\n```python\nimport numpy as np\n\n# Create grid of points in embedding space\nx = np.linspace(embedding[:, 0].min(), embedding[:, 0].max(), 10)\ny = np.linspace(embedding[:, 1].min(), embedding[:, 1].max(), 10)\nxx, yy = np.meshgrid(x, y)\ngrid_points = np.c_[xx.ravel(), yy.ravel()]\n\n# Reconstruct samples from grid\nreconstructed_samples = reducer.inverse_transform(grid_points)\n```\n\n### AlignedUMAP\n\nFor analyzing temporal or related datasets (e.g., time-series experiments, batch data):\n\n```python\nfrom umap import AlignedUMAP\n\n# List of related datasets\ndatasets = [day1_data, day2_data, day3_data]\n\n# Create aligned embeddings\nmapper = AlignedUMAP().fit(datasets)\naligned_embeddings = mapper.embeddings_  # List of embeddings\n```\n\n**When to use:** Comparing embeddings across related datasets while maintaining consistent coordinate systems.\n\n## Reproducibility\n\nTo ensure reproducible results, always set the `random_state` parameter:\n\n```python\nreducer = umap.UMAP(random_state=42)\n```\n\nUMAP uses stochastic optimization, so results will vary slightly between runs without a fixed random state.\n\n## Common Issues and Solutions\n\n**Issue:** Disconnected components or fragmented clusters\n- **Solution:** Increase `n_neighbors` to emphasize more global structure\n\n**Issue:** Clusters too spread out or not well separated\n- **Solution:** Decrease `min_dist` to allow tighter packing\n\n**Issue:** Poor clustering results\n- **Solution:** Use clustering-specific parameters (n_neighbors=30, min_dist=0.0, n_components=5-10)\n\n**Issue:** Transform results differ significantly from training\n- **Solution:** Ensure test data distribution matches training, or use Parametric UMAP\n\n**Issue:** Slow performance on large datasets\n- **Solution:** Set `low_memory=True` (default), or consider dimensionality reduction with PCA first\n\n**Issue:** All points collapsed to single cluster\n- **Solution:** Check data preprocessing (ensure proper scaling), increase `min_dist`\n\n## Resources\n\n### references\u002F\n\nContains detailed API documentation:\n- `api_reference.md`: Complete UMAP class parameters and methods\n\nLoad these references when detailed parameter information or advanced method usage is needed.\n","# UMAP-Learn\n\n## Overview\n\nUMAP (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 preserve local and global structure, supervised learning, and clustering preprocessing.\n\n## Quick Start\n\n### Installation\n\n```bash\nuv pip install umap-learn\n```\n\n### Basic Usage\n\nUMAP follows scikit-learn conventions and can be used as a drop-in replacement for t-SNE or PCA.\n\n```python\nimport umap\nfrom sklearn.preprocessing import StandardScaler\n\n# Prepare data (standardization is essential)\nscaled_data = StandardScaler().fit_transform(data)\n\n# Method 1: Single step (fit and transform)\nembedding = umap.UMAP().fit_transform(scaled_data)\n\n# Method 2: Separate steps (for reusing trained model)\nreducer = umap.UMAP(random_state=42)\nreducer.fit(scaled_data)\nembedding = reducer.embedding_  # Access the trained embedding\n```\n\n**Critical preprocessing requirement:** Always standardize features to comparable scales before applying UMAP to ensure equal weighting across dimensions.\n\n### Typical Workflow\n\n```python\nimport umap\nimport matplotlib.pyplot as plt\nfrom sklearn.preprocessing import StandardScaler\n\n# 1. Preprocess data\nscaler = StandardScaler()\nscaled_data = scaler.fit_transform(raw_data)\n\n# 2. Create and fit UMAP\nreducer = umap.UMAP(\n    n_neighbors=15,\n    min_dist=0.1,\n    n_components=2,\n    metric='euclidean',\n    random_state=42\n)\nembedding = reducer.fit_transform(scaled_data)\n\n# 3. Visualize\nplt.scatter(embedding[:, 0], embedding[:, 1], c=labels, cmap='Spectral', s=5)\nplt.colorbar()\nplt.title('UMAP Embedding')\nplt.show()\n```\n\n## Parameter Tuning Guide\n\nUMAP has four primary parameters that control the embedding behavior. Understanding these is crucial for effective usage.\n\n### n_neighbors (default: 15)\n\n**Purpose:** Balances local versus global structure in the embedding.\n\n**How it works:** Controls the size of the local neighborhood UMAP examines when learning manifold structure.\n\n**Effects by value:**\n- **Low values (2-5):** Emphasizes fine local detail but may fragment data into disconnected components\n- **Medium values (15-20):** Balanced view of both local structure and global relationships (recommended starting point)\n- **High values (50-200):** Prioritizes broad topological structure at the expense of fine-grained details\n\n**Recommendation:** Start with 15 and adjust based on results. Increase for more global structure, decrease for more local detail.\n\n### min_dist (default: 0.1)\n\n**Purpose:** Controls how tightly points cluster in the low-dimensional space.\n\n**How it works:** Sets the minimum distance apart that points are allowed to be in the output representation.\n\n**Effects by value:**\n- **Low values (0.0-0.1):** Creates clumped embeddings useful for clustering; reveals fine topological details\n- **High values (0.5-0.99):** Prevents tight packing; emphasizes broad topological preservation over local structure\n\n**Recommendation:** Use 0.0 for clustering applications, 0.1-0.3 for visualization, 0.5+ for loose structure.\n\n### n_components (default: 2)\n\n**Purpose:** Determines the dimensionality of the embedded output space.\n\n**Key feature:** Unlike t-SNE, UMAP scales well in the embedding dimension, enabling use beyond visualization.\n\n**Common uses:**\n- **2-3 dimensions:** Visualization\n- **5-10 dimensions:** Clustering preprocessing (better preserves density than 2D)\n- **10-50 dimensions:** Feature engineering for downstream ML models\n\n**Recommendation:** Use 2 for visualization, 5-10 for clustering, higher for ML pipelines.\n\n### metric (default: 'euclidean')\n\n**Purpose:** Specifies how distance is calculated between input data points.\n\n**Supported metrics:**\n- **Minkowski variants:** euclidean, manhattan, chebyshev\n- **Spatial metrics:** canberra, braycurtis, haversine\n- **Correlation metrics:** cosine, correlation (good for text\u002Fdocument embeddings)\n- **Binary data metrics:** hamming, jaccard, dice, russellrao, kulsinski, rogerstanimoto, sokalmichener, sokalsneath, yule\n- **Custom metrics:** User-defined distance functions via Numba\n\n**Recommendation:** Use euclidean for numeric data, cosine for text\u002Fdocument vectors, hamming for binary data.\n\n### Parameter Tuning Example\n\n```python\n# For visualization with emphasis on local structure\numap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='euclidean')\n\n# For clustering preprocessing\numap.UMAP(n_neighbors=30, min_dist=0.0, n_components=10, metric='euclidean')\n\n# For document embeddings\numap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, metric='cosine')\n\n# For preserving global structure\numap.UMAP(n_neighbors=100, min_dist=0.5, n_components=2, metric='euclidean')\n```\n\n## Supervised and Semi-Supervised Dimension Reduction\n\nUMAP supports incorporating label information to guide the embedding process, enabling class separation while preserving internal structure.\n\n### Supervised UMAP\n\nPass target labels via the `y` parameter when fitting:\n\n```python\n# Supervised dimension reduction\nembedding = umap.UMAP().fit_transform(data, y=labels)\n```\n\n**Key benefits:**\n- Achieves cleanly separated classes\n- Preserves internal structure within each class\n- Maintains global relationships between classes\n\n**When to use:** When you have labeled data and want to separate known classes while keeping meaningful point embeddings.\n\n### Semi-Supervised UMAP\n\nFor partial labels, mark unlabeled points with `-1` following scikit-learn convention:\n\n```python\n# Create semi-supervised labels\nsemi_labels = labels.copy()\nsemi_labels[unlabeled_indices] = -1\n\n# Fit with partial labels\nembedding = umap.UMAP().fit_transform(data, y=semi_labels)\n```\n\n**When to use:** When labeling is expensive or you have more data than labels available.\n\n### Metric Learning with UMAP\n\nTrain a supervised embedding on labeled data, then apply to new unlabeled data:\n\n```python\n# Train on labeled data\nmapper = umap.UMAP().fit(train_data, train_labels)\n\n# Transform unlabeled test data\ntest_embedding = mapper.transform(test_data)\n\n# Use as feature engineering for downstream classifier\nfrom sklearn.svm import SVC\nclf = SVC().fit(mapper.embedding_, train_labels)\npredictions = clf.predict(test_embedding)\n```\n\n**When to use:** For supervised feature engineering in machine learning pipelines.\n\n## UMAP for Clustering\n\nUMAP serves as effective preprocessing for density-based clustering algorithms like HDBSCAN, overcoming the curse of dimensionality.\n\n### Best Practices for Clustering\n\n**Key principle:** Configure UMAP differently for clustering than for visualization.\n\n**Recommended parameters:**\n- **n_neighbors:** Increase to ~30 (default 15 is too local and can create artificial fine-grained clusters)\n- **min_dist:** Set to 0.0 (pack points densely within clusters for clearer boundaries)\n- **n_components:** Use 5-10 dimensions (maintains performance while improving density preservation vs. 2D)\n\n### Clustering Workflow\n\n```python\nimport umap\nimport hdbscan\nfrom sklearn.preprocessing import StandardScaler\n\n# 1. Preprocess data\nscaled_data = StandardScaler().fit_transform(data)\n\n# 2. UMAP with clustering-optimized parameters\nreducer = umap.UMAP(\n    n_neighbors=30,\n    min_dist=0.0,\n    n_components=10,  # Higher than 2 for better density preservation\n    metric='euclidean',\n    random_state=42\n)\nembedding = reducer.fit_transform(scaled_data)\n\n# 3. Apply HDBSCAN clustering\nclusterer = hdbscan.HDBSCAN(\n    min_cluster_size=15,\n    min_samples=5,\n    metric='euclidean'\n)\nlabels = clusterer.fit_predict(embedding)\n\n# 4. Evaluate\nfrom sklearn.metrics import adjusted_rand_score\nscore = adjusted_rand_score(true_labels, labels)\nprint(f\"Adjusted Rand Score: {score:.3f}\")\nprint(f\"Number of clusters: {len(set(labels)) - (1 if -1 in labels else 0)}\")\nprint(f\"Noise points: {sum(labels == -1)}\")\n```\n\n### Visualization After Clustering\n\n```python\n# Create 2D embedding for visualization (separate from clustering)\nvis_reducer = umap.UMAP(n_neighbors=15, min_dist=0.1, n_components=2, random_state=42)\nvis_embedding = vis_reducer.fit_transform(scaled_data)\n\n# Plot with cluster labels\nimport matplotlib.pyplot as plt\nplt.scatter(vis_embedding[:, 0], vis_embedding[:, 1], c=labels, cmap='Spectral', s=5)\nplt.colorbar()\nplt.title('UMAP Visualization with HDBSCAN Clusters')\nplt.show()\n```\n\n**Important caveat:** UMAP does not completely preserve density and can create artificial cluster divisions. Always validate and explore resulting clusters.\n\n## Transforming New Data\n\nUMAP enables preprocessing of new data through its `transform()` method, allowing trained models to project unseen data into the learned embedding space.\n\n### Basic Transform Usage\n\n```python\n# Train on training data\ntrans = umap.UMAP(n_neighbors=15, random_state=42).fit(X_train)\n\n# Transform test data\ntest_embedding = trans.transform(X_test)\n```\n\n### Integration with Machine Learning Pipelines\n\n```python\nfrom sklearn.svm import SVC\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nimport umap\n\n# Split data\nX_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2)\n\n# Preprocess\nscaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X_train)\nX_test_scaled = scaler.transform(X_test)\n\n# Train UMAP\nreducer = umap.UMAP(n_components=10, random_state=42)\nX_train_embedded = reducer.fit_transform(X_train_scaled)\nX_test_embedded = reducer.transform(X_test_scaled)\n\n# Train classifier on embeddings\nclf = SVC()\nclf.fit(X_train_embedded, y_train)\naccuracy = clf.score(X_test_embedded, y_test)\nprint(f\"Test accuracy: {accuracy:.3f}\")\n```\n\n### Important Considerations\n\n**Data consistency:** The transform method assumes the overall distribution in the higher-dimensional space is consistent between training and test data. When this assumption fails, consider using Parametric UMAP instead.\n\n**Performance:** Transform operations are efficient (typically \u003C1 second), though initial calls may be slower due to Numba JIT compilation.\n\n**Scikit-learn compatibility:** UMAP follows standard sklearn conventions and works seamlessly in pipelines:\n\n```python\nfrom sklearn.pipeline import Pipeline\n\npipeline = Pipeline([\n    ('scaler', StandardScaler()),\n    ('umap', umap.UMAP(n_components=10)),\n    ('classifier', SVC())\n])\n\npipeline.fit(X_train, y_train)\npredictions = pipeline.predict(X_test)\n```\n\n## Advanced Features\n\n### Parametric UMAP\n\nParametric UMAP replaces direct embedding optimization with a learned neural network mapping function.\n\n**Key differences from standard UMAP:**\n- Uses TensorFlow\u002FKeras to train encoder networks\n- Enables efficient transformation of new data\n- Supports reconstruction via decoder networks (inverse transform)\n- Allows custom architectures (CNNs for images, RNNs for sequences)\n\n**Installation:**\n```bash\nuv pip install umap-learn[parametric_umap]\n# Requires TensorFlow 2.x\n```\n\n**Basic usage:**\n```python\nfrom umap.parametric_umap import ParametricUMAP\n\n# Default architecture (3-layer 100-neuron fully-connected network)\nembedder = ParametricUMAP()\nembedding = embedder.fit_transform(data)\n\n# Transform new data efficiently\nnew_embedding = embedder.transform(new_data)\n```\n\n**Custom architecture:**\n```python\nimport tensorflow as tf\n\n# Define custom encoder\nencoder = tf.keras.Sequential([\n    tf.keras.layers.InputLayer(input_shape=(input_dim,)),\n    tf.keras.layers.Dense(128, activation='relu'),\n    tf.keras.layers.Dense(64, activation='relu'),\n    tf.keras.layers.Dense(2)  # Output dimension\n])\n\nembedder = ParametricUMAP(encoder=encoder, dims=(input_dim,))\nembedding = embedder.fit_transform(data)\n```\n\n**When to use Parametric UMAP:**\n- Need efficient transformation of new data after training\n- Require reconstruction capabilities (inverse transforms)\n- Want to combine UMAP with autoencoders\n- Working with complex data types (images, sequences) benefiting from specialized architectures\n\n**When to use standard UMAP:**\n- Need simplicity and quick prototyping\n- Dataset is small and computational efficiency isn't critical\n- Don't require learned transformations for future data\n\n### Inverse Transforms\n\nInverse transforms enable reconstruction of high-dimensional data from low-dimensional embeddings.\n\n**Basic usage:**\n```python\nreducer = umap.UMAP()\nembedding = reducer.fit_transform(data)\n\n# Reconstruct high-dimensional data from embedding coordinates\nreconstructed = reducer.inverse_transform(embedding)\n```\n\n**Important limitations:**\n- Computationally expensive operation\n- Works poorly outside the convex hull of the embedding\n- Accuracy decreases in regions with gaps between clusters\n\n**Use cases:**\n- Understanding structure of embedded data\n- Visualizing smooth transitions between clusters\n- Exploring interpolations between data points\n- Generating synthetic samples in embedding space\n\n**Example: Exploring embedding space:**\n```python\nimport numpy as np\n\n# Create grid of points in embedding space\nx = np.linspace(embedding[:, 0].min(), embedding[:, 0].max(), 10)\ny = np.linspace(embedding[:, 1].min(), embedding[:, 1].max(), 10)\nxx, yy = np.meshgrid(x, y)\ngrid_points = np.c_[xx.ravel(), yy.ravel()]\n\n# Reconstruct samples from grid\nreconstructed_samples = reducer.inverse_transform(grid_points)\n```\n\n### AlignedUMAP\n\nFor analyzing temporal or related datasets (e.g., time-series experiments, batch data):\n\n```python\nfrom umap import AlignedUMAP\n\n# List of related datasets\ndatasets = [day1_data, day2_data, day3_data]\n\n# Create aligned embeddings\nmapper = AlignedUMAP().fit(datasets)\naligned_embeddings = mapper.embeddings_  # List of embeddings\n```\n\n**When to use:** Comparing embeddings across related datasets while maintaining consistent coordinate systems.\n\n## Reproducibility\n\nTo ensure reproducible results, always set the `random_state` parameter:\n\n```python\nreducer = umap.UMAP(random_state=42)\n```\n\nUMAP uses stochastic optimization, so results will vary slightly between runs without a fixed random state.\n\n## Common Issues and Solutions\n\n**Issue:** Disconnected components or fragmented clusters\n- **Solution:** Increase `n_neighbors` to emphasize more global structure\n\n**Issue:** Clusters too spread out or not well separated\n- **Solution:** Decrease `min_dist` to allow tighter packing\n\n**Issue:** Poor clustering results\n- **Solution:** Use clustering-specific parameters (n_neighbors=30, min_dist=0.0, n_components=5-10)\n\n**Issue:** Transform results differ significantly from training\n- **Solution:** Ensure test data distribution matches training, or use Parametric UMAP\n\n**Issue:** Slow performance on large datasets\n- **Solution:** Set `low_memory=True` (default), or consider dimensionality reduction with PCA first\n\n**Issue:** All points collapsed to single cluster\n- **Solution:** Check data preprocessing (ensure proper scaling), increase `min_dist`\n\n## Resources\n\n### references\u002F\n\nContains detailed API documentation:\n- `api_reference.md`: Complete UMAP class parameters and methods\n\nLoad these references when detailed parameter information or advanced method usage is needed.\n",{"name":5,"description":7},"main","2b749c82b5d11fac39d9a6e021ce3f5b8a541bd1","cli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn",3931,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates","https:\u002F\u002Faitmpl.com","https:\u002F\u002Fgithub.com\u002Fdavila7","https:\u002F\u002Fdanielavila.me","Building AI dev tools with LLMs","2026-11-14 06:14:46",{"source":8,"skillName":5,"commands":58,"prompt":68,"zipAvailable":69},[59,62,65],{"tool":60,"command":61},"npx","npx skills add davila7\u002Fclaude-code-templates --skill umap-learn",{"tool":63,"command":64},"bunx","bunx skills add davila7\u002Fclaude-code-templates --skill umap-learn",{"tool":66,"command":67},"pnpm","pnpm dlx skills add davila7\u002Fclaude-code-templates --skill umap-learn","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002FSKILL.md",true,[71],{"path":72,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fapi_reference.md","REFERENCE","参考文档",18966,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002Freferences\u002Fapi_reference.md",[78,107,134,167,202,226],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":87,"publishedAt":42},"01M70NHBTQ8BV0A2SCAZXEPHCX","wealthville-pool-scoring","Score DeFi liquidity pools before providing liquidity. Returns a 0-100 pool score and an Enter\u002FHold\u002FExit\u002FReduce\u002FAvoid verdict with calibrated confidence for ~68,800 Solana pools and 575 EVM pools, plus a public miss-inclusive track record. Use when asked whether a pool is worth LPing into, which pools look best right now, or how accurate the scores have actually been.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fweb-data\u002Fwealthville-pool-scoring\u002FSKILL.md",[84],{"categoryNo":85,"categoryName":86,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[88,89,90,91,92,37,93,94,95,96,97,98,99,100,101,102,103,104,105,106],"scoring","pool","wealthville pool scoring","liquidity","which","exit","now","use","when","reduce","with","record","track","verdict","evm","solana","how","public","look",{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":114,"publishedAt":42},"01M70MB6VR8ERJ4EM8D5KHBMEV","technical-debt-auditor","Scans a codebase and produces a quantified technical debt report with a prioritized remediation plan. Analyzes dead code, TODO\u002FFIXME\u002FHACK markers, dependency staleness, complexity hotspots, code duplication signals, test coverage gaps, unused exports, and outdated patterns. Use this skill when the user asks to audit their codebase for tech debt, wants a health check of their code quality, says things like \"where should I focus refactoring\", \"find code smells\", \"audit my codebase\", \"what technical debt do we have\", \"prioritize cleanup work\", or asks about code quality metrics. Also trigger when the user mentions \"code rot\", \"legacy cleanup\", \"refactoring priorities\", or wants to understand the overall health of a project before a major effort. Trigger even if the user doesn't say \"technical debt\" explicitly — any request to systematically assess code quality and identify improvement priorities belongs here.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Ftechnical-debt-auditor\u002FSKILL.md",[113],{"categoryNo":85,"categoryName":86,"taxonomyType":21,"taxonomyTypeDesc":22},[115,116,117,118,119,120,121,122,123,124,125,96,126,127,128,129,130,131,132,133],"technical debt","debt","technical","technical debt auditor","auditor","coverage","complexity","markers","project","cleanup","unused","code","todo","work","plan","focus","signals","audit","dependency",{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":138,"categories":139,"keywords":149,"publishedAt":42},"01M70KPYH9QNHCNME5GJQGE22K","readonly-sql-guard","Make an agent's database access provably read-only. Use when an agent runs caller-supplied SQL against a production\u002FERP\u002Fanalytics database (a \"query\" MCP tool, text-to-SQL, an admin console), or when reviewing DB-access code for write\u002FDDL\u002Fside-effect\u002Ftransaction-escape risks. Checks what a statement CALLS, not just its shape.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdatabase\u002Freadonly-sql-guard\u002FSKILL.md",[140,143,144],{"categoryNo":141,"categoryName":142,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口",{"categoryNo":85,"categoryName":86,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":145,"categoryName":146,"taxonomyType":147,"taxonomyTypeDesc":148},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[150,151,152,153,154,155,156,37,157,158,159,160,161,162,163,95,164,165,96,166],"readonly","guard","sql guard","sql","readonly sql guard","erp","effect","read-only","db","just","tool","calls","only","MCP","access","database","query",{"skillNo":168,"name":169,"nameZh":6,"description":170,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":171,"licenseFileUrl":172,"sourceHtmlUrl":173,"categories":174,"keywords":178,"publishedAt":42},"01M6AFY6F7CC2BBZP1QD6VTNVC","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FSKILL.md",[175],{"categoryNo":176,"categoryName":177,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",[179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,37,201],"artifacts builder","web","web artifacts builder","artifacts","builder","state","routing","state management","component","css","frontend","ui","Tools","file","components","shadcn","react","Tailwind","suite","jsx","html","single-file","ui components",{"skillNo":203,"name":204,"nameZh":6,"description":205,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":171,"licenseFileUrl":206,"sourceHtmlUrl":207,"categories":208,"keywords":213,"publishedAt":42},"01M6AFWF33SFV9Z3SF4PEEE4BF","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FSKILL.md",[209,212],{"categoryNo":210,"categoryName":211,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",{"categoryNo":176,"categoryName":177,"taxonomyType":21,"taxonomyTypeDesc":22},[214,215,216,217,218,180,219,189,190,220,221,222,223,37,224,98,225],"webapp testing","testing","webapp","browser","playwright","applications","debugging","toolkit","logs","screenshots","local","behavior",{"skillNo":227,"name":228,"nameZh":6,"description":229,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":171,"licenseFileUrl":230,"sourceHtmlUrl":231,"categories":232,"keywords":240,"publishedAt":42},"01M6AF67Q67JJJ5V51JR2P52KA","discernment-nudge","After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FSKILL.md",[233,236,237],{"categoryNo":234,"categoryName":235,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":85,"categoryName":86,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":238,"categoryName":239,"taxonomyType":147,"taxonomyTypeDesc":148},"01JBSEEDCAT000000000000036","内容创作者",[241,242,243,244,245,246,27,247,182,248,192,126,249,250,251,252,253,162,254,96,255,256,257,258,259,104,260],"discernment nudge","nudge","interpretation","help","run","reasoning","writing","lookup","content","review","conversation","short","up","invoke","you","analysis","claims","argument","assemble","recommendations"]