Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.datasets import load_breast_cancer
- import numpy as np
- import pandas as pd
- from sklearn.preprocessing import StandardScaler
- data = load_breast_cancer()
- df = pd.DataFrame(data = data.data, columns = data.feature_names)
- print(df.head())
- #NEXT CELL
- standardized = StandardScaler()
- standardized.fit(df)
- StandardScaler(copy = True, with_mean = True, with_std = True)
- scaled_data = standardized.transform(df)
- print(scaled_data)
- #NEXT CELL
- from sklearn.decomposition import PCA
- import matplotlib.pyplot as plt
- import seaborn as sns
- pca = PCA(n_components = 2)
- pca.fit(scaled_data)
- x_pca = pca.transform(scaled_data)
- %matplotlib inline
- fig = plt.figure(figsize = (8,8))
- ax = fig.add_subplot(1,1,1)
- ax.set_xlabel('Principal Component 1', fontsize = 15)
- ax.set_ylabel('Principal Component 2', fontsize = 15)
- ax.set_title("2 Component PCA", fontsize = 15)
- ax.scatter(x_pca[:,0], x_pca[:,1])
Advertisement
Add Comment
Please, Sign In to add comment