Exercise 5.3: PCA 1) Apply PCA to the data - output of Exercise 5.2 (with no outliers) in order to reduce the dimension
Posted: Fri May 20, 2022 11:52 am
Exercise 5.3: PCA 1) Apply PCA to the data - output of
Exercise 5.2 (with no outliers) in order to reduce the dimension
from 3 to 2 (use "PCA(n_components = 2)". 2) Transform your
data (3 dimensional) to a new data (2 dimensional) by applying
"pca.transform", then print the shapes and the first 5 rows of your
data and new/transformed data.
this is the cod for Exercise 5.2
df = pd.DataFrame(columns= ["Normal","Exp1","Exp2"])
df["Normal"] = np.random.normal(0,1,200)
df["Exp1"] = np.random.exponential(2,200)
df["Exp2"] = np.random.exponential(3,200)
sns.distplot(df["Normal"])
sns.distplot(df["Exp1"])
sns.distplot(df["Exp2"])
Exercise 5.2 (with no outliers) in order to reduce the dimension
from 3 to 2 (use "PCA(n_components = 2)". 2) Transform your
data (3 dimensional) to a new data (2 dimensional) by applying
"pca.transform", then print the shapes and the first 5 rows of your
data and new/transformed data.
this is the cod for Exercise 5.2
df = pd.DataFrame(columns= ["Normal","Exp1","Exp2"])
df["Normal"] = np.random.normal(0,1,200)
df["Exp1"] = np.random.exponential(2,200)
df["Exp2"] = np.random.exponential(3,200)
sns.distplot(df["Normal"])
sns.distplot(df["Exp1"])
sns.distplot(df["Exp2"])