您的位置:首页 > 其它

How to decide on the correct number of clusters?

2015-06-24 22:58 435 查看
Determining the number of clusters/segments in hierarchical clustering/segmentation algorithms

由于unique函数在这里找矩阵不同元素的时不能有效得到,所以自己编了小程序实现。

Matlab codeL:

clear
load fisheriris
figure(1)
Z = linkage(meas,'ward','euclidean');%Create a hierarchical binary cluster tree using linkage
[Hr,Tr]=dendrogram(Z);  %generates a dendrogram plot of the hierarchical binary cluster tree

val0=eval(vpa(Z(:,3),5));

t=1; n(1)=0; val=val0(1); f(1)=val;
for i=1:length(val0)
if val0(i)==val
n(t)=n(t)+1;
continue
else
t=t+1;
val=val0(i);
n(t)=1;
f(t)=val;
continue
end
end
figure(2)
fsum=cumsum(n);
plot(length(val0)-fsum, f, 'o-','LineWidth', 2)
xlabel('Number of Clusters')
ylabel('Merge Distance')
title('A sample evalution graph')




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: