{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.pyplot import figure\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:31.093821Z","iopub.execute_input":"2022-07-05T10:55:31.095304Z","iopub.status.idle":"2022-07-05T10:55:31.099732Z","shell.execute_reply.started":"2022-07-05T10:55:31.095277Z","shell.execute_reply":"2022-07-05T10:55:31.099143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"../input/titanic/train.csv\")\ndata.head()\n\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:31.143925Z","iopub.execute_input":"2022-07-05T10:55:31.144739Z","iopub.status.idle":"2022-07-05T10:55:31.163924Z","shell.execute_reply.started":"2022-07-05T10:55:31.144714Z","shell.execute_reply":"2022-07-05T10:55:31.163089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/titanic/gender_submission.csv\")\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:31.179588Z","iopub.execute_input":"2022-07-05T10:55:31.179822Z","iopub.status.idle":"2022-07-05T10:55:31.188912Z","shell.execute_reply.started":"2022-07-05T10:55:31.179800Z","shell.execute_reply":"2022-07-05T10:55:31.188071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:31.201146Z","iopub.execute_input":"2022-07-05T10:55:31.201524Z","iopub.status.idle":"2022-07-05T10:55:31.209480Z","shell.execute_reply.started":"2022-07-05T10:55:31.201501Z","shell.execute_reply":"2022-07-05T10:55:31.208587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(columns = ['PassengerId'])\ndata = data.drop(columns = ['Name'])\ndata = data.drop(columns = ['Cabin'])\ndata = data.drop(columns = ['Ticket'])","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:31.237408Z","iopub.execute_input":"2022-07-05T10:55:31.238075Z","iopub.status.idle":"2022-07-05T10:55:31.245087Z","shell.execute_reply.started":"2022-07-05T10:55:31.238050Z","shell.execute_reply":"2022-07-05T10:55:31.243861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:55:44.112511Z","iopub.execute_input":"2022-07-05T10:55:44.113043Z","iopub.status.idle":"2022-07-05T10:55:44.128404Z","shell.execute_reply.started":"2022-07-05T10:55:44.113002Z","shell.execute_reply":"2022-07-05T10:55:44.127019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T10:59:02.724946Z","iopub.execute_input":"2022-07-05T10:59:02.725313Z","iopub.status.idle":"2022-07-05T10:59:02.734305Z","shell.execute_reply.started":"2022-07-05T10:59:02.725284Z","shell.execute_reply":"2022-07-05T10:59:02.733252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.Age = data.Age.replace({np.nan:data[\"Age\"].mean()})","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:02:57.869334Z","iopub.execute_input":"2022-07-05T11:02:57.869647Z","iopub.status.idle":"2022-07-05T11:02:57.876387Z","shell.execute_reply.started":"2022-07-05T11:02:57.869623Z","shell.execute_reply":"2022-07-05T11:02:57.875257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:04:13.660664Z","iopub.execute_input":"2022-07-05T11:04:13.660962Z","iopub.status.idle":"2022-07-05T11:04:13.667260Z","shell.execute_reply.started":"2022-07-05T11:04:13.660939Z","shell.execute_reply":"2022-07-05T11:04:13.666724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"Embarked\"].mode()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:08:46.132326Z","iopub.execute_input":"2022-07-05T11:08:46.132621Z","iopub.status.idle":"2022-07-05T11:08:46.140222Z","shell.execute_reply.started":"2022-07-05T11:08:46.132598Z","shell.execute_reply":"2022-07-05T11:08:46.139416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndata.Embarked = data.Embarked.replace({np.nan:\"S\"})","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:13:01.000654Z","iopub.execute_input":"2022-07-05T11:13:01.000959Z","iopub.status.idle":"2022-07-05T11:13:01.006707Z","shell.execute_reply.started":"2022-07-05T11:13:01.000934Z","shell.execute_reply":"2022-07-05T11:13:01.006126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:13:21.133228Z","iopub.execute_input":"2022-07-05T11:13:21.133561Z","iopub.status.idle":"2022-07-05T11:13:21.142553Z","shell.execute_reply.started":"2022-07-05T11:13:21.133538Z","shell.execute_reply":"2022-07-05T11:13:21.141487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:15:14.610011Z","iopub.execute_input":"2022-07-05T11:15:14.610369Z","iopub.status.idle":"2022-07-05T11:15:14.626537Z","shell.execute_reply.started":"2022-07-05T11:15:14.610340Z","shell.execute_reply":"2022-07-05T11:15:14.625711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"a = data[\"Pclass\"].value_counts(sort=False)\nfig=plt.figure(figsize=(8,5),dpi=60)\nb = sns.barplot(x = a.index,y = a.values)\nb.set_xlabel(\"Pclass\", fontsize = 12)\nb.set_ylabel(\"Number of Pclass\", fontsize = 12)\nb.set_title(\"Number of Pclass in each area\")","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:16:06.355874Z","iopub.execute_input":"2022-07-05T11:16:06.356169Z","iopub.status.idle":"2022-07-05T11:16:06.535317Z","shell.execute_reply.started":"2022-07-05T11:16:06.356145Z","shell.execute_reply":"2022-07-05T11:16:06.534567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = data[\"Sex\"].value_counts(sort=False)\nfig=plt.figure(figsize=(8,5),dpi=60)\nb = sns.barplot(x = a.index,y = a.values)\nb.set_xlabel(\"Sex\", fontsize = 12)\nb.set_ylabel(\"Number of Sex\", fontsize = 12)\nb.set_title(\"Number of Sex in each area\")","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:16:35.642180Z","iopub.execute_input":"2022-07-05T11:16:35.642511Z","iopub.status.idle":"2022-07-05T11:16:36.234412Z","shell.execute_reply.started":"2022-07-05T11:16:35.642488Z","shell.execute_reply":"2022-07-05T11:16:36.233474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = data[\"SibSp\"].value_counts(sort=False)\nfig=plt.figure(figsize=(8,5),dpi=60)\nb = sns.barplot(x = a.index,y = a.values)\nb.set_xlabel(\"SibSp\", fontsize = 12)\nb.set_ylabel(\"Number of SibSp\", fontsize = 12)\nb.set_title(\"Number of SibSp in each area\")","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:17:07.030905Z","iopub.execute_input":"2022-07-05T11:17:07.031287Z","iopub.status.idle":"2022-07-05T11:17:07.173686Z","shell.execute_reply.started":"2022-07-05T11:17:07.031257Z","shell.execute_reply":"2022-07-05T11:17:07.172756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = data[\"Parch\"].value_counts(sort=False)\nfig=plt.figure(figsize=(8,5),dpi=60)\nb = sns.barplot(x = a.index,y = a.values)\nb.set_xlabel(\"Parch\", fontsize = 12)\nb.set_ylabel(\"Number of Parch\", fontsize = 12)\nb.set_title(\"Number of Parch in each area\")","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:17:42.715110Z","iopub.execute_input":"2022-07-05T11:17:42.715477Z","iopub.status.idle":"2022-07-05T11:17:42.873016Z","shell.execute_reply.started":"2022-07-05T11:17:42.715443Z","shell.execute_reply":"2022-07-05T11:17:42.871898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = data[\"Embarked\"].value_counts(sort=False)\nfig=plt.figure(figsize=(8,5),dpi=60)\nb = sns.barplot(x = a.index,y = a.values)\nb.set_xlabel(\"Embarked\", fontsize = 12)\nb.set_ylabel(\"Number of Embarked\", fontsize = 12)\nb.set_title(\"Number of Embarked in each area\")","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:18:28.864039Z","iopub.execute_input":"2022-07-05T11:18:28.864920Z","iopub.status.idle":"2022-07-05T11:18:28.980247Z","shell.execute_reply.started":"2022-07-05T11:18:28.864893Z","shell.execute_reply":"2022-07-05T11:18:28.979256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Relationship between features and target","metadata":{}},{"cell_type":"code","source":"aa = pd.crosstab(data[\"Survived\"],data[\"Sex\"])","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:43:59.409439Z","iopub.execute_input":"2022-07-05T11:43:59.409815Z","iopub.status.idle":"2022-07-05T11:43:59.425735Z","shell.execute_reply.started":"2022-07-05T11:43:59.409786Z","shell.execute_reply":"2022-07-05T11:43:59.424564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"aa.plot.bar(rot=0)","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:45:00.272115Z","iopub.execute_input":"2022-07-05T11:45:00.272435Z","iopub.status.idle":"2022-07-05T11:45:00.415362Z","shell.execute_reply.started":"2022-07-05T11:45:00.272412Z","shell.execute_reply":"2022-07-05T11:45:00.413655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb = pd.crosstab(data[\"Survived\"],data[\"Embarked\"])\nbb.plot.bar(rot=0)","metadata":{"execution":{"iopub.status.busy":"2022-07-05T11:54:01.560061Z","iopub.execute_input":"2022-07-05T11:54:01.560743Z","iopub.status.idle":"2022-07-05T11:54:01.743801Z","shell.execute_reply.started":"2022-07-05T11:54:01.560715Z","shell.execute_reply":"2022-07-05T11:54:01.742693Z"},"trusted":true},"execution_count":null,"outputs":[]}]}