normalization

PHOTO EMBED

Thu Aug 08 2024 04:21:05 GMT+0000 (Coordinated Universal Time)

Saved by @signup

from sklearn.preprocessing import MinMaxScaler
scaler=MinMaxScaler()
columns_to_scale=['Age','Salary','Experience','Dependents','Rating']
df[columns_to_scale]=scaler.fit_transform(df[columns_to_scale])
df.head()
*******************************
  from sklearn.preprocessing import LabelEncoder,OneHotEncoder
from sklearn.compose import ColumnTransformer
l=LabelEncoder()
df['Purchased']=l.fit_transform(df['Purchased'])
ed_mapping={'Bachelor':1,'Master':2,'PhD':3}
df['Education']=df['Education'].map(ed_mapping)
df=pd.get_dummies(df,columns=['City','Product_Category'],drop_first=True)
df.head()
********************************
  from sklearn.decomposition import PCA
pca=PCA(n_components=2)
pca_f=pca.fit_transform(df[columns_to_scale])
pca_df=pd.DataFrame(pca_f,columns=['PCA1','PCA2'])
df=pd.concat([df,pca_df],axis=1)
df.head()
***********************
  df.drop('Name',axis=1,inplace=True)
df.head()
***************************
  import seaborn as sns
import matplotlib.pyplot as plt
corr_mat=df.corr()
plt.figure(figsize=(10,8))
sns.heatmap(corr_mat,annot=True,cmap="coolwarm")
plt.title("Correlation Matrix")
plt.show()
**********************************
  df.hist(bins=20,figsize=(20,15))
plt.show()
skewness=df.skew()
print(skewness)
**********************
  # prompt: plt.figure(figsize=(15,10))

plt.figure(figsize=(15,10))
sns.boxplot(data=df[['Age','Salary','Experience','Dependents','Rating']])
plt.title("Box Plots for Numerical Features")
plt.show()
*********************************
content_copyCOPY