# Compact Spatial Clustering with exogen variable

I have a table with 2400 polygons being a partition of a country at a low level. I have as well the population and the area for each polygon, giving me the density of each polygon.

I would like to make compact clusters of polygons to get nice-looking regions, based on the density.

Step 1, I took for each polygon the centroid then do a k-means with the coordinates of the centroids and the log of the density(as values could go from 0 to 400K).

The result is not resilient, as it depends a lot on the initial position of the points in the k-means algorithm and the result is not compact.

I am looking for another approach to this problem, which could solve my issues, aka:

• Clusters are not resilient

• Clusters are not compact

• Clusters should take in account the density variable.

• Not mandatory, but if I could ppick the number of clusters, it is a plus.

So far, I tried to do a bagging hierarchical clustering to solve the resilient issue (worse than the non-bagging one) and to play with the normalisation of the variables. But My ideas come to an end.

I code with R, but nice solutions in python welcome.

• No result ever will be resilient, because it depends on how you normalize your data, will it? – Anony-Mousse Dec 8 '15 at 22:09
• Yes, the clusters depends highly on the normalisation. Normalise the longitude and latitude doesn't make sense from my point of view, as I want to put the distance in my cluster. The log normalisation of density allows to have the difference between two coordinates in the same order as the difference between two density. But I would expect that with the same normalisation and different algorithm, the result would be a little bit similar. It is not, except where the difference in density is really high between consecutive polygons. – YCR Dec 8 '15 at 22:33
• Now, I think the resilience issue could be solve, if I manage to solve the compact issue. – YCR Dec 8 '15 at 22:34