Test-Example~9.3:  6 clusters in R^2

(* 
Submodules: WKMeans[], WF[], WG[], Rand[], Hdist[];
Output: data set, optimal partition, Rand and Jaccard index, confusion matrix;
*)

SeedRandom[1213];
c={{-8,-6},{-3,-8},{-1,-1},{8,4},{6,9},{-1,8}};
var=1.5; broj=200; AG={{-15,15},{-15,15}};
podaci=Table[RandomVariate[MultinormalDistribution[ci,var IdentityMatrix[2]],broj],{ci,c}];
pod=Flatten[podaci,1]; 
m=Length[pod];
w=Table[1,{i,m}];
Dimensions[pod]	
						(* PODACI *)
A=Flatten[podaci,1];
xG={Min[A[[All,1]]]-.5,Max[A[[All,1]]]+.5};yG={Min[A[[All,2]]]-.5,Max[A[[All,2]]]+.5};
AG={xG,yG};
m=Length[A];
w=Table[1,{i,m}]; 
slA=ListPlot[A,PlotStyle->{PointSize[.01]},AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG,ImageSize->Small]
slc=ListPlot[c,PlotStyle->{Gray,PointSize[.03],Opacity[.6]}];
slpod1=Show[ListPlot[podaci,PlotStyle->{PointSize[.01]}],slc,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG,ImageSize->Small]
z0={{-10,-8},{0,-8},{0,0},{0,8},{8,2},{8,10}};k=Length[z0];
slz0=ListPlot[z0,PlotStyle->{Red,PointSize[.04],Opacity[.8]}];
slpod2=Show[slA,slz0,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG];
GraphicsGrid[{{slpod1,slpod2}},ImageSize->Medium]
							(* k-means *)
time=Timing[sol=WKMeans[w,A,z0]];
Print["F= ",WF[sol[[1]]],   ";  G= ",WG[sol[[1]]],"; CPU=",time[[1]]]
							(* SLIKE *)
Print["k-means reconstruction for selected centers z0: ",z0]
slc=ListPlot[sol[[2]],PlotMarkers->{"✶",20},PlotStyle->{Red,PointSize[.025],Opacity[.7]}];
slPI=ListPlot[Table[sol[[1,j,All,2]],{j,k}],PlotStyle->Table[Hue[j/k],{j,k}]];
PI1=Table[Union[sol[[1,j,All,2]]],{j,Length[sol[[1]]]}];
sl3=Show[slA,slc,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG];
Print[GraphicsGrid[{{slpod1,sl3}},ImageSize->Medium]];
tab=Table[sol[[1,j,All,2]],{j,Length[sol[[1]]]}];
ind=Rand[podaci,tab];
Print["Hausdorff dist. = ",Hdist[sol[[2]],c]]
Print["{Rand, Jaccard} index = ",{ind[[1]],ind[[2]]}]
Print["Confusion matrix S= ",ind[[3]]//MatrixForm]