dbscan-custom-metric-weighting
Implementing a weighted Euclidean distance metric for DBSCAN to account for anisotropic spatial features.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- dbscan-custom-metric-weighting
- description
- Implementing a weighted Euclidean distance metric for DBSCAN to account for anisotropic spatial features.
03 SKILL.md 正文
When clustering spatial data where features (like x and y coordinates) have different importance or scales, a custom distance metric can be used with sklearn.cluster.DBSCAN.
The formula provided: $d(a, b) = \sqrt{(w \cdot \Delta x)^2 + ((2 - w) \cdot \Delta y)^2}$ allows for "stretching" or "compressing" the influence of horizontal vs vertical distances.
Implementation with Scikit-Learn:
To use this with DBSCAN, you can define a function and pass it to the metric parameter.
from sklearn.cluster import DBSCAN
import numpy as np
def custom_dist(a, b, w):
dx = a[0] - b[0]
dy = a[1] - b[1]
return np.sqrt((w * dx)**2 + ((2 - w) * dy)**2)
# Using it in DBSCAN (note: using lambda to pass the weight)
db = DBSCAN(eps=epsilon, min_samples=min_samples,
metric=lambda u, v: custom_dist(u, v, weight))
clusters = db.fit_predict(points)
Alternatively, for performance during grid search, precomputing the distance matrix or using a vectorized function inside the metric argument is recommended.
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
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.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.