# How to form multiple clusters of given size from a set of points?

Let us consider a 2 dimensional space. There are 100 points in it. So, each point has its $$x$$ and $$y$$ coordinates. I want to form 10 clusters. Each cluster has 10 points.

How can I form such clusters.

• Oct 25 '18 at 22:18
• Your "definition" of a cluster needs some clarification. For a start: When are two points in the point cloud "adjacent"? Oct 25 '18 at 22:18
• @HenrikSchumacher, I have x and y-axis coordinates of 100 points. I want to perform clustring over these points. Lets say I want to generate 10 clusters, each cluster with exactly 10 elements. Oct 26 '18 at 16:20
• The result is depend by distance of points to cluster center. Consider this situation: cluster 1-points[1-11]-center1, cluster2-ponits[12-20]-center2. there are 11 points in cluster1, 9 points in cluster2, we can move point 11 to cluster2? But distance[center1, point11]< distance[center2, point11], is this valid? Oct 28 '18 at 5:05

You need an exact definition of "adjacent" as Henrik already said, because it is the bread and butter of finding clusters of similar elements.

pts = RandomReal[1, {100, 2}];
ListPlot[FindClusters[pts, 10], PlotStyle -> PointSize[0.05]] • Thanks. How do you gurantee that each cluster has 10 points? Oct 26 '18 at 11:20

Here an example for constructing two clusters, which can easily expanded to n clusters:

cstart = {1, 2};


Now this forms the "start"-cluster

   clusterStart = (# + cstart) & /@
RandomVariate[NormalDistribution[0, 0.5], {10^3, 2}];


Next a bunch of clusters, somewhat drifting apart from the start cluster

clusterList =
Table[(# + cstart + delta*{1, 1}) & /@
RandomVariate[NormalDistribution[0, 0.5], {10^3, 2}], {delta, 0.5,
4, 0.3}];


Lastly, forming the clusters:

clusterList = {clusterStart, #} & /@ clusterList;


Finally plotting the resulting point sets:

With[{out =
Graphics[{{Red, Point[#[]]}, {Green, Point[#[]]}},
Frame -> True] & /@ clusterList},
GraphicsGrid[Partition[out, 3], ImageSize -> Large]
]


this delivers: 