Stanford 机器学习 Week8 作业:K-means Clustering and Principal Component Analysis
FindClosestCentroidsfori=1:size(X,1)
dis=sum((centroids-X(i,:)).^2,2);
[t,idx(i)]=min(dis);
endComputeCentroidsfori=1:K
id=find(idx==i);
tot=X(id,:);
centroids(i,:)=mean(tot);
endRandomInitialization