Skip to content

Instantly share code, notes, and snippets.


amankharwal/ Secret

Created Feb 18, 2021
What would you like to do?
#PCA without Scikit-Learn
X_centered = X - X.mean(axis=0)
U, s, Vt = np.linalg.svd(X_centered)
c1 = Vt.T[:, 0]
c2 = Vt.T[:, 1]
m, n = X.shape
S = np.zeros(X_centered.shape)
S[:n, :n] = np.diag(s)
W2 = Vt.T[:, :2]
X2D =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment