[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6JM7J5XMGWVC5YAGAF5TX0W":3,"skill-same:01M6JM7J5XMGWVC5YAGAF5TX0W":67},{"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":18,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":42,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":6,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M6JM7J5XMGWVC5YAGAF5TX0W","umap-learn",null,"UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D\u002F3D visualization, clustering preprocessing (HDBSCAN), supervised\u002Fparametric UMAP, for high-dimensional data.","transaurus\u002Fstaging-davila7-claude-code-templates","transaurus","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F210882017?v=4","01M6JH1R6ZCRXGJCTDP5ZKZBE6","Page Turner Agent","01M6JH1RBBR2P6Y0XWDGM4B0G7",0,"MIT","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],"learn","umap learn","umap","visualization","fast","data","clustering","3D","learning","preprocessing","dimensionality reduction","manifold","high","for","2d","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","34fa6acf794b9a6310d298cbb8fb8c9420a5edcf","cli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn",2,"https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates","https:\u002F\u002Fgithub.com\u002Ftransaurus","Automated works of Page Turner","2026-03-28 10:12:59",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add transaurus\u002Fstaging-davila7-claude-code-templates --skill umap-learn",{"tool":53,"command":54},"bunx","bunx skills add transaurus\u002Fstaging-davila7-claude-code-templates --skill umap-learn",{"tool":56,"command":57},"pnpm","pnpm dlx skills add transaurus\u002Fstaging-davila7-claude-code-templates --skill umap-learn","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002FSKILL.md",true,[61],{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fapi_reference.md","REFERENCE","参考文档",18966,"https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fumap-learn\u002Freferences\u002Fapi_reference.md",[68,94,115,138,158,181],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":34},"01M6JMRJR3BE0HGWFWDZSB853S","zapier-make-patterns","No-code automation democratizes workflow building. Zapier and Make (formerly Integromat) let non-developers automate business processes without writing code. But no-code doesn't mean no-complexity - these platforms have their own patterns, pitfalls, and breaking points.  This skill covers when to use which platform, how to build reliable automations, and when to graduate to code-based solutions. Key insight: Zapier optimizes for simplicity and integrations (7000+ apps), Make optimizes for power","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Fzapier-make-patterns\u002FSKILL.md",[],[75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,32,93],"zapier make patterns","patterns","make","zapier","writing","workflow","automation","code","integrations","business","use","power","complexity","platform","apps","how to","No-Code","which","spawner",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":34},"01M6JMR8YK6SWPCTG1MCQTMN9S","yeet","Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Fyeet\u002FSKILL.md",[],[96,101,102,103,104,105,106,107,108,109,110,111,85,112,113,114],"cli","github","commit","pull request","openai","pull","push","flow","open","gh","user","only","stage","github cli",{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":121,"publishedAt":34},"01M6JMQNFE64ZASQK90HARRXW8","workflow-automation","Workflow automation is the infrastructure that makes AI agents reliable. Without durable execution, a network hiccup during a 10-step payment flow means lost money and angry customers. With it, workflows resume exactly where they left off.  This skill covers the platforms (n8n, Temporal, Inngest) and patterns (sequential, parallel, orchestrator-worker) that turn brittle scripts into production-grade automation.  Key insight: The platforms make different tradeoffs. n8n optimizes for accessibility","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Fworkflow-automation\u002FSKILL.md",[],[80,81,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,32,93],"Workflow Automation","ai agents","accessibility","workflows","apache","execution","inngest","parallel","orchestrator","resume","n8n","payment","worker","scripts","temporal","with",{"skillNo":139,"name":140,"nameZh":6,"description":141,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":142,"categories":143,"keywords":144,"publishedAt":34},"01M6JMQDYJ0XETERPHGDR3EVGN","trigger-dev","Trigger.dev expert for background jobs, AI workflows, and reliable async execution with excellent developer experience and TypeScript-first design. Use when: trigger.dev, trigger dev, background task, ai background job, long running task.","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Ftrigger-dev\u002FSKILL.md",[],[145,146,147,148,149,125,150,126,127,151,85,152,153,154,155,156,157,137,32,93],"dev","trigger dev","trigger","design","typescript","async execution","first","async","developer experience","expert","task","background jobs","long",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":164,"publishedAt":34},"01M6JMQ5J6KK3GSX9FJCWWK6G6","planning-with-files","Transforms workflow to use Manus-style persistent markdown files for planning, progress tracking, and knowledge storage. Use when starting complex tasks, multi-step projects, research tasks, or when the user mentions planning, organizing work, tracking progress, or wants structured output.","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Fplanning-with-files\u002FSKILL.md",[],[165,166,167,137,168,80,169,170,171,172,173,174,85,175,176,177,178,179,180,32],"planning with files","planning","files","with files","storage","tasks","markdown","knowledge","projects","work","manus","structured output","progress","transforms","multi","output",{"skillNo":182,"name":183,"nameZh":6,"description":184,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":185,"categories":186,"keywords":187,"publishedAt":34},"01M6JMPWAT60RXXNEC4V9TRBRS","n8n-workflow-patterns","Proven workflow architectural patterns from real n8n workflows. Use when building new workflows, designing workflow structure, choosing workflow patterns, planning workflow architecture, or asking about webhook processing, HTTP API integration, database operations, AI agent workflows, or scheduled tasks.","https:\u002F\u002Fgithub.com\u002Ftransaurus\u002Fstaging-davila7-claude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fworkflow-automation\u002Fn8n\u002Fn8n-workflow-patterns\u002FSKILL.md",[],[80,188,132,189,76,190,191,125,192,170,166,193,194,195,196,197,198,199,200,201],"n8n workflow patterns","workflow patterns","n8n workflow","ai agent","architecture","database","api","planning workflow","structure","database operations","webhook","processing","http api","scheduled"]