【Matlab】層次聚類並繪製氣泡圖
阿新 • • 發佈:2018-12-24
%% 層次聚類 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