% Demo for LFD1 : vectors, rescaling and visualisation

clear all; close all

% columns are:  age, education, sex(1=male), hours worked per week, >50K=1 

data = xlsread('age_eduction_data.xls');


% transform each attribute to have zero mean and unit variance :
m1 = mean(data(:,1)); std1 = std(data(:,1));
newdata(:,1) = (data(:,1) - m1)./std1; % age

m2 = mean(data(:,2)); std2 = std(data(:,2));
newdata(:,2) = (data(:,2) - m2)./std2; %  Education

m4 = mean(data(:,4)); std4 = std(data(:,4));
newdata(:,3) = (data(:,4) - m4)./std4; % hours per week


ms = 15; fs=20; % some stuff for printing
plot3(newdata(:,1),newdata(:,2),newdata(:,3),'.','markersize',ms,'linewidth',4);
xlabel('age','fontsize',fs); ylabel('education','fontsize',fs); zlabel('hours','fontsize',fs)
set(gca,'fontsize',20)

pause
close

% now colour code this :
% blue cirlce for male, magenta circle for female
% green cross for >50K, red cross for <50K

men = find(data(:,3)==1); women = find(data(:,3)==0);
rich = find(data(:,5)==1); poor = find(data(:,5)==0);

plot3(newdata(men,1),newdata(men,2),newdata(men,3),'bo','markersize',ms,'linewidth',4); hold on
plot3(newdata(women,1),newdata(women,2),newdata(women,3),'mo','markersize',ms,'linewidth',4); hold on
xlabel('age','fontsize',fs); ylabel('education','fontsize',fs); zlabel('hours','fontsize',fs)
set(gca,'fontsize',20)

plot3(newdata(rich,1),newdata(rich,2),newdata(rich,3),'gx','markersize',ms,'linewidth',4); hold on
plot3(newdata(poor,1),newdata(poor,2),newdata(poor,3),'rx','markersize',ms,'linewidth',4); hold on
xlabel('age','fontsize',fs); ylabel('education','fontsize',fs); zlabel('hours','fontsize',fs)
set(gca,'fontsize',20)

