Created
March 16, 2019 14:34
-
-
Save wangz10/478ff09ee665b3fb4078581e22886c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Compute covariance matrix | |
| C = np.dot(X.T, X) / (n-1) | |
| # Eigen decomposition | |
| eigen_vals, eigen_vecs = np.linalg.eig(C) | |
| # SVD | |
| U, Sigma, Vh = np.linalg.svd(X, | |
| full_matrices=False, | |
| compute_uv=True) | |
| # Relationship between singular values and eigen values: | |
| print(np.allclose(np.square(Sigma) / (n - 1), eigen_vals)) # True |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nvishnya X need to be z-score transformed: subtract mean then divided by standard deviation.
Actually it only need to be centered around 0 for them to be equivalent: