% function which loads data and apply PCA on them


function final_mat=pca_fin_v1(folder) 
% load data
X=load(folder); % address of the initial data
X=X.Matrix'; %examples in rows 
% PCA from coursera
% normalization towards mean
[X_norm, mu, sigma]=featureNormalize(X);
% sigma matrix computation
cov_mat=1/size(X_norm,1)*X_norm'*X_norm;
% SVD
[U, S, V]=svd(cov_mat);
% creer data
k=20;
Ured=U(:, 1:k);
Z=Ured'*X_norm';
% Z is the final data we have 
%% FINAL 20 dimensions is enough to keep 99 variance 
%     0.962 -> 20 dimensions
end