Convert categorical features to numerical levels (Label Encoder)

PHOTO EMBED

Wed Mar 16 2022 09:24:44 GMT+0000 (UTC)

Saved by @abhin__dev

# Convert categorical features to numeric levels
for feature in ['Sex', 'Cabin', 'Embarked', 'Embarked_clean', 'Title']:
    le = LabelEncoder()
    titanic[feature] = le.fit_transform(titanic[feature].astype(str))
    
titanic.head()
content_copyCOPY