Advertisement
mahmoodn

Untitled

Dec 25th, 2020
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. from matplotlib.figure import Figure
  4. from sklearn.decomposition import PCA
  5. from sklearn.preprocessing import StandardScaler
  6.  
  7. #---------- Reading input
  8. df = pd.read_csv("test.csv", index_col=[0])
  9. print( df )
  10.  
  11. features = df.columns
  12. print( features )
  13.  
  14. x = df.loc[:, features].values
  15. print( x )
  16.  
  17. targets = df.index
  18. print( targets )
  19.  
  20. #---------- Do PCA
  21. x = StandardScaler().fit_transform(x)
  22. pca = PCA(n_components=2)
  23. principalComponents = pca.fit_transform(x)
  24. print( principalComponents )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement