• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
华东 博客
17年国科大博士毕业,曾就职于三星电子,清华博后,目前在某大模型创业公司工作,研究方向大模型、智能体 新浪博客: http://blog.sina.com.cn/u/2463286753
博客园    首页    新随笔    联系   管理    订阅  订阅
How to decide on the correct number of clusters?


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

posted on 2015-06-24 22:58  华东博客  阅读(348)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3