<< Cluster Analysis Cluster Analysis Descriptive Statistics >>

NaN Toolbox >> NaN Toolbox > Cluster Analysis > nan_kmeans

nan_kmeans

K-means clustering algorithm.

Calling Sequence

[model,y] = nan_kmeans(X,num_centers)
[model,y] = nan_kmeans(X,num_centers,Init_centers)

Description

[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.

Parameters

Input:

X [num_data x dim]:

Input vectors.

num_centers [1x1]:

Number of centers.

Init_centers [1x1]:

Starting point of the algorithm.

Output:

model [struct]:

Found clustering:

.X [num_centers x dim]:

Found centers.

.y [1 x num_centers]:

Implicitly added labels 1..num_centers.

.t [1x1]:

Number of iterations.

.MsErr:

[1xt] Mean-Square error at each iteration.

y [1 x num_data]:

Labels assigned to data according to

Examples

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')

Authors


<< Cluster Analysis Cluster Analysis Descriptive Statistics >>