k-means clustering algorithm
1 view (last 30 days)
Show older comments
I have a data with dimension 1801 by 88, to be clustered into k regions. Intially, all the centres are assigned randomly. the 'i' th data , sig is assigned to the nearest data cluster, c based on minimum Euclidean distance, where i=1:1801 and j=1:k. After completeing the assigning process for all the data, the new position of centre is measured according to
I have written the accordingly, but is not run and I am unable to understand about new position of the centre, although I have written. But not clear to me. How to add number of iteration in this code.
please help me
load signal.dat;
sig=signal(:,1:88);
[maxrow,maxcol]=size(sig);
k=1;
for i=1:k
p(i,:)=randperm(size(sig,1));
end
for i=1:k
for j=1:88
c(i,j)=sig(p(i),j);%random initialization
end
end
temp=zeros(maxrow,1);
while 1
for i1=1:1801
for j=1:88
d(:,j)=sum(dist2(sig(:,j),c(1,j)));
end
[z,g]=max(d,[],1);
if g==temp
break;
else
temp=g;
end
for i=1:k
f=find(g==i);
if f
c(i,:)=mean(sig(find(g==i),:),1);
end
end
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox 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!