%% test for princomp(Principal Component Analysis) clear all; clc; close all; %% load data set data=xlsread('D:\XX\PCA.xlsx','xx'); % input the name of files and sheets % data2=data(:, 201:1951); %% box plot forratings data % To get a quickimpression of the ratings data, make a box plot % figure; % boxplot(data2,'orientation','horizontal','labels',categories); % grid on; %% pre-process % stdr =std(data2); % sr=repmat(stdr,400,1); % sr =data2./repmat(stdr,400,1); %% use princomp [coeff,score,latent,tsquare]= pca(data,'NumComponents',10); %% extract the principal component % figure; percent_explained= 100*latent/sum(latent); %cumsum(latent)./sum(latent) pareto(percent_explained); xlabel('PrincipalComponent'); ylabel('VarianceExplained (%)'); %% Visualizing theResults % figure; % biplot(coeff(:,1:2),'scores',score(:,1:2),... % 'varlabels',categories); % biplot(coeff(:,1:10),'scores',score(:,1:10),'varlabels',categories); % biplot(coeff(:,1:2),'varlabels',categories); % hold on % scatter(score(1:150,1),score(1:150,2),'g') % % hold on; scatter(score(151:329,1),score(151:329,2),'r') % axis([-.26 1 -.51.51]);