
%Step 1--Import Dataset
D = importdata('../data/Mall_Customers.csv')
%Step 2--Take only the AnnualIncome & Spedingscore columns(4 & 5)
X=D.data(:,2:3);
N = size(X,1)
%Step 3--Perform Data Preprocessing
%Checking null value is present or not
	sum(ismissing(X))
%Standardization
%	Data.AnnualIncome=(Data.AnnualIncome-mean(Data.AnnualIncome))/std(Data.AnnualIncome);
%	Data.SpendingScore=(Data.SpendingScore-mean(Data.SpendingScore))/std(Data.SpendingScore);
%Convert the data from table to array 
%Data=table2array(Data);


Z=linkage(X,'ward')

g=unique(Z(:,3));
m=sort(g);
whos;pause;


mk=(m>=13);
m=m(mk);
figure(1);clf;
%pause(5);
for i=1:length(m)
	threshold = m(i)
	
	subplot(2,1,1);
	H=dendrogram(Z,N,'ColorThreshold',m(i));
	set(H,'LineWidth',1)
	c=cluster(Z,'cutoff',m(i),'Criterion','distance');
	subplot(2,1,2);
	gscatter(X(:,1),X(:,2),c);
	
	pause;
%	if(i~=length(m)) clf; end
end
