-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_hierarchical.m
56 lines (47 loc) · 1.87 KB
/
demo_hierarchical.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
%% DEMO: Evaluation of clusterings generated by a hierarchical algorithm
% ------------------------------------------------------------------------
% The Cluster Validity Index Tooolbox (CVIT) for automatic determination
% of clusters from clustering solution contains more than 70 functions (m-files)
% This toolbox was developed with MATLAB R2014a.
%
% Developed by
% Adan Jose-Garcia (adan.jose@cinvestav.mx)
% Wilfrido Gomez Flores (wgomez@cinvestav.mx)
%
% Please, cite the following paper where this toolbox was introduced:
%
% [PENDING]...
%
%
% IMPORTANT: First run "RUN_ME_FIRST.m" file to add this toolbox to search path.
%------------------------------------------------------------------------
clc; clear all; close all;
addpath([pwd '/proximity']);
addpath([pwd '/cvi']);
addpath([pwd '/datasets']);
% List of available cluster validity indices (CVIs)
CVInames = {'xb','ch','sf','pbm','cs',...
'gd31','gd41','gd51','gd33','gd43',...
'gd53','db2','db','cop','sil',...
'dunn','sv','sym','sdunn','sdb',...
'sdbw','cind'};
% List of available distances
Distnames = {'euc','neuc','cos','pcorr','scorr','lap'};
% List of datasets provided
DSnames = {'Data_4_3','Data_5_2','Moon', 'Iris'};
% ------------------------------------------------------------------------
%% Evaluate a set of clusterings generated by a hierarchical clustering algorithm
% Load the Iris dataset
load fisheriris;
% Hierarchical methods: 'single', 'complete', 'weighted', 'centroid', 'ward'
hmethod = 'average';
Z = linkage(meas, hmethod);
% Generation of clusterings when varying the number of clusters
Kmax = 10;
clust = zeros(size(meas,1),Kmax);
for k=1:Kmax
clust(:,k) = cluster(Z, 'maxclust', k);
end
% Evaluation of the clustering solutions using the 'ch' index
DXX = pdist2(meas,meas,'Euclidean'); % Euclidean distance matrix
eva = evalcvi(clust, 'sil', DXX)