custom-distance-metrics

Define custom distance metrics for sklearn and scipy clustering tasks.

4|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/GeneralReasoning/env-skillsbench --skill custom-distance-metrics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: custom-distance-metrics
Source: https://github.com/GeneralReasoning/env-skillsbench/tree/main/mars-clouds-clustering/environment/skills/custom-distance-metrics
Command: npx skills add https://github.com/GeneralReasoning/env-skillsbench --skill custom-distance-metrics

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Define application-specific distance metrics for clustering and ML tasks.

Core Features & Use Cases

  • Custom metric functions for sklearn DBSCAN and scipy distance calculations
  • Parameterized distance functions via closures or factories
  • Use cases include computing distance matrices and pairwise distances for domain-specific data

Quick Start

Create a simple distance function and pass it to a clustering algorithm such as DBSCAN to see your custom metric in action.

Frequently Asked Questions about custom-distance-metrics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use a custom distance metric with DBSCAN in sklearn?

You can use a custom distance metric with DBSCAN by supplying a Python callable that accepts two 1D arrays and returns a scalar as the metric argument. This parameterized function enables sklearn DBSCAN to cluster vector data using your application-specific distance logic.

What is a custom distance metric for clustering?

A custom distance metric for clustering is an application-specific Python callable that calculates similarity between vector data points. It replaces standard distance formulas to handle domain-specific data requirements in metric-based clustering and similarity tasks.

Can I pass parameterized distance functions to scipy cdist or pdist?

Yes, you can pass parameterized distance functions to scipy cdist or pdist. By using closures or factories to parameterize your custom callable, you can supply it as the metric argument to compute pairwise distances for domain-specific vector data.

Does this approach support parameterized distance functions via closures?

Yes, this custom distance metric approach supports parameterization via closures or factories. You can create a Python callable that accepts two 1D arrays and returns a scalar, injecting parameters to customize clustering and similarity calculations for domain-specific data.

When do I need a custom distance metric for similarity-based ML tasks?

You need a custom distance metric for similarity-based ML tasks when standard distance formulas fail to capture domain-specific data relationships. Defining an application-specific Python callable ensures metric-based clustering algorithms process your vector data accurately.

What are the limitations of using custom metrics with sklearn and scipy?

A key limitation of custom metrics is that your function must be a Python callable accepting two 1D arrays and returning a scalar. This structural requirement ensures compatibility with sklearn and scipy but restricts metric design for clustering and similarity tasks.