custom-distance-metrics
Define custom distance/similarity metrics for clustering and ML algorithms
Install / Use
npx skills add benchflow-ai/skillsbench --skill custom-distance-metricsInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Development & EngineeringSupported Platforms
Our assessment of custom-distance-metrics
custom-distance-metrics scores 86/100 on our quality scale, 1589th of 3,997 Development & Engineering skills we index (top 40%).
Its SKILL.md is 2.6 KB long, well organised into 12 sections with 4 code examples: a solid amount of guidance for an agent.
With 1,813 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated about 2 months ago, so custom-distance-metrics is actively maintained.
- It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
custom-distance-metrics compared with similar skills
All 4 of these similar skills score higher than custom-distance-metrics; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| custom-distance-metrics (this skill)by benchflow-ai | 86 | 1.8k | 2mo ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 86.4k | 15d ago | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 74.2k | today | CLAUDE.md |
| ai-job-searchby MadsLorentzen | 100 | 44.6k | today | CLAUDE.md |
| claude-howtoby luongnv89 | 100 | 41.7k | today | CLAUDE.md |
Frequently asked questions
- How do I install custom-distance-metrics?
- Run
npx skills add benchflow-ai/skillsbench --skill custom-distance-metrics. The install tabs above show the steps for each supported agent. - Which AI agents does custom-distance-metrics work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is custom-distance-metrics safe to use?
- It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is custom-distance-metrics still maintained?
- The repository was last updated about 2 months ago, so custom-distance-metrics is actively maintained.
Skill content
View source on GitHubname: custom-distance-metrics description: Define custom distance/similarity metrics for clustering and ML algorithms. Use when working with DBSCAN, sklearn, or scipy distance functions with application-specific metrics.
Custom Distance Metrics
Custom distance metrics allow you to define application-specific notions of similarity or distance between data points.
Defining Custom Metrics for sklearn
sklearn's DBSCAN accepts a callable as the metric parameter:
from sklearn.cluster import DBSCAN
def my_distance(point_a, point_b):
"""Custom distance between two points."""
# point_a and point_b are 1D arrays
return some_calculation(point_a, point_b)
db = DBSCAN(eps=5, min_samples=3, metric=my_distance)
Parameterized Distance Functions
To use a distance function with configurable parameters, use a closure or factory function:
def create_weighted_distance(weight_x, weight_y):
"""Create a distance function with specific weights."""
def distance(a, b):
dx = a[0] - b[0]
dy = a[1] - b[1]
return np.sqrt((weight_x * dx)**2 + (weight_y * dy)**2)
return distance
# Create distances with different weights
dist_equal = create_weighted_distance(1.0, 1.0)
dist_x_heavy = create_weighted_distance(2.0, 0.5)
# Use with DBSCAN
db = DBSCAN(eps=10, min_samples=3, metric=dist_x_heavy)
Example: Manhattan Distance with Parameter
As an example, Manhattan distance (L1 norm) can be parameterized with a scale factor:
def create_manhattan_distance(scale=1.0):
"""
Manhattan distance with optional scaling.
Measures distance as sum of absolute differences.
This is just one example - you can design custom metrics for your specific needs.
"""
def distance(a, b):
return scale * (abs(a[0] - b[0]) + abs(a[1] - b[1]))
return distance
# Use with DBSCAN
manhattan_metric = create_manhattan_distance(scale=1.5)
db = DBSCAN(eps=10, min_samples=3, metric=manhattan_metric)
Using scipy.spatial.distance
For computing distance matrices efficiently:
from scipy.spatial.distance import cdist, pdist, squareform
# Custom distance for cdist
def custom_metric(u, v):
return np.sqrt(np.sum((u - v)**2))
# Distance matrix between two sets of points
dist_matrix = cdist(points_a, points_b, metric=custom_metric)
# Pairwise distances within one set
pairwise = pdist(points, metric=custom_metric)
dist_matrix = squareform(pairwise)
Performance Considerations
- Custom Python functions are slower than built-in metrics
- For large datasets, consider vectorizing operations
- Pre-compute distance matrices when doing multiple lookups
Related Skills
Agent-Reach
86.4kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
74.2kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
ai-job-search
44.6kThe job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.
claude-howto
41.7kA visual, example-driven guide to Claude Code — from basic concepts to advanced agents, with copy-paste templates that bring immediate value.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
