层次聚类分析、动态聚类分析
例
尽管我个人非常不喜欢人们被划分圈子,因为这样就有了歧视、偏见、排挤和矛盾,但“物以类聚,人以群分”确实是一种客观的现实——这其中就蕴含着聚类分析的思想。
层次聚类分析
1 2 3 4 5 6 7 8 9 10 11 12 13
| X=xlsread('chengji.xlsx')
x=zscore(X(:,2:3))
y=pdist(x,'euclidean')
Z=linkage(y,'average') obslabel=cell(3:1)
H=dendrogram(Z,0,'orientation','right','label',obslabel) set(H,'LineWidth',1,'Color','k') xlabel('标准化距离(类平均法)') inconsisten0=inconsistent(Z,4)
|
动态聚类分析
1 2 3 4 5 6 7
| 1.手动动态聚类分析 data=xlsread('chengji.xlsx') gc=data(:,1) data=zscore(data(:,2:3)) x1=data(:,1) x2=data(:,2) scatter(x1,x2,'r')
|
1 2 3 4
| startdata=data([7,11,27,33,22],:) idx=kmeans(data,5,'Start',startdata) [S,H]=silhouette(data,idx) gc(idx==1),gc(idx==2),gc(idx==3),gc(idx==4),gc(idx==5)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| ans = 3 12 21 28 34 36 37 40 ans = 11 13 14 19 23 24 30 39 ans = 5 8 10 26 27 ans = 6 9 18 29 33 ans = 1 2 4 7 15 16 17 20 22 25 31 32 35 38
|
1 2 3 4 5 6 7
| 2.自动动态聚类分析 data=xlsread('chengji.xlsx') gc=data(:,1) data=zscore(data(:,2:3)) idx=kmeans(data,4,'replicates',100) [S,H]=silhouette(data,idx) Leibie1=gc(idx==1),Leibie2=gc(idx==2),Leibie3=gc(idx==3),Leibie4=gc(idx==4)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| idx = 4 4 4 4 3 2 4 2 2 4 1 3 1 1 4 4 4 2 1 4 3 4 1 1 4 1 2 3 2 1 4 4 2 3 4 3 3 4 1 3 S = 0.8370 0.8517 0.2813 0.6478 0.5259 0.2780 0.7061 0.3439 0.5923 0.3430 0.8410 0.8241 0.4059 0.6917 0.7877 0.4397 0.5408 0.3044 0.6531 0.7272 0.5483 0.5974 0.6877 0.5867 0.7845 0.2691 0.1136 0.8183 0.5519 0.8519 0.8551 0.6766 0.5177 0.8740 0.6046 0.7840 0.7143 0.6256 0.7967 0.8840 H = Figure (1) - 属性: Number: 1 Name: '' Color: [0.9400 0.9400 0.9400] Position: [488 342 560 420] Units: 'pixels' 显示 所有属性 Leibie1 = 11 13 14 19 23 24 26 30 39 Leibie2 = 6 8 9 18 27 29 33 Leibie3 = 5 12 21 28 34 36 37 40 Leibie4 = 1 2 3 4 7 10 15 16 17 20 22 25 31 32 35 38
|
参考