【Matlab】层次聚类并绘制气泡图

%% 层次聚类
Ncluster=5;         %聚类个数
%% data
xx=[0.7480    0.3852    1.6347;
    0.0232    0.4712    1.5317;
    0.5345    1.2082    1.6758;
    1.4728    0.0822    0.5044;
    0.4606    0.1168    1.4891;
    0.0223    0.1725    1.6759;
    0.6168    0.3941    1.3694;
    1.1760    0.1637    1.2768;
    0.4419    1.8362    0.2417;
    0.1609    0.5908    1.5335;
    0.4020    0.1438    1.6599;
    0.4368    1.2724    1.1251;
    1.6135    0.4609    0.3089;
    0.2746    1.6599    1.3660;
    1.6219    0.8850    0.5334;
    0.5491    1.5883    0.9841;
    0.1430    0.6150    1.5901;
    0.4776    0.7175    1.2943;
    0.5521    1.1103    0.2756;
    0.6750    0.0043    1.7092;
    0.6232    0.9450    1.3509;
    2.0627    0.3890    0.0770;
    0.2205    1.3761    0.0625;
    0.2722    1.2966    0.8168;
    0.0440    1.1775    1.0629;
    0.3717    0.5048    1.5623;
    0.2261    1.3210    1.7070;
    0.0453    0.0784    1.7615;
    1.2114    1.3764    0.1493;
    0.7879    1.2022    0.8279;
    1.0047    0.1420    1.6948;
    1.5137    0.0916    1.2293;
    0.5003    1.8880    0.8512;
    1.1719    1.4563    0.8741;
    1.4614    0.2990    0.4769;
    1.2483    0.4043    0.7533;
    0.5217    0.2078    1.7699;
    0.1006    1.1681    0.9148;
    0.3469    0.5783    1.5790;
    0.2860    0.2097    1.9930;
    0.8422    0.6160    1.6268;
    1.7767    1.3523    0.0971;
    0.6358    0.6706    1.5740;
    0.6760    0.3168    1.5125;
    0.0113    0.1121    1.8074;
    0.2494    0.2482    1.7111];
[number, ~]=size(xx);

%% Pairwise distance between observations.
%'euclidean':欧氏距离(默认);
%'seuclidean':标准化欧氏距离;
%'mahalanobis':马氏距离;
%'cityblock':布洛克距离;
%'minkowski':明可夫斯基距离;
%'cosine':余弦距离;
%'correlation':相关性;
%'hamming':汉明距离;
%'jaccard':Jaccard相似度
%'chebychev':Chebychev距离。
yy=pdist(xx,'euclidean');

%% Create hierarchical cluster tree.
%'single':单连通,最短距离法(默认);
%'complete':全连通,最长距离法;
%'average':未加权平均距离法; 
%'weighted': 加权平均法;
%'centroid': 质心距离法;
%'median':加权质心距离法;
%'ward':内平方距离法(最小方差算法)
zz=linkage(yy,'single');

%% Construct clusters from a hierarchical cluster tree.
result = cluster( zz,'maxclust', Ncluster ); 

%% Plot
sz = linspace(100,1000,number);
face_color = rand(Ncluster,3);
edge_color = rand(Ncluster,3);
for i=1:Ncluster
    for j=1:number
        if result(j)==i
            scatter3(xx(j,1)',xx(j,2)',xx(j,3)',sz(j),'MarkerFaceColor',face_color(i,:),'MarkerEdgeColor',edge_color(i,:));
            hold on;
        end
    end
end

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页