Skip to content

Instantly share code, notes, and snippets.

@Yeaseen
Created December 8, 2018 08:21
Show Gist options
  • Save Yeaseen/945f3ed053f172ce9c3b9b65448b13a3 to your computer and use it in GitHub Desktop.
Save Yeaseen/945f3ed053f172ce9c3b9b65448b13a3 to your computer and use it in GitHub Desktop.
M = np.mean(train.T, axis=1)
C= M - train
V=np.cov(C.T)
eigenValues, eigenVectors =eig(V)
k=2
idx = eigenValues.argsort()[-k:][::-1]
eigenValues = eigenValues[idx]
eigenVectors = eigenVectors[:,idx]
P = eigenVectors.T.dot(C.T)
PrincipalComponents=P.T
#from sklearn.decomposition import PCA
#pca = PCA(n_components=2)
#principalComponents = pca.fit_transform(train)
plt.scatter(PrincipalComponents[:,0], PrincipalComponents[:,1], color=['red'], marker= '*', s=7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment