<jupyter_start><jupyter_text>Exploratory Data Analysis<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
%matplotlib inline
titanic = pd.read_csv('titanic.csv')
titanic.head()<jupyter_output><empty_output><jupyter_text>Explore Continuous features<jupyter_code>titanic.describe()
titanic.groupby('Survived').mean()
titanic.groupby(titanic['Age'].isnull()).mean()<jupyter_output><empty_output><jupyter_text>Plot contnuous features<jupyter_code>for i in ['Age', 'Fare']:
    died = list(titanic[titanic['Survived'] == 0][i].dropna())
    survived = list(titanic[titanic['Survived'] == 1][i].dropna())
    xmin = min(min(died), min(survived))
    xmax = max(max(died), max(survived))
    width = (xmax - xmin) / 40
    sns.distplot(died, color='r', kde=False, bins=np.arange(xmin, xmax, width))
    sns.distplot(survived, color='g', kde=False, bins=np.arange(xmin, xmax, width))
    plt.legend(['Did not survive', 'Survived'])
    plt.title('Overlaid histogram for {}'.format(i))
    plt.show()
for i, col in enumerate(['Pclass', 'SibSp', 'Parch']):
    plt.figure(i)
    sns.catplot(x=col, y='Survived', data=titanic, kind='point', aspect=2,)
titanic['Family_cnt'] = titanic['SibSp'] + titanic['Parch']
sns.catplot(x='Family_cnt', y='Survived', data=titanic, kind='point', aspect=2,)
#Drop irrelevant continuous variable
titanic.drop('PassengerId', axis=1, inplace=True)
titanic.head()<jupyter_output><empty_output><jupyter_text>Fill missing for age<jupyter_code>titanic.groupby(titanic['Age'].isnull()).mean()
titanic['Age'].fillna(titanic['Age'].mean(), inplace=True)
titanic.isnull().sum()
titanic.head(10)
# Drop all continuous features
cont_feat = ['Pclass', 'Name', 'Age', 'SibSp', 'Parch', 'Fare']
titanic.drop(cont_feat, axis=1, inplace=True)
titanic.head()<jupyter_output><empty_output><jupyter_text>Explore categorical features<jupyter_code>titanic.info()
titanic.groupby(titanic['Cabin'].isnull()).mean()
titanic['Cabin_ind'] = np.where(titanic['Cabin'].isnull(), 0, 1)
titanic.head(10)<jupyter_output><empty_output><jupyter_text>Plot categorical features<jupyter_code>for i, col in enumerate(['Cabin_ind', 'Sex', 'Embarked']):
    plt.figure(i)
    sns.catplot(x=col, y='Survived', data=titanic, kind='point', aspect=2, )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1817789291882556, 'fraction_numerical': 0.006476683937823834, 'mean_word_length': 7.8773946360153255, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '584594', 'license': 'MIT', 'n_tokens_mistral': 950, 'n_tokens_neox': 906, 'n_words': 144, 'path': 'EDA.ipynb', 'repo_name': 'pavannaik3009/Titanic', 'size': '2316'}