from sklearn import preprocessing | |
class FuncToNumber: | |
def ToNumber(df): | |
# transform non-numerical labels to numerical labels | |
#Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked | |
le = preprocessing.LabelEncoder() | |
df["Sex"] = le.fit_transform(df["Sex"]) | |
df["Age"] = le.fit_transform(df["Age"]) | |
df["Ticket"] = le.fit_transform(df["Ticket"]) | |
df["Fare"] = le.fit_transform(df["Fare"]) | |
df["Cabin"] = le.fit_transform(df["Cabin"]) | |
return df |