To read the given data and perform Feature Generation process and save the data to a file.
Feature Generation (also known as feature construction, feature extraction or feature engineering) is the process of transforming features into new features that better relate to the target.
Read the given Data
Clean the Data Set using Data Cleaning Process
Apply Feature Generation techniques to all the feature of the data set
Save the data to the file
import pandas as pd
df=pd.read_csv('/content/data.csv')
df
from sklearn.preprocessing import LabelEncoder,OrdinalEncoder
education=['High School','Diploma','Bachelors','Masters','PhD']
enc=OrdinalEncoder(categories=[education])
enc.fit_transform(df[['Ord_2']])
df['education']=enc.fit_transform(df[['Ord_2']])
df=df.drop('Ord_2',axis=1)
df
weather=['Cold','Warm','Hot','Very Hot']
enc1=OrdinalEncoder(categories=[weather])
enc1.fit_transform(df[['Ord_1']])
df['weather']=enc1.fit_transform(df[['Ord_1']])
df
from sklearn.preprocessing import OneHotEncoder
ohe=OneHotEncoder(sparse=False)
enc=pd.DataFrame(ohe.fit_transform(df[['City']]))
df=pd.concat([df,enc],axis=1)
df
from category_encoders import BinaryEncoder
be=BinaryEncoder()
newdata=be.fit_transform(df['bin_1'])
new_data=be.fit_transform(df['bin_2'])
df=pd.concat([df,new_data],axis=1)
df
from sklearn.preprocessing import StandardScaler
df1=df.copy()
df1.columns = df1.columns.astype(str)
# Or remove any columns with string values
df1 = df1.select_dtypes(exclude=['object'])
# Then apply the StandardScaler
sc = StandardScaler()
df1_scaled = pd.DataFrame(sc.fit_transform(df1), columns=df1.columns)
df1_scaled
from sklearn.preprocessing import MinMaxScaler
sc=MinMaxScaler()
df2=pd.DataFrame(sc.fit_transform(df1))
df2
from sklearn.preprocessing import MinMaxScaler
sc1=MinMaxScaler()
df3=pd.DataFrame(sc1.fit_transform(df1))
df3
from sklearn.preprocessing import RobustScaler
sc2=RobustScaler()
df4=pd.DataFrame(sc2.fit_transform(df1))
df4
import pandas as pd
df=pd.read_csv('/content/Encoding Data.csv')
df
from category_encoders import BinaryEncoder
be=BinaryEncoder()
data=be.fit_transform(df["bin_1"])
df=pd.concat([df,data],axis=1)
df
new_data = be.fit_transform(df["bin_2"])
df=pd.concat([df,newdata],axis=1)
df
df1=df.copy()
from sklearn.preprocessing import LabelEncoder,OrdinalEncoder
le=LabelEncoder()
oe=OrdinalEncoder()
df1["nom_0"] = oe.fit_transform(df1[["nom_0"]])
temp=['Cold','Warm','Hot']
oe2=OrdinalEncoder(categories=[temp])
df1['ord_2'] = oe2.fit_transform(df1[['ord_2']])
df1
from sklearn.preprocessing import StandardScaler
df1=df.copy()
df1.columns = df1.columns.astype(str)
# Or remove any columns with string values
df1 = df1.select_dtypes(exclude=['object'])
# Then apply the StandardScaler
sc = StandardScaler()
df1_scaled = pd.DataFrame(sc.fit_transform(df1), columns=df1.columns)
df1_scaled
#feature scaling
from sklearn.preprocessing import MinMaxScaler
sc=MinMaxScaler()
df0=pd.DataFrame(sc.fit_transform(df1),columns=df1.columns)
df0
from sklearn.preprocessing import MaxAbsScaler
sc2=MaxAbsScaler()
df3=pd.DataFrame(sc2.fit_transform(df1),columns=df1.columns)
df3
from sklearn.preprocessing import RobustScaler
sc3=RobustScaler()
df4=pd.DataFrame(sc3.fit_transform(df1),columns=df1.columns)
df4
import pandas as pd
df=pd.read_csv("titanic_dataset.csv")
df
#removing unwanted data
df.drop("Name",axis=1,inplace=True)
df.drop("Ticket",axis=1,inplace=True)
df.drop("Cabin",axis=1,inplace=True)
#data cleaning
df.isnull().sum()
df["Age"]=df["Age"].fillna(df["Age"].median())
df["Embarked"]=df["Embarked"].fillna(df["Embarked"].mode()[0])
df.isnull().sum()
df
#feature encoding
from category_encoders import BinaryEncoder
be=BinaryEncoder()
data=be.fit_transform(df[["Sex"]])
df=pd.concat([df,data],axis=1)
df
df1=df.copy()
from sklearn.preprocessing import LabelEncoder, OrdinalEncoder
embark=['S','C','Q']
e1=OrdinalEncoder(categories=[embark])
df1['Embarked'] = e1.fit_transform(df[['Embarked']])
df1
from sklearn.preprocessing import StandardScaler
df1=df.copy()
df1.columns = df1.columns.astype(str)
# Or remove any columns with string values
df1 = df1.select_dtypes(exclude=['object'])
# Then apply the StandardScaler
sc = StandardScaler()
df1_scaled = pd.DataFrame(sc.fit_transform(df1), columns=df1.columns)
df1_scaled
#feature scaling
from sklearn.preprocessing import MinMaxScaler
sc=MinMaxScaler()
df2=pd.DataFrame(sc.fit_transform(df1),columns=df1.columns)
df2
from sklearn.preprocessing import StandardScaler
sc1=StandardScaler()
df3=pd.DataFrame(sc1.fit_transform(df1),columns=df1.columns)
df3
from sklearn.preprocessing import MaxAbsScaler
sc2=MaxAbsScaler()
df4=pd.DataFrame(sc2.fit_transform(df1),columns=df1.columns)
df4
from sklearn.preprocessing import RobustScaler
sc3=RobustScaler()
df5=pd.DataFrame(sc3.fit_transform(df1),columns=df1.columns)
df5
Thus the experiment executed sucessfully.