-
Notifications
You must be signed in to change notification settings - Fork 0
/
hclust_gower_2class.m
125 lines (87 loc) · 2.94 KB
/
hclust_gower_2class.m
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
function [ conca_hclust_ri, agg_hclust_ri ] = hclust_gower_2class( X,Y,K,truth )
trials = 10;
% The following are the same:
% Z1 = linkage(X','single','cityblock');
% Y = pdist(X','cityblock');
% Z2 = linkage(Y,'single');
% Z1 = Z2
XY = [X ; Y];
% Hierarchical Clustering using concatenate gower distance
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower(XY));
ZZ = linkage(D,'complete');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
conca_hclust_ri.complete = mean(hclust_ri_ind);
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower(XY));
ZZ = linkage(D,'single');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
conca_hclust_ri.single = mean(hclust_ri_ind);
%%% Average
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower(XY));
ZZ = linkage(D,'average');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
conca_hclust_ri.average = mean(hclust_ri_ind);
% Ward
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower(XY));
ZZ = linkage(D,'ward');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
conca_hclust_ri.ward = mean(hclust_ri_ind);
%% Hierarchical Clustering using Aggregate gower distance
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower_2data(X,Y));
ZZ = linkage(D,'complete');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
agg_hclust_ri.complete = mean(hclust_ri_ind);
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower_2data(X,Y));
ZZ = linkage(D,'single');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
agg_hclust_ri.single = mean(hclust_ri_ind);
%%% Average
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower_2data(X,Y));
ZZ = linkage(D,'average');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
agg_hclust_ri.average = mean(hclust_ri_ind);
% Ward
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
D = squareform(gower_2data(X,Y));
ZZ = linkage(D,'ward');
% Z = linkage(X','average','cityblock');
idx3 = cluster(ZZ,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
agg_hclust_ri.ward = mean(hclust_ri_ind);
end