Guest User

Experiment 7(1)

a guest
Apr 23rd, 2025
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. from sklearn.datasets import load_breast_cancer
  2. import numpy as np
  3. import pandas as pd
  4. from sklearn.preprocessing import StandardScaler
  5. data = load_breast_cancer()
  6. df = pd.DataFrame(data = data.data, columns = data.feature_names)
  7. print(df.head())
  8.  
  9. #NEXT CELL
  10. standardized = StandardScaler()
  11. standardized.fit(df)
  12. StandardScaler(copy = True, with_mean = True, with_std = True)
  13. scaled_data = standardized.transform(df)
  14. print(scaled_data)
  15.  
  16. #NEXT CELL
  17. from sklearn.decomposition import PCA
  18. import matplotlib.pyplot as plt
  19. import seaborn as sns
  20. pca = PCA(n_components = 2)
  21. pca.fit(scaled_data)
  22. x_pca = pca.transform(scaled_data)
  23. %matplotlib inline
  24. fig = plt.figure(figsize = (8,8))
  25. ax = fig.add_subplot(1,1,1)
  26. ax.set_xlabel('Principal Component 1', fontsize = 15)
  27. ax.set_ylabel('Principal Component 2', fontsize = 15)
  28. ax.set_title("2 Component PCA", fontsize = 15)
  29. ax.scatter(x_pca[:,0], x_pca[:,1])
Advertisement
Add Comment
Please, Sign In to add comment