-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_kmeans.m
61 lines (49 loc) · 1.95 KB
/
demo_kmeans.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
%% DEMO: Evaluation of clustering solutions generated by k-means
% ------------------------------------------------------------------------
% 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 ([email protected])
% Wilfrido Gomez Flores ([email protected])
%
% 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 some datasets provided
DSnames = {'Data_4_3','Data_5_2','Moon', 'Iris'};
% ------------------------------------------------------------------------
%% Evaluate a clustering solution generated by the k-means algorithm
% Example 1
load Data_4_3;
X = data(:,1:end-1);
clust = kmeans(X,4,'distance','sqeuclidean');
eva1 = chindex(clust,X);
%E2 = evalclusters(X,clust,'CalinskiHarabasz');
% Example 2
load fisheriris;
clust = kmeans(meas,3,'distance','sqeuclidean');
eva2 = chindex(clust,meas);
%% Evaluate a set of clustering solutions generated by k-means algorithm
% Load the Iris dataset
load fisheriris;
% Generation of clusterings using k-means and varying the number of clusters
Kmax = 6;
clust = zeros(size(meas,1),Kmax);
for k=1:Kmax
clust(:,k) = kmeans(meas,k,'distance','sqeuclidean');
end
% Evaluation of the clustering solutions using the 'ch' index
eva = evalcvi(clust, 'ch', meas)