• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

wordlinkage选择合适的聚类个数matlabcode

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
clear
load fisheriris
X = meas;
m  = size(X,2);
 % load machine
%  load census
% % X = meas;
% X=X(1:2000,:);
d = pdist(X,'euclidean');

Z = linkage(d,'ward');%Create a hierarchical binary cluster tree using linkage
% [Hr,Tr]=dendrogram(Z, 0);  %generates a dendrogram plot of the hierarchical binary cluster tree
% h_gca = gca;
% h_gca.TickDir = 'out';
% h_gca.TickLength = [.002 0];
% h_gca.XTickLabel = [];
% c = cluster

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);
x= length(val0)-fsum;
plot(x, f, 'o-','LineWidth', 2)
xlabel('Number of Clusters')
ylabel('Merge Distance')
title('A sample evalution graph')

% for i = 1: length(x)
%     y= cluster(Z, x(i));
%     B = Amean(X, y)
% end

x =x(end:-1:1);
f=f(end:-1:1);

i=0;
flag = 1;  b =  length(x); minerror_c_old = b-1;
while flag ~=0 & b>=20
    RMSE = [];
    for c = 2: (b-2)
        x1 = x(1:c); y1 = f(1 : c);
        x2 = x(c:b); y2 = f(c : b);
        [~, s1] = polyfit(x1, y1,1);
        [~, s2] = polyfit(x2, y2,1);
        RMSE(c-1) = ((c-1)/(b-1))*s1.normr + ( (b-c)/(b-1))*s2.normr;
    end
     [~, minerror_c ]= min(RMSE);
     minerror_c= minerror_c+1;
     if  minerror_c >= minerror_c_old
         break
     else
         minerror_c_old = minerror_c;
%           b = b -1;
          b = 2*minerror_c ;
     end
     i=i+1
end

hold on 
plot(x( minerror_c), f( minerror_c),'ro')
c =x( minerror_c)

labels = cluster(Z, c);

labs = unique(labels);
CORR = zeros();
for i = 1:length(labs)
    corri = cov(X(labels == i, :)); 
    CORR = CORR +  corri; 
end

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
DelphiXE10让android的界面设计摆脱繁杂发布时间:2022-07-18
下一篇:
Delphi 判断一个字符串是否为数字发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap