Run1 dbscan custom metric
Implementing custom distance metrics for DBSCAN in scikit-learn for specialized coordinate-based clustering.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run1_dbscan-custom-metricAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
0.9 KB, 226 tokens by cl100k_base, as published. Nobody here has run it
Custom Distance Logic
Standard DBSCAN in scikit-learn accepts a metric argument. To implement the specified weighted Euclidean distance:
d(a, b) = sqrt((w * Δx)² + ((2 - w) * Δy)²)
You should define a function:
import numpy as np
def get_custom_metric(w):
def distance(u, v):
# u and v are coordinate pairs [x, y]
dx = (u[0] - v[0]) * w
dy = (u[1] - v[1]) * (2 - w)
return np.sqrt(dx**2 + dy**2)
return distance
Pass this to the DBSCAN constructor: DBSCAN(eps=epsilon, min_samples=min_samples, metric=get_custom_metric(shape_weight)).
Note: Since metric='precomputed' is often faster for large datasets, consider pre-calculating the distance matrix if memory allows, or pass the callable directly if the dataset size per image is small.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.