Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # TEST
- def PCA_test():
- iris = datasets.load_iris()
- p = iris.data.shape[1]
- k = p
- X_reduced = PCA(n_components=k).fit(iris.data)
- X_reduced_eig = PCA_eig(iris.data, k)
- comp_diff = np.round(np.absolute(X_reduced.components_) - np.absolute(X_reduced_eig['components'].transpose()),3)
- print('Equal Components: ', np.array_equal(comp_diff,np.zeros([p,p])))
- var_diff = np.round(X_reduced.explained_variance_ - X_reduced_eig['explained_variance'], 3)
- print('Equal Explained Variance:', np.array_equal(var_diff, np.zeros(k)))
- return
- PCA_test()
- # Output
- # Equal Components: True
- # Equal Explained Variance: True
Add Comment
Please, Sign In to add comment