Python for Machine Learning – Part 41 – FeatureEngineering

”’
Topic to be covered – Feature Engineering

SibSp – No of Siblings / Spouses aboard the Titanic Ship

Parch – No of Parenst / Children aboard the Titanic Ship

”’

import pandas as pd
import warnings

warnings.filterwarnings(‘ignore’)

train = pd.read_csv(‘train.csv’)

train[‘Family’] = train[‘SibSp’] + train[‘Parch’] + 1

train[‘FamSize’] = train[‘Family’]

train[‘FamSize’].loc[train[‘Family’] == 1] = ‘Small’

train[‘Family’].loc[train[‘Family’] == 1] = ‘Alone’

import matplotlib.pyplot as plt
import seaborn as sns

fig, (fig1,fig2) = plt.subplots(1,2,figsize=(10,5))
sns.barplot(data=train, x=’Family’,y=’Survived’, ax=fig1)
sns.countplot(data=train, x=’Family’,hue=’Survived’, ax=fig2)

fig, (fig3,fig4) = plt.subplots(1,2,figsize=(10,4))
sns.barplot(data=train, x=’FamSize’,y=’Survived’, ax=fig3)
sns.countplot(data=train, x=’FamSize’,hue=’Survived’, ax=fig4)

Leave a Comment

Your email address will not be published. Required fields are marked *