用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill custom-dbscan-metric命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
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.
基于 SOC 职业分类
正在显示 SKILL.md
| name | custom-dbscan-metric |
| description | Implementation of a custom distance metric for DBSCAN clustering using scipy and sklearn. |
When using DBSCAN with a non-standard distance metric, you can either provide a callable to the metric parameter or precompute the distance matrix.
For the Mars cloud task, the distance is defined as:
d(a, b) = sqrt((w * Δx)² + ((2 - w) * Δy)²)
Precomputing the distance matrix is often more efficient for grid searches if the metric is reused or if you want to use sklearn.cluster.DBSCAN.
import numpy as np
from scipy.spatial.distance import cdist
from sklearn.cluster import DBSCAN
def custom_metric(p1, p2, w):
dx = p1[0] - p2[0]
dy = p1[1] - p2[1]
return np.sqrt((w * dx)**2 + ((2 - w) * dy)**2)
# Vectorized version for efficiency
def precompute_custom_distance(X, w):
# X is (N, 2)
# Using cdist with a custom lambda can be slow,
# better to use vectorized numpy if possible.
X_weighted = X * np.array([w, 2 - w])
# Note: the formula is sqrt((w*dx)^2 + ((2-w)*dy)^2)
# which is equivalent to standard Euclidean distance on weighted coordinates
return cdist(X_weighted, X_weighted, metric='euclidean')
# Using DBSCAN with precomputed metric
# dist_matrix = precompute_custom_distance(X, w)
# db = DBSCAN(eps=epsilon, min_samples=min_samples, metric='precomputed')
# labels = db.fit_predict(dist_matrix)
epsilon in DBSCAN will be compared against the distances produced by this custom metric.shape_weight (w) is applied correctly to the coordinates before distance calculation if using standard Euclidean as a shortcut.