Line 20 in PCA should change, eig returns eigenvalues , eigenvectors. It is stated in reverse form in the code.