% % Example 6.7 % This shows how to use the function for the whole MBC procedure. % % Written by: % -- % John L. Weatherwax 2005-08-14 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; drawnow; rehash; clc; clear; addpath( '../../Code/eda_data' ); addpath( '../../Code/eda_toolbox' ); addpath( '../Chapter1' ); %X = load_skulls(0,0,0,0); X = load_skulls(1,0,1,0); % <- computation z-score %X = load_skulls(1,0,0,1); % <- PCA based dimensionality reduction ... %X = load_skulls(1,0,0,2); % <- SVD based dimensionality reduction ... [n,p] = size(X); data = X; % Do the agglomerative model-based clustering which is included in the EDA Toolbox and the MBC Toolbox. Z = agmbclust(X); % Construct a dendrogram. figure; dendrogram(Z); title('Results for Skulls Data - Agglomerative MBC') saveas( gcf, '../../WriteUp/Graphics/Chapter6/prob_6_7_skulls_dendrogram', 'epsc' ); % Consider the uniform-gap statistics to determine the number of clusters % -- modified from Example 5.7 % K = 6; B = 50; [Z, khat, gap, Wobs, muWb] = gap_uniform(X,K,B); fprintf('khat = %10d\n',khat); % from the gap-statistic plot we find a prediction of four clusters figure; plot(1:K,Wobs,'o-',1:K,muWb,'x-') legend({'Observed';'Expected'}) xlabel('Number of Clusters k') ylabel('Observed and Expected log(W_k)') %saveas( gcf, '../../WriteUp/Graphics/Chapter6/prob_6_7_skulls_wobs', 'epsc' ); figure; plot(1:K,gap,'o-'); xlabel('Number of Clusters k'); ylabel('Gap') %saveas( gcf, '../../WriteUp/Graphics/Chapter6/prob_6_7_skulls_gap', 'epsc' ); % We can apply the silhouette procedure for this result after we find a partition. cind = cluster(Z,'maxclust',3); figure; [S,H] = silhouette(X,cind); fprintf('mean silhouette value = %10.6f\n', mean(S) ); title('Silhouette Plot - Agglomerative MBC') saveas( gcf, '../../WriteUp/Graphics/Chapter6/prob_6_7_skulls_silhouette', 'epsc' );