Retrieving the data points when performing clustering

1 view (last 30 days)
I have a data matrix that contains the observations on its rows and the features on the columns. I am performing spectral clustering to cluster the data, so I calculate the correlation matrix and then generate the laplacian graph to finally apply kmeans on the resulting matrix. My code (part of it) is shown below:
load('census.mat'); %load the data
X = bsxfun(@times,census,1./sqrt(sum(census.^2,1)));%normalize the columns
X = X(:,3:end); %Pick up the useful data
n = size(X,1);
K = size(X,2);
S = corr(X'); %Calculate the correlation(adjancency) matrix
A = sparse((abs(S) > 0.75)*1.); %Sparse the matrix with the given threshold
degs = sum(A,2); %degree of rows of A
DD = diag(degs.^(-.5)); %diagonal elements ^ -0.5
Lsym = DD*A*DD; %Calculate the Laplacian graph matrix
[U,D] = eigs(Lsym,20); %Calculate the first twenty eigenvalues(vectors)
d = diag(D); %d contains the eigenvalues in its diagonal
[~,I] = sort(d,'descend'); %sort them
V = U(:,I); %V is the sorted eigenvectors
K = 5;
VV = V(:,I(1:10));
VV = bsxfun( @times, VV, 1./ sqrt(sum(VV.^2,2)) ); %normalize each row
Nit = 1;
figure(3), clf,
%calculate the Kmeans with K=5 and plot
for t = 1:Nit
[IDX, C] = kmeans(VV, K, 'MaxIter', 200);
colors = jet(K); %generate the colors
subplot(1,1,t), hold on
for k = 1:K
idx = IDX == k;
plot3(VV(idx,I(1)),VV(idx,I(2)),VV(idx,I(3)), '.', 'color', colors(k,:))
end
%axis equal
view(3)
grid on
end
What I wish to do now is to add an ID column to the original data, giving each observation an ID (possibly numbers 1...n), and then be able to track the observations to finally identify each point that is assigned to each cluster (i.e. point 1 is assigned to cluster 5, point 2 is assigned to cluster 3, etc.).
I kind of lost the track of my data points after doing the eigenvalue decomposition and sorting the data, so I am a bit confused how to have the data points organized so that I can identify them at the end.
Thank you

Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!