Weighted k - means algorithm

WKMeans[w_,A_,z_,Ind_:0]:=Module[{m=Length[A],k=Length[z],c0,Pod,imin,tab,PI,It=0},
Pod=Table[{w[[i]],A[[i]]},{i,m}];
c0=z; 
PI=Table[{},{i,k}]; 
			(* Minimal distance principle *)
Do[
tab=Table[Norm[Pod[[i,2]]-c0[[j]]],{j,k}];
imin=Ordering[tab,1][[1]];
PI[[imin]]=Append[PI[[imin]],Pod[[i]]],
{i,m}];
PI=DeleteCases[PI,{}];
k=Length[PI];
If[Ind≠ 0,Print[It,": F = ",WF[PI]]];
						(* New centers *)
While[
c=Table[Mean[WeightedData[PI[[j,All,2]],PI[[j,All,1]]]],{j,Length[PI]}]; 
		(* The case of reducing the number of clusters in a partition
				in the case n=2 - can be extended to an arbitrary n *)
If[Length[c]<Length[c0],
Print["There was a case of reducing the number of clusters in the partition {",Length[c0]," -> ",Length[c],"}\nTry with a new initial centers"];
	];
Chop[Norm[c-c0]]≠0,c0=c;It=It+1;
				(* New partition *)
PI=Table[{},{i,k}]; 
Do[
tab=Table[Norm[Pod[[i,2]]-c0[[j]]],{j,k}];
imin=Ordering[tab,1][[1]];
PI[[imin]]=Append[PI[[imin]],Pod[[i]]],
{i,m}];
PI=DeleteCases[PI,{}];
k=Length[PI]; 
If[Ind≠ 0,Print[It,": F = ",WF[PI]]];
               ];
{PI,c0,WF[PI],It}]

Example

(* Call Submodule WF[] *)
A={{1,5},{2,4},{3,6},{2,7},{2,1},{3,2},{4,1},{3,1},{6,5},{8,5},{7,4},{7,6}}//N; w=Table[1,{i,Length[A]}];   z0={{3,3},{2,2},{5,7}}; 
slpod2=ListPlot[{A,z0},PlotStyle->{PointSize[.05]},AspectRatio->Automatic,GridLines->Automatic];
time=Timing[sol=WKMeans[w,A,z0]];
Print["F= ",WF[sol[[1]]]//N,   ";  G= ",WG[sol[[1]]]//N,"; CPU=",time[[1]], "; It = ",sol[[4]]];
(* Figures *)
Print["k-means reconstruction for selected centers z0: ",z0]
slc=ListPlot[sol[[2]],PlotMarkers->{"✶",20},PlotStyle->{Gray,PointSize[.025],Opacity[.7]}];
slPI=ListPlot[Table[sol[[1,j,All,2]],{j,Length[sol[[2]]]}],PlotStyle->Table[{PointSize[.05],Hue[j/k]},{j,Length[sol[[2]]]}]];
sl3=Show[slPI,slc,AspectRatio->Automatic,AxesOrigin->{0,0}];
Print[GraphicsGrid[{{slpod2,sl3}},ImageSize->Medium]]