Skip to content

Instantly share code, notes, and snippets.

@wangz10
Created March 16, 2019 14:34
Show Gist options
  • Select an option

  • Save wangz10/478ff09ee665b3fb4078581e22886c8e to your computer and use it in GitHub Desktop.

Select an option

Save wangz10/478ff09ee665b3fb4078581e22886c8e to your computer and use it in GitHub Desktop.
# 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
@wangz10
Copy link
Author

wangz10 commented Nov 1, 2019

@ScientificDetectivesAgency is your matrix X z-scored?

@theprunuscerasus
Copy link

I also get False. What does "matrix X is z-scored" mean?

@wangz10
Copy link
Author

wangz10 commented May 23, 2020

@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:

X = X - X.mean(axis=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment