text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

import seaborn as sns

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.model_selection import train_test_split, cross_val_score, GridSearchCV
from sklearn.metrics import confusion_matrix, accuracy_score
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB

data_train = pd.read_csv('/kaggle/input/titanic/train.csv')
data_test = pd.read_csv('/kaggle/input/titanic/test.csv')
data_total = data_train.append(data_test, ignore_index=True)
data_train_length = len(data_train.index)
for c in ['Age', 'Fare']:
    g = sns.FacetGrid(data_train, col='Survived')
    g.map(plt.hist, c)
corr = data_train.corr()

age_mean_by_pclass = data_total[['Pclass', 'Age']].groupby('Pclass').mean()
data_total['Age'] = data_total.apply(lambda row: age_mean_by_pclass.loc[row['Pclass'], 'Age'] if np.isnan(row['Age']) else row['Age'], axis=1)
fare_median_by_pclass = data_total[['Pclass', 'Fare']].groupby('Pclass').median()
data_total['Fare'] = data_total.apply(lambda row: fare_median_by_pclass.loc[row['Pclass'], 'Fare'] if np.isnan(row['Fare']) else row['Fare'], axis=1)
data_total['Embarked'].fillna(data_total['Embarked'].mode()[0], inplace=True)
data_total.info()