Straight SQL Kmean
✓ Published0🌍 Public
Aandrewxhill
Last edited Oct 11, 2012
Created on Oct 11, 2012
Straight SQL Kmean demonstrates k-means clustering directly in PostgreSQL, showing how spatial points group into nine clusters based on proximity. The visualization maps each input point to its nearest cluster centroid, with cluster membership determined by recursive SQL queries and PostGIS geometric functions like `ST_Distance`, `ST_Centroid`, and `ST_Collect`. It uses `CDB_RectangleGrid` to generate initial centroids and `UNNEST` to iterate through cluster assignments over 20 refinement steps. The final output renders points colored by cluster ID via CartoDB's web mercator geometry.
AI-generated description