January 2018
Beginner to intermediate
316 pages
7h 14m
English
NumPy is a handy function that computes eigenvectors and eigenvalues that we can use in order to get the principal components of our iris dataset:
# calculate the eigenvectors and eigenvalues of our covariance matrix of the iris dataseteig_val_cov, eig_vec_cov = np.linalg.eig(cov_mat)# Print the eigen vectors and corresponding eigenvalues# in order of descending eigenvaluesfor i in range(len(eig_val_cov)): eigvec_cov = eig_vec_cov[:,i] print 'Eigenvector {}: \n{}'.format(i+1, eigvec_cov) print 'Eigenvalue {} from covariance matrix: {}'.format(i+1, eig_val_cov[i]) print 30 * '-'Eigenvector 1: [ 0.36158968 -0.08226889 0.85657211 0.35884393] Eigenvalue 1 from covariance matrix: 4.22484076832 ...Read now
Unlock full access