tabular-haversine-knn-candidate-generation
A high-performance utility for finding geographically proximate entities using KNN and haversine distance.
Install
mkdir -p .claude/skills/tabular-haversine-knn-candidate-generation && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13150" && unzip -o skill.zip -d .claude/skills/tabular-haversine-knn-candidate-generation && rm skill.zipInstalls to .claude/skills/tabular-haversine-knn-candidate-generation
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Generates geographically proximate candidate pairs for entity matching using KNN with haversine distance, optionally partitioned by country.Key capabilities
- →Generate geographically proximate candidate pairs
- →Partition data by country or region for efficiency
- →Calculate haversine distance between coordinates
- →Build candidate pair DataFrames with distance and rank
- →Extract K nearest neighbors for each record
How it works
This skill uses K-Nearest Neighbors with haversine distance to find geographically closest candidates. It partitions data by country to reduce the search space before fitting the KNN model.
Inputs & outputs
When to use tabular-haversine-knn-candidate-generation
- →Generate location candidates
- →Perform entity matching
- →Find closest entities
- →Cluster spatial data
About this skill
Haversine KNN Candidate Generation
Overview
Entity matching at scale requires a candidate generation step — comparing all N^2 pairs is infeasible. For location-based entities (POIs, stores, addresses), KNN with haversine distance finds the K geographically closest candidates per record. Partitioning by country/region reduces the search space further and prevents cross-continent false matches. The resulting candidate pairs are then scored by a downstream classifier.
Quick Start
import numpy as np
from sklearn.neighbors import NearestNeighbors
def generate_geo_candidates(df, n_neighbors=20, partition_col="country"):
"""Generate candidate pairs using haversine KNN per partition."""
all_candidates = []
for group, group_df in df.groupby(partition_col):
group_df = group_df.reset_index(drop=True)
coords = np.deg2rad(group_df[["latitude", "longitude"]].values)
knn = NearestNeighbors(
n_neighbors=min(len(group_df), n_neighbors),
metric="haversine", n_jobs=-1
)
knn.fit(coords)
dists, indices = knn.kneighbors(coords)
for i in range(len(group_df)):
for j in range(1, len(indices[i])): # skip self-match
all_candidates.append({
"id": group_df.iloc[i]["id"],
"match_id": group_df.iloc[indices[i][j]]["id"],
"geo_dist": dists[i][j] * 6371, # km
"neighbor_rank": j,
})
return pd.DataFrame(all_candidates)
candidates = generate_geo_candidates(df, n_neighbors=20)
Workflow
- Convert lat/lon to radians (required by haversine metric)
- Partition data by country or region to reduce search space
- Fit KNN with haversine metric per partition
- Extract K nearest neighbors and distances for each record
- Build candidate pair DataFrame with distance and rank features
Key Decisions
- n_neighbors: 10-50 typical; higher recall but more pairs to classify
- Partitioning: By country prevents cross-region false matches; skip for global matching
- Distance unit: Haversine returns radians; multiply by 6371 for kilometers
- Dual index: Combine geo KNN with text-based KNN for higher recall
References
When not to use it
- →When global matching is required without regional partitioning
- →When comparing all N^2 pairs is feasible for small datasets
- →When the primary matching criteria is not location-based
Limitations
- →The `n_neighbors` parameter impacts recall and the number of pairs to classify
- →Partitioning by country prevents cross-continent false matches
- →Haversine metric returns radians, requiring conversion for kilometers
How it compares
This skill optimizes location-based entity matching by combining haversine distance with regional partitioning, which is more efficient than comparing all pairs or performing global matching for large datasets.
Compared to similar skills
tabular-haversine-knn-candidate-generation side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| tabular-haversine-knn-candidate-generation (this skill) | 0 | 4mo | No flags | Intermediate |
| quant-analyst | 103 | 2mo | No flags | Advanced |
| umap-learn | 6 | 2mo | Review | Intermediate |
| embedding-strategies | 8 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
quant-analyst
zenobi-us
Expert quantitative analyst specializing in financial modeling, algorithmic trading, and risk analytics. Masters statistical methods, derivatives pricing, and high-frequency trading with focus on mathematical rigor, performance optimization, and profitable strategy development.
umap-learn
K-Dense-AI
UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.
embedding-strategies
wshobson
Select and optimize embedding models for semantic search and RAG applications. Use when choosing embedding models, implementing chunking strategies, or optimizing embedding quality for specific domains.
building-automl-pipelines
jeremylongshore
Build automated machine learning pipelines, including feature engineering, model selection, and performance evaluation.
model-compare
rawwerks
Compare 3D CAD models using boolean operations (IoU, Dice, precision/recall). Use when evaluating generated models against gold references, diffing CAD revisions, or computing similarity metrics for ML training. Triggers on: model diff, compare models, IoU, intersection over union, model similarity, CAD comparison, STEP diff, 3D evaluation, gold reference, generated model, precision recall 3D.
matchms
davila7
Mass spectrometry analysis. Process mzML/MGF/MSP, spectral similarity (cosine, modified cosine), metadata harmonization, compound ID, for metabolomics and MS data processing.