text_plain_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_data = pd.read_csv('/kaggle/input/titanic/train.csv')

test_data = pd.read_csv('/kaggle/input/titanic/test.csv')

train_data.dtypes

train_data.isnull().sum()

test_data.isnull().sum()

train_data.fillna(train_data.Age.mean(), inplace=True)
train_data['Cabin'].fillna('Unknown', inplace=True)
train_data['Embarked'].fillna('Unknown', inplace=True)
test_data.fillna(test_data['Age'].mean(), inplace=True)
test_data.fillna(test_data['Fare'].mean(), inplace=True)
test_data['Cabin'].fillna('Unknown', inplace=True)

train_data.groupby(['Sex'])['Survived'].value_counts(normalize=True)

train_data.groupby(['Pclass'])['Survived'].value_counts(normalize=True)

y = train_data['Survived'].values
features = train_data[['Pclass', 'Sex', 'SibSp', 'Parch']]
X = pd.get_dummies(features)
X.head()