{"version":"1.0","type":"rich","title":"Better Kmeans loop for any number of clusters","description":"A PostgreSQL recursive query iteratively refines k-means clustering on natural earth point data, partitioning features into an arbitrary number of groups. The process seeds centroids from a rectangular grid generated with CartoDB’s `CDB_RectangleGrid`, then repeatedly reassigns points to the nearest centroid and recomputes cluster centers using `ST_Centroid` and `ST_Collect`. After ten iterations, each point is labeled with its final cluster ID via a spatial join on `ST_Distance`. The output shows the clustered point assignments, not the centroid geometries.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-3906431?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}