-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexist_methods.m
70 lines (48 loc) · 1.53 KB
/
exist_methods.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
function [ kmeans_ri, hclust_ri ] = exist_methods( X,K,truth,distance_metric )
if strcmp(distance_metric,'squaredeuclidean')
distance_metric1 = 'sqeuclidean';
else
distance_metric1 = distance_metric;
end
%% Clustering on X1
%%% K-means
trials = 10;
kmeans_ri_ind = zeros(1,trials);
for r = 1:trials
idx = kmeans(X',K,'Distance',distance_metric1);
kmeans_ri_ind(r) = rand_index(idx',truth,'adjusted');
end
kmeans_ri = mean(kmeans_ri_ind);
% Hierarchical Clustering
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
Z = linkage(X','complete',distance_metric);
% Z = linkage(X','average','cityblock');
idx3 = cluster(Z,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
hclust_ri.complete = mean(hclust_ri_ind);
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
Z = linkage(X','single',distance_metric);
idx3 = cluster(Z,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
hclust_ri.single = mean(hclust_ri_ind);
%%% Average
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
Z = linkage(X','average',distance_metric);
idx3 = cluster(Z,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
hclust_ri.average = mean(hclust_ri_ind);
% Ward
hclust_ri_ind = zeros(1,trials);
for r = 1:trials
Z = linkage(X','ward');
idx3 = cluster(Z,'maxclust',K);
hclust_ri_ind(r) = rand_index(idx3',truth,'adjusted');
end
hclust_ri.ward = mean(hclust_ri_ind);
end