Skip to main content
100%

Super naive but fast kmeans

✓ Published0🌍 Public
Aandrewxhill
Last edited Nov 29, 2012
Created on Nov 29, 2012

This example shows a fast, approximate k-means clustering of 500,000 geographic points, grouping them into up to 16 clusters by nearest centroid. It first reduces the data by aggregating points into a coarse grid, then uses a recursive PostGIS query with `ST_Centroid`, `ST_Collect`, and `ST_Distance` to iteratively refine cluster centers over 20 passes. The final query assigns each original point to its closest cluster using the `<->` spatial index operator, outputting a `kmean_id` for every record. The approach prioritizes speed over precision, completing in about 25 seconds.

AI-generated description

Similar vizzes