-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhier_clustering.m
49 lines (41 loc) · 1.28 KB
/
hier_clustering.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
function [c]=hier_clustering(dataset, number_of_clusters, algorithm)
switch algorithm
case 'complete'
Z = linkage(dataset,'complete');
case 'ward'
Z = linkage(dataset,'ward');
case 'WPGMC'
Z = linkage(dataset,'median');
otherwise
disp('Error: There is no hierarchical algorithm with this name')
end
% figure()
% dendrogram(Z)
% xlabel('Nodes - Patterns')
% tlt = "Agglomerative Clustering (" + algorithm + ")";
% title(tlt)
c = cluster(Z,'Maxclust',number_of_clusters);
% cuttoff = input('Give the cutoff, please:');
% depth = input('Give the depth, please:');
% c = cluster(Z,'cutoff',cuttoff, 'Criterion', 'distance');
% uv = unique(c)
% n = histc(c,uv)
% [~,i] = min(n);
% minmode = uv(i);
% if minmode < 50
% disp('remove outliers')
%
% end
figure()
scatter3(dataset(:,1),dataset(:,2),dataset(:,3),5,c);
xlabel('PC1')
ylabel('PC2')
zlabel('PC3')
tlt = "Dataset after Agglomerative Clustering (" + algorithm + ")";
title(tlt)
figure()
scatter(dataset(:,1),dataset(:,2),5,c);
xlabel('PC1')
ylabel('PC2')
title(tlt)
end