ワンクリックで
dbscan-custom-metrics
Implement DBSCAN clustering with custom distance metrics using scikit-learn's pairwise_distances.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Implement DBSCAN clustering with custom distance metrics using scikit-learn's pairwise_distances.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
A comprehensive PDF toolkit for advanced data extraction and document analysis. Beyond text and table extraction, this tool is optimized for visual layout reasoning: it can map graphical elements to coordinates (such as determining appointment times based on their position on a calendar timeline) and identify color-coded features (e.g., distinguishing high-priority blocks from flexible blue-colored entries). Use this skill when the task requires interpreting schedule layouts, calculating durations from visual spans, or resolving scheduling conflicts based on the spatial and color properties of a PDF document.
Build deterministic, verifiable data visualizations with D3.js (v6). Generate standalone HTML/SVG (and optional PNG) from local data files without external network dependencies. Use when tasks require charts, plots, axes/scales, legends, tooltips, or data-driven SVG output.
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
| name | dbscan-custom-metrics |
| description | Implement DBSCAN clustering with custom distance metrics using scikit-learn's pairwise_distances. |
DBSCAN can use custom distance metrics by computing a precomputed distance matrix or using pairwise_distances with a custom metric function.
A custom metric function takes two 1D arrays (two points) and returns a scalar distance:
def custom_metric(u, v, shape_weight):
"""Compute weighted distance between two points."""
dx = u[0] - v[0]
dy = u[1] - v[1]
return np.sqrt((shape_weight * dx)**2 + ((2 - shape_weight) * dy)**2)
For DBSCAN with a custom metric, use metric='precomputed' and pass a precomputed distance matrix:
from sklearn.metrics.pairwise import pairwise_distances
from sklearn.cluster import DBSCAN
# Compute precomputed distance matrix
distances = pairwise_distances(
points,
metric=custom_metric,
metric_params={'shape_weight': w}
)
# Run DBSCAN with precomputed distances
clusterer = DBSCAN(eps=epsilon, min_samples=min_samples, metric='precomputed')
labels = clusterer.fit_predict(distances)
import numpy as np
from sklearn.metrics.pairwise import pairwise_distances
from sklearn.cluster import DBSCAN
def shape_weighted_distance(u, v, shape_weight):
"""Distance metric with shape weighting."""
dx = u[0] - v[0]
dy = u[1] - v[1]
return np.sqrt((shape_weight * dx)**2 + ((2 - shape_weight) * dy)**2)
def cluster_with_custom_metric(points, epsilon, min_samples, shape_weight):
"""Cluster points using DBSCAN with custom distance metric."""
if len(points) == 0:
return np.array([], dtype=int)
# Compute distance matrix
distances = pairwise_distances(
points,
metric=shape_weighted_distance,
metric_params={'shape_weight': shape_weight}
)
# Run DBSCAN
clusterer = DBSCAN(eps=epsilon, min_samples=min_samples, metric='precomputed')
labels = clusterer.fit_predict(distances)
return labels