
clear all
close all force

load fisheriris % meas (150 x 4), species cell(150)

[coefs,vars] = eigs(cov(meas));
scores=meas*coefs;
variances=diag(vars);

gse = ismember(species,'setosa');
gvi =  ismember(species,'virginica');
gve = ismember(species,'versicolor');

figure(1)
plot( meas(find(gse),1), meas(find(gse),2), 'ro') 
hold on
plot( meas(find(gvi),1), meas(find(gvi),2), 'go') 
plot( meas(find(gve),1), meas(find(gve),2), 'ko') 
legend('Setosa','Virginica','Versicolor',0)
xlabel('1st Coordinate')
ylabel('2nd Coordinate')
%print -depsc 'C:\Brani\Courses\isyestatu\Summer2014\HW1\fisherpca1.eps'

% 
figure(2)
plot( scores(find(gse),1), scores(find(gse),2), 'ro') 
hold on
plot( scores(find(gvi),1), scores(find(gvi),2), 'go') 
plot( scores(find(gve),1), scores(find(gve),2), 'ko') 
legend('Setosa','Virginica','Versicolor',0)
xlabel('1st Principal Component')
ylabel('2nd Principal Component')
%print -depsc 'C:\Brani\Courses\isyestatu\Summer2014\HW1\fisherpca2.eps'

variances(1)/sum(variances)   %    92.46% (explained by 1st PC)
figure(3)
pareto(variances) 
xlabel('Principal Component') 
ylabel('Variance Explained (%)')
%print -depsc 'C:\Brani\Courses\isyestatu\Summer2014\HW1\fisherpca3.eps'

