Guest User

Untitled

a guest
Jan 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. # TEST
  2. def PCA_test():
  3. iris = datasets.load_iris()
  4. p = iris.data.shape[1]
  5. k = p
  6. X_reduced = PCA(n_components=k).fit(iris.data)
  7. X_reduced_eig = PCA_eig(iris.data, k)
  8. comp_diff = np.round(np.absolute(X_reduced.components_) - np.absolute(X_reduced_eig['components'].transpose()),3)
  9. print('Equal Components: ', np.array_equal(comp_diff,np.zeros([p,p])))
  10. var_diff = np.round(X_reduced.explained_variance_ - X_reduced_eig['explained_variance'], 3)
  11. print('Equal Explained Variance:', np.array_equal(var_diff, np.zeros(k)))
  12. return
  13.  
  14. PCA_test()
  15. # Output
  16. # Equal Components: True
  17. # Equal Explained Variance: True
Add Comment
Please, Sign In to add comment