% % 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; clc; clear; addpath( '../../Code/eda_data' ); addpath( '../../Code/eda_toolbox' ); addpath( '../Chapter1' ); X = load_sparrow(1,0,1,0); [n,p] = size(X); % specify a number of cluster (and their threshold) to visualize ... % ... these are based on the dendrogram plot and would need to be changed for each new data set khat = 4; k_thresh = 3.; y = pdist(X,'euclidean'); z = linkage(y,'average'); figure; [h,T]=dendrogram(z,'colorthreshold',k_thresh); title( 'sparrow dendrogram with average linkage' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_5_sparrow_den', 'epsc' ); % % A treemap: % % Example 8.2 This shows the treemap implementation in Matlab. Let's continue with the same % leukemia data set as in the previous example. The matrix Z was calculated in Example 8.1. % treemap(z,khat); title( 'a treemap of the sparrow dataset' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_5_sparrow_tm', 'epsc' ); % % A rectangle plot: % % Example 8.3 Use same leukemia data set and matrix Z from Example 8.1. The second argument is the % number of clusters. The third argument is a string specifying what information the second argument % provides. % rectplot(z,khat,'nclus',zeros(1,n)) %rectplot(Z,13.0,'dis'); title( 'a rectangle plot of the sparrow dataset' ); saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_5_sparrow_rp', 'epsc' ); % % The ReClus plot % reclus(T); title( 'ReClus plot of the sparrow dataset' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_5_sparrow_rc', 'epsc' ); % % A data image: % % Example 8.6 This shows how to do the data image. % T = cluster(z,'maxclust',khat); % Sort these, so points in the same cluster are adjacent. [Ts,inds] = sort(T); % Sort the distance matrix using this and replot. Ys = squareform(y); figure imagesc(Ys(inds,inds)) title('Interpoint Distance Matrix - Cluster Order') colormap(gray(256)) axis off saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_5_sparrow_di', 'epsc' );