K-means clustering algorithm.
[model,y] = nan_kmeans(X,num_centers) [model,y] = nan_kmeans(X,num_centers,Init_centers)
[model,y] = nan_kmeans(X,num_centers) runs K-means clustering where inital centers are randomly selected from the input vectors X. The output are found centers stored in structure model.
[model,y] = nan_kmeans(X,num_centers,Init_centers) uses init_centers as the starting point.
Input vectors.
Number of centers.
Starting point of the algorithm.
Found clustering:
Found centers.
Implicitly added labels 1..num_centers.
Number of iterations.
[1xt] Mean-Square error at each iteration.
Labels assigned to data according to
X = [rand(100,2,'normal')+ones(100,2); rand(100,2,'normal')-ones(100,2)]; [model,idx] = nan_kmeans( X, 2 ); plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12) plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12) ctrs=model.X; plot(ctrs(:,1),ctrs(:,2),'ko', 'MarkerSize',12,'LineWidth',2) plot(ctrs(:,1),ctrs(:,2),'kx', 'MarkerSize',12,'LineWidth',2); legend('Cluster 1','Cluster 2','Centroids', 'Location','NW')