#Importing the Relevant Libraries
#---------------------------------------------------------------------
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#Importing the Dataset from SkLearn & Converting to Dataframe
#---------------------------------------------------------------------
from sklearn.datasets import load_breast_cancer
dataset = load_breast_cancer()
df = pd.DataFrame(dataset.data, columns= dataset.feature_names)
#Feature Scaling
#---------------------------------------------------------------------
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
df_scaled = sc.fit_transform(df)
#Principal Component Analysis (PCA)
#---------------------------------------------------------------------
from sklearn.decomposition import PCA
pca = PCA(n_components = 2)
df_pca = pca.fit_transform(df_scaled)
#Shape of dataframe before & after Applying PCA
#---------------------------------------------------------------------
print('Before Applying PCA:', df.shape)
print('\nAfter Applying PCA:', df_pca.shape)
plt.figure(figsize=(8,6))
plt.scatter(df_pca[:,0],df_pca[:,1],c = dataset['target'])
plt.xlabel('First principle component')
plt.ylabel('Second principle component')
#Importing the Relevant Libraries
#---------------------------------------------------------------------
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#Importing the Dataset from SkLearn & Converting to Dataframe
#---------------------------------------------------------------------
from sklearn.datasets import load_iris
dataset = load_iris()
df = pd.DataFrame(dataset.data, columns= dataset.feature_names)
#Feature Scaling
#---------------------------------------------------------------------
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
df_scaled = sc.fit_transform(df)
#Principal Component Analysis (PCA)
#---------------------------------------------------------------------
from sklearn.decomposition import PCA
pca = PCA(n_components = 2)
df_pca = pca.fit_transform(df_scaled)
#Shape of dataframe before & after Applying PCA
#---------------------------------------------------------------------
print('Before Applying PCA:', df.shape)
print('\nAfter Applying PCA:', df_pca.shape)
plt.figure(figsize=(8,6))
plt.scatter(df_pca[:,0],df_pca[:,1],c = dataset['target'])
plt.xlabel('First principle component')
plt.ylabel('Second principle component')