{"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 seaborn as sns\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:49:28.146686Z","iopub.execute_input":"2022-07-20T05:49:28.147391Z","iopub.status.idle":"2022-07-20T05:49:29.311254Z","shell.execute_reply.started":"2022-07-20T05:49:28.147301Z","shell.execute_reply":"2022-07-20T05:49:29.310305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nsns.set_context('poster')\nsns.set_palette('viridis')\nsns.set(rc = {'figure.figsize':(15,8)})","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:49:55.304008Z","iopub.execute_input":"2022-07-20T05:49:55.304379Z","iopub.status.idle":"2022-07-20T05:49:55.314899Z","shell.execute_reply.started":"2022-07-20T05:49:55.304348Z","shell.execute_reply":"2022-07-20T05:49:55.313712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:49:58.525294Z","iopub.execute_input":"2022-07-20T05:49:58.525692Z","iopub.status.idle":"2022-07-20T05:49:58.560532Z","shell.execute_reply.started":"2022-07-20T05:49:58.525656Z","shell.execute_reply":"2022-07-20T05:49:58.559673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Importing train data","metadata":{}},{"cell_type":"code","source":"titanic_train=pd.read_csv('../input/titanic/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:09.454140Z","iopub.execute_input":"2022-07-20T05:50:09.455854Z","iopub.status.idle":"2022-07-20T05:50:09.474041Z","shell.execute_reply.started":"2022-07-20T05:50:09.455808Z","shell.execute_reply":"2022-07-20T05:50:09.473067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_train.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:13.746116Z","iopub.execute_input":"2022-07-20T05:50:13.747182Z","iopub.status.idle":"2022-07-20T05:50:13.774118Z","shell.execute_reply.started":"2022-07-20T05:50:13.747130Z","shell.execute_reply":"2022-07-20T05:50:13.772969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_train.info()","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:50:15.064692Z","iopub.execute_input":"2022-07-20T05:50:15.065090Z","iopub.status.idle":"2022-07-20T05:50:15.089860Z","shell.execute_reply.started":"2022-07-20T05:50:15.065056Z","shell.execute_reply":"2022-07-20T05:50:15.088770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Heatmap before fixing missing values","metadata":{}},{"cell_type":"code","source":"sns.heatmap(titanic_train.isnull(),yticklabels=False,cbar=False)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:50:17.376844Z","iopub.execute_input":"2022-07-20T05:50:17.377224Z","iopub.status.idle":"2022-07-20T05:50:17.645530Z","shell.execute_reply.started":"2022-07-20T05:50:17.377193Z","shell.execute_reply":"2022-07-20T05:50:17.644399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = titanic_train.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:18.557227Z","iopub.execute_input":"2022-07-20T05:50:18.557653Z","iopub.status.idle":"2022-07-20T05:50:18.562654Z","shell.execute_reply.started":"2022-07-20T05:50:18.557608Z","shell.execute_reply":"2022-07-20T05:50:18.561664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since there are many missing values from cabin , it is better to drop it","metadata":{}},{"cell_type":"code","source":"train_data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:23.086078Z","iopub.execute_input":"2022-07-20T05:50:23.086706Z","iopub.status.idle":"2022-07-20T05:50:23.093975Z","shell.execute_reply.started":"2022-07-20T05:50:23.086657Z","shell.execute_reply":"2022-07-20T05:50:23.092878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.drop('Cabin',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:23.873254Z","iopub.execute_input":"2022-07-20T05:50:23.873778Z","iopub.status.idle":"2022-07-20T05:50:23.883831Z","shell.execute_reply.started":"2022-07-20T05:50:23.873725Z","shell.execute_reply":"2022-07-20T05:50:23.882302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def impute_age(col):\n    Age=col[0]\n    Pclass=col[1]\n    Sex=col[2]\n    if pd.isnull(Age):\n        if Pclass==1:\n            if Sex=='male':\n                return 41\n            else:\n                return 40\n        elif Pclass==2:\n            if Sex=='male':\n                return 31\n            else:\n                return 24\n        else:\n            if Sex=='male':\n                return 25\n            else:\n                return 23\n    else:\n        return Age  ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:57.075437Z","iopub.execute_input":"2022-07-20T05:50:57.075912Z","iopub.status.idle":"2022-07-20T05:50:57.084703Z","shell.execute_reply.started":"2022-07-20T05:50:57.075873Z","shell.execute_reply":"2022-07-20T05:50:57.083443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['Age'] = train_data[['Age','Pclass','Sex']].apply(impute_age,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:58.771612Z","iopub.execute_input":"2022-07-20T05:50:58.772107Z","iopub.status.idle":"2022-07-20T05:50:58.798561Z","shell.execute_reply.started":"2022-07-20T05:50:58.772065Z","shell.execute_reply":"2022-07-20T05:50:58.796976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['Embarked'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:00.733571Z","iopub.execute_input":"2022-07-20T05:51:00.734062Z","iopub.status.idle":"2022-07-20T05:51:00.744206Z","shell.execute_reply.started":"2022-07-20T05:51:00.734024Z","shell.execute_reply":"2022-07-20T05:51:00.742868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:07.725271Z","iopub.execute_input":"2022-07-20T05:51:07.726143Z","iopub.status.idle":"2022-07-20T05:51:07.735280Z","shell.execute_reply.started":"2022-07-20T05:51:07.726097Z","shell.execute_reply":"2022-07-20T05:51:07.733870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:08.360820Z","iopub.execute_input":"2022-07-20T05:51:08.362133Z","iopub.status.idle":"2022-07-20T05:51:08.379573Z","shell.execute_reply.started":"2022-07-20T05:51:08.362068Z","shell.execute_reply":"2022-07-20T05:51:08.377878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Heatmap after fixing missing values ","metadata":{}},{"cell_type":"code","source":"sns.heatmap(train_data.isnull(),yticklabels=False,cbar=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:11.714272Z","iopub.execute_input":"2022-07-20T05:51:11.714747Z","iopub.status.idle":"2022-07-20T05:51:11.948077Z","shell.execute_reply.started":"2022-07-20T05:51:11.714712Z","shell.execute_reply":"2022-07-20T05:51:11.947170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA - Train dataset ","metadata":{}},{"cell_type":"code","source":"train_data.groupby('Survived')['Sex'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:21.552776Z","iopub.execute_input":"2022-07-20T05:51:21.553242Z","iopub.status.idle":"2022-07-20T05:51:21.567532Z","shell.execute_reply.started":"2022-07-20T05:51:21.553206Z","shell.execute_reply":"2022-07-20T05:51:21.566294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"g = sns.catplot(x=\"Pclass\", hue=\"Sex\", col=\"Survived\",\n                data=train_data, kind=\"count\",palette='seismic')\n","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:51:22.569497Z","iopub.execute_input":"2022-07-20T05:51:22.570733Z","iopub.status.idle":"2022-07-20T05:51:23.222375Z","shell.execute_reply.started":"2022-07-20T05:51:22.570673Z","shell.execute_reply":"2022-07-20T05:51:23.220924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For Not Survived : More Males than females\n\nFor Survived : More Female than males","metadata":{}},{"cell_type":"code","source":"sns.histplot(\n    train_data,\n    x=\"Age\", hue=\"Sex\",\n    multiple=\"stack\",\n    palette=\"light:m_r\",\n    edgecolor=\".3\",\n    linewidth=.5,\n    log_scale=False,\n)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:28.344029Z","iopub.execute_input":"2022-07-20T05:51:28.345125Z","iopub.status.idle":"2022-07-20T05:51:28.799649Z","shell.execute_reply.started":"2022-07-20T05:51:28.345070Z","shell.execute_reply":"2022-07-20T05:51:28.798693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Passengers who were travelling mostly their age was between 20 to 40","metadata":{}},{"cell_type":"code","source":"a = train_data.groupby('SibSp')['Survived'].value_counts()\ntotal = train_data['SibSp'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:31.699160Z","iopub.execute_input":"2022-07-20T05:51:31.699554Z","iopub.status.idle":"2022-07-20T05:51:31.707165Z","shell.execute_reply.started":"2022-07-20T05:51:31.699509Z","shell.execute_reply":"2022-07-20T05:51:31.706313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SibSp_total = pd.crosstab(train_data['SibSp'],train_data['Survived']).join(total,on='SibSp',how='inner').rename(columns={0:'Not Survived',1:'Survived','SibSp':'Total'})","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:33.481355Z","iopub.execute_input":"2022-07-20T05:51:33.482076Z","iopub.status.idle":"2022-07-20T05:51:33.515667Z","shell.execute_reply.started":"2022-07-20T05:51:33.482038Z","shell.execute_reply":"2022-07-20T05:51:33.514705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SibSp_total['Not Survived percent']= round(SibSp_total['Not Survived']/SibSp_total['Total'],2)\nSibSp_total['Survived percent']= round(SibSp_total['Survived']/SibSp_total['Total'],2)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:36.112142Z","iopub.execute_input":"2022-07-20T05:51:36.112596Z","iopub.status.idle":"2022-07-20T05:51:36.121392Z","shell.execute_reply.started":"2022-07-20T05:51:36.112557Z","shell.execute_reply":"2022-07-20T05:51:36.120231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(SibSp_total)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:51:38.988307Z","iopub.execute_input":"2022-07-20T05:51:38.989748Z","iopub.status.idle":"2022-07-20T05:51:39.001189Z","shell.execute_reply.started":"2022-07-20T05:51:38.989695Z","shell.execute_reply":"2022-07-20T05:51:38.999823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SibSp_total['Survived percent'].plot()\nSibSp_total['Not Survived percent'].plot()\nplt.legend(['Survived', 'Not Survived'], bbox_to_anchor=(1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:41.494902Z","iopub.execute_input":"2022-07-20T05:51:41.495889Z","iopub.status.idle":"2022-07-20T05:51:41.831715Z","shell.execute_reply.started":"2022-07-20T05:51:41.495845Z","shell.execute_reply":"2022-07-20T05:51:41.830532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Observation : only Passenger with 1 Sibling/Spouse  has More Survival rate than not survival rate ","metadata":{}},{"cell_type":"code","source":"plt.subplot(1,2,2)\nsns.countplot('SibSp',data=train_data,hue='Survived')\nplt.subplot(1,2,1)\nsns.countplot('SibSp',data=train_data)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:51:45.080903Z","iopub.execute_input":"2022-07-20T05:51:45.081378Z","iopub.status.idle":"2022-07-20T05:51:45.530302Z","shell.execute_reply.started":"2022-07-20T05:51:45.081336Z","shell.execute_reply":"2022-07-20T05:51:45.529179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Most of the passenger boarded were single or had a spouse or sibling \n\n#### Passengers who survived were mostly single or had one spouse or siblings","metadata":{}},{"cell_type":"code","source":"plt.subplot(1,2,2)\nsns.countplot('Parch',data=train_data,hue='Survived')\nplt.subplot(1,2,1)\nsns.countplot('Parch',data=train_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:51:50.015832Z","iopub.execute_input":"2022-07-20T05:51:50.016290Z","iopub.status.idle":"2022-07-20T05:51:50.450456Z","shell.execute_reply.started":"2022-07-20T05:51:50.016254Z","shell.execute_reply":"2022-07-20T05:51:50.449211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Prefernce were given to the parents or parents with childen compared to bachelor","metadata":{}},{"cell_type":"markdown","source":"### Importing Test data","metadata":{}},{"cell_type":"code","source":"titanic_test = pd.read_csv(\"../input/titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:04.809150Z","iopub.execute_input":"2022-07-20T05:52:04.809638Z","iopub.status.idle":"2022-07-20T05:52:04.826287Z","shell.execute_reply.started":"2022-07-20T05:52:04.809597Z","shell.execute_reply":"2022-07-20T05:52:04.824775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_test.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:07.372917Z","iopub.execute_input":"2022-07-20T05:52:07.374201Z","iopub.status.idle":"2022-07-20T05:52:07.392180Z","shell.execute_reply.started":"2022-07-20T05:52:07.374148Z","shell.execute_reply":"2022-07-20T05:52:07.390953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_test.info()","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:52:07.932217Z","iopub.execute_input":"2022-07-20T05:52:07.933055Z","iopub.status.idle":"2022-07-20T05:52:07.949696Z","shell.execute_reply.started":"2022-07-20T05:52:07.933001Z","shell.execute_reply":"2022-07-20T05:52:07.948593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,7))\nsns.set_context('poster')\nsns.heatmap(titanic_test.isnull(),yticklabels=False,cbar=False,cmap='coolwarm')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:09.151493Z","iopub.execute_input":"2022-07-20T05:52:09.152272Z","iopub.status.idle":"2022-07-20T05:52:09.376845Z","shell.execute_reply.started":"2022-07-20T05:52:09.152212Z","shell.execute_reply":"2022-07-20T05:52:09.375840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:09.886937Z","iopub.execute_input":"2022-07-20T05:52:09.887699Z","iopub.status.idle":"2022-07-20T05:52:09.899138Z","shell.execute_reply.started":"2022-07-20T05:52:09.887659Z","shell.execute_reply":"2022-07-20T05:52:09.898045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Treating missing values from fare , Cabin and Age ","metadata":{}},{"cell_type":"code","source":"titanic_test['Fare'].fillna(titanic_test['Fare'].mean(),inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:28.301433Z","iopub.execute_input":"2022-07-20T05:52:28.301854Z","iopub.status.idle":"2022-07-20T05:52:28.307393Z","shell.execute_reply.started":"2022-07-20T05:52:28.301821Z","shell.execute_reply":"2022-07-20T05:52:28.306578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since there was only one missing value, it wa replaced with the mean of the fare variable","metadata":{}},{"cell_type":"code","source":"round(titanic_test.groupby(by=['Pclass','Sex'],axis=0)['Age'].mean(),0)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:29.943480Z","iopub.execute_input":"2022-07-20T05:52:29.944318Z","iopub.status.idle":"2022-07-20T05:52:29.958843Z","shell.execute_reply.started":"2022-07-20T05:52:29.944279Z","shell.execute_reply":"2022-07-20T05:52:29.957742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_test['Age'] = titanic_test[['Age','Pclass','Sex']].apply(impute_age,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:43.379379Z","iopub.execute_input":"2022-07-20T05:52:43.379771Z","iopub.status.idle":"2022-07-20T05:52:43.397603Z","shell.execute_reply.started":"2022-07-20T05:52:43.379741Z","shell.execute_reply":"2022-07-20T05:52:43.396480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"the missing value of age is replaced with mean age of Pclass gender wise ","metadata":{}},{"cell_type":"code","source":"titanic_test.drop('Cabin',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:52:46.715728Z","iopub.execute_input":"2022-07-20T05:52:46.716089Z","iopub.status.idle":"2022-07-20T05:52:46.723402Z","shell.execute_reply.started":"2022-07-20T05:52:46.716058Z","shell.execute_reply":"2022-07-20T05:52:46.722057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since there were too many missing data from Cabin it was dropped from the dataset ","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12,7))\nsns.set_context('poster')\nsns.heatmap(titanic_test.isnull(),yticklabels=False,cbar=False,cmap='coolwarm')","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:53:03.956502Z","iopub.execute_input":"2022-07-20T05:53:03.956998Z","iopub.status.idle":"2022-07-20T05:53:04.193769Z","shell.execute_reply.started":"2022-07-20T05:53:03.956958Z","shell.execute_reply":"2022-07-20T05:53:04.192731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"###  target acheived : NO Missing value in the train , test  dataset and EDA ḍone ","metadata":{}},{"cell_type":"markdown","source":"### Data Preprocessing ","metadata":{}},{"cell_type":"code","source":"train = train_data.copy()\ntrain.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:09.843472Z","iopub.execute_input":"2022-07-20T05:53:09.843964Z","iopub.status.idle":"2022-07-20T05:53:09.852076Z","shell.execute_reply.started":"2022-07-20T05:53:09.843927Z","shell.execute_reply":"2022-07-20T05:53:09.851038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(['PassengerId','Name','Ticket'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:11.732900Z","iopub.execute_input":"2022-07-20T05:53:11.733293Z","iopub.status.idle":"2022-07-20T05:53:11.741141Z","shell.execute_reply.started":"2022-07-20T05:53:11.733262Z","shell.execute_reply":"2022-07-20T05:53:11.739728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:14.532453Z","iopub.execute_input":"2022-07-20T05:53:14.532854Z","iopub.status.idle":"2022-07-20T05:53:14.547491Z","shell.execute_reply.started":"2022-07-20T05:53:14.532820Z","shell.execute_reply":"2022-07-20T05:53:14.546672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.plot.box(figsize=(12,8))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:16.504291Z","iopub.execute_input":"2022-07-20T05:53:16.504735Z","iopub.status.idle":"2022-07-20T05:53:16.786658Z","shell.execute_reply.started":"2022-07-20T05:53:16.504699Z","shell.execute_reply":"2022-07-20T05:53:16.785528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Fare'].plot.box(figsize=(12,8))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:17.569448Z","iopub.execute_input":"2022-07-20T05:53:17.569859Z","iopub.status.idle":"2022-07-20T05:53:17.714905Z","shell.execute_reply.started":"2022-07-20T05:53:17.569822Z","shell.execute_reply":"2022-07-20T05:53:17.713382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train['Pclass'].value_counts())\ntrain.groupby('Pclass')['Fare'].max()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:21.612931Z","iopub.execute_input":"2022-07-20T05:53:21.613857Z","iopub.status.idle":"2022-07-20T05:53:21.627565Z","shell.execute_reply.started":"2022-07-20T05:53:21.613815Z","shell.execute_reply":"2022-07-20T05:53:21.626443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[['Fare','Age']].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:23.735493Z","iopub.execute_input":"2022-07-20T05:53:23.736347Z","iopub.status.idle":"2022-07-20T05:53:23.754755Z","shell.execute_reply.started":"2022-07-20T05:53:23.736307Z","shell.execute_reply":"2022-07-20T05:53:23.753833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:26.443206Z","iopub.execute_input":"2022-07-20T05:53:26.443738Z","iopub.status.idle":"2022-07-20T05:53:26.450812Z","shell.execute_reply.started":"2022-07-20T05:53:26.443690Z","shell.execute_reply":"2022-07-20T05:53:26.449940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dummy variable for Sex , Embarked\ntrain['Sex'] = pd.get_dummies(train['Sex'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:28.586131Z","iopub.execute_input":"2022-07-20T05:53:28.586488Z","iopub.status.idle":"2022-07-20T05:53:28.594625Z","shell.execute_reply.started":"2022-07-20T05:53:28.586458Z","shell.execute_reply":"2022-07-20T05:53:28.593314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[['Embarked_Q','Embarked_S']] = pd.get_dummies(train['Embarked'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:30.646145Z","iopub.execute_input":"2022-07-20T05:53:30.646497Z","iopub.status.idle":"2022-07-20T05:53:30.656336Z","shell.execute_reply.started":"2022-07-20T05:53:30.646466Z","shell.execute_reply":"2022-07-20T05:53:30.655424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.reindex(sorted(train.columns), axis=1)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:53:32.596143Z","iopub.execute_input":"2022-07-20T05:53:32.596559Z","iopub.status.idle":"2022-07-20T05:53:32.604945Z","shell.execute_reply.started":"2022-07-20T05:53:32.596523Z","shell.execute_reply":"2022-07-20T05:53:32.603708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('Embarked',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:34.389816Z","iopub.execute_input":"2022-07-20T05:53:34.390225Z","iopub.status.idle":"2022-07-20T05:53:34.398971Z","shell.execute_reply.started":"2022-07-20T05:53:34.390191Z","shell.execute_reply":"2022-07-20T05:53:34.397673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:36.666217Z","iopub.execute_input":"2022-07-20T05:53:36.666734Z","iopub.status.idle":"2022-07-20T05:53:36.683457Z","shell.execute_reply.started":"2022-07-20T05:53:36.666692Z","shell.execute_reply":"2022-07-20T05:53:36.682141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Titanic Test ","metadata":{}},{"cell_type":"code","source":"test=titanic_test.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:40.982758Z","iopub.execute_input":"2022-07-20T05:53:40.983237Z","iopub.status.idle":"2022-07-20T05:53:40.989554Z","shell.execute_reply.started":"2022-07-20T05:53:40.983200Z","shell.execute_reply":"2022-07-20T05:53:40.987998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.drop(['PassengerId','Name','Ticket'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:41.829886Z","iopub.execute_input":"2022-07-20T05:53:41.830265Z","iopub.status.idle":"2022-07-20T05:53:41.837887Z","shell.execute_reply.started":"2022-07-20T05:53:41.830236Z","shell.execute_reply":"2022-07-20T05:53:41.836299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head(3)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:53:42.898987Z","iopub.execute_input":"2022-07-20T05:53:42.899832Z","iopub.status.idle":"2022-07-20T05:53:42.913194Z","shell.execute_reply.started":"2022-07-20T05:53:42.899799Z","shell.execute_reply":"2022-07-20T05:53:42.912102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test[['Embarked_Q','Embarked_S']] = pd.get_dummies(test['Embarked'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:43.759054Z","iopub.execute_input":"2022-07-20T05:53:43.760195Z","iopub.status.idle":"2022-07-20T05:53:43.905545Z","shell.execute_reply.started":"2022-07-20T05:53:43.760143Z","shell.execute_reply":"2022-07-20T05:53:43.904549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Sex'] = pd.get_dummies(test['Sex'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:44.586600Z","iopub.execute_input":"2022-07-20T05:53:44.587019Z","iopub.status.idle":"2022-07-20T05:53:44.593467Z","shell.execute_reply.started":"2022-07-20T05:53:44.586981Z","shell.execute_reply":"2022-07-20T05:53:44.592733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.drop('Embarked',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:45.342463Z","iopub.execute_input":"2022-07-20T05:53:45.343356Z","iopub.status.idle":"2022-07-20T05:53:45.350575Z","shell.execute_reply.started":"2022-07-20T05:53:45.343312Z","shell.execute_reply":"2022-07-20T05:53:45.349294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Embarked_Q']=train['Embarked_Q'].astype('float64')\ntrain['Embarked_S']=train['Embarked_S'].astype('float64')\ntrain['Sex']=train['Sex'].astype('float64')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:46.161821Z","iopub.execute_input":"2022-07-20T05:53:46.162669Z","iopub.status.idle":"2022-07-20T05:53:46.170525Z","shell.execute_reply.started":"2022-07-20T05:53:46.162634Z","shell.execute_reply":"2022-07-20T05:53:46.169749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"scrolled":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Embarked_Q']=test['Embarked_Q'].astype('int64')\ntest['Embarked_S']=test['Embarked_S'].astype('int64')\ntest['Sex']=test['Sex'].astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:49.405650Z","iopub.execute_input":"2022-07-20T05:53:49.406357Z","iopub.status.idle":"2022-07-20T05:53:49.414084Z","shell.execute_reply.started":"2022-07-20T05:53:49.406317Z","shell.execute_reply":"2022-07-20T05:53:49.412932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.reindex(sorted(test.columns), axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:53:50.263116Z","iopub.execute_input":"2022-07-20T05:53:50.264065Z","iopub.status.idle":"2022-07-20T05:53:50.270212Z","shell.execute_reply.started":"2022-07-20T05:53:50.264013Z","shell.execute_reply":"2022-07-20T05:53:50.269364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:24.426242Z","iopub.execute_input":"2022-07-20T05:54:24.426658Z","iopub.status.idle":"2022-07-20T05:54:24.441430Z","shell.execute_reply.started":"2022-07-20T05:54:24.426624Z","shell.execute_reply":"2022-07-20T05:54:24.440074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Modelling","metadata":{}},{"cell_type":"code","source":"X=train.iloc[:,:-1]\nprint(X.head(4))\ny= train['Survived']\nprint(y.head(4))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:28.390088Z","iopub.execute_input":"2022-07-20T05:54:28.390879Z","iopub.status.idle":"2022-07-20T05:54:28.405839Z","shell.execute_reply.started":"2022-07-20T05:54:28.390830Z","shell.execute_reply":"2022-07-20T05:54:28.404812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:31.148736Z","iopub.execute_input":"2022-07-20T05:54:31.149419Z","iopub.status.idle":"2022-07-20T05:54:31.239000Z","shell.execute_reply.started":"2022-07-20T05:54:31.149372Z","shell.execute_reply":"2022-07-20T05:54:31.237788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"split_ = train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:32.830170Z","iopub.execute_input":"2022-07-20T05:54:32.832823Z","iopub.status.idle":"2022-07-20T05:54:32.837146Z","shell.execute_reply.started":"2022-07-20T05:54:32.832774Z","shell.execute_reply":"2022-07-20T05:54:32.835978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_test,y_train,y_test = split_(X,y,test_size=0.3,random_state=101)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:34.587349Z","iopub.execute_input":"2022-07-20T05:54:34.587717Z","iopub.status.idle":"2022-07-20T05:54:34.596734Z","shell.execute_reply.started":"2022-07-20T05:54:34.587687Z","shell.execute_reply":"2022-07-20T05:54:34.595597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"x_train\\n\",x_train.shape)\nprint(\"x_test\\n\",x_test.shape)\nprint(\"y_train\\n\",y_train.shape)\nprint(\"y_test\\n\",x_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:36.350238Z","iopub.execute_input":"2022-07-20T05:54:36.350679Z","iopub.status.idle":"2022-07-20T05:54:36.358210Z","shell.execute_reply.started":"2022-07-20T05:54:36.350636Z","shell.execute_reply":"2022-07-20T05:54:36.356916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:38.455442Z","iopub.execute_input":"2022-07-20T05:54:38.455864Z","iopub.status.idle":"2022-07-20T05:54:38.530681Z","shell.execute_reply.started":"2022-07-20T05:54:38.455830Z","shell.execute_reply":"2022-07-20T05:54:38.529737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logmodel = LogisticRegression()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:39.971381Z","iopub.execute_input":"2022-07-20T05:54:39.971753Z","iopub.status.idle":"2022-07-20T05:54:39.976912Z","shell.execute_reply.started":"2022-07-20T05:54:39.971722Z","shell.execute_reply":"2022-07-20T05:54:39.975500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test = logmodel.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:41.878504Z","iopub.execute_input":"2022-07-20T05:54:41.879384Z","iopub.status.idle":"2022-07-20T05:54:41.921633Z","shell.execute_reply.started":"2022-07-20T05:54:41.879343Z","shell.execute_reply":"2022-07-20T05:54:41.920609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_ = logmodel.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:46.202311Z","iopub.execute_input":"2022-07-20T05:54:46.203009Z","iopub.status.idle":"2022-07-20T05:54:46.210066Z","shell.execute_reply.started":"2022-07-20T05:54:46.202968Z","shell.execute_reply":"2022-07-20T05:54:46.209040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report,confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:49.092630Z","iopub.execute_input":"2022-07-20T05:54:49.093040Z","iopub.status.idle":"2022-07-20T05:54:49.097583Z","shell.execute_reply.started":"2022-07-20T05:54:49.093003Z","shell.execute_reply":"2022-07-20T05:54:49.096591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cr = classification_report","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:51.301297Z","iopub.execute_input":"2022-07-20T05:54:51.302331Z","iopub.status.idle":"2022-07-20T05:54:51.307790Z","shell.execute_reply.started":"2022-07-20T05:54:51.302254Z","shell.execute_reply":"2022-07-20T05:54:51.306336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm = confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:53.099700Z","iopub.execute_input":"2022-07-20T05:54:53.100655Z","iopub.status.idle":"2022-07-20T05:54:53.107503Z","shell.execute_reply.started":"2022-07-20T05:54:53.100596Z","shell.execute_reply":"2022-07-20T05:54:53.105995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(cr(y_test,predict_))","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:54:54.934473Z","iopub.execute_input":"2022-07-20T05:54:54.934951Z","iopub.status.idle":"2022-07-20T05:54:54.947625Z","shell.execute_reply.started":"2022-07-20T05:54:54.934915Z","shell.execute_reply":"2022-07-20T05:54:54.946352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test = logmodel.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:54:58.237614Z","iopub.execute_input":"2022-07-20T05:54:58.238035Z","iopub.status.idle":"2022-07-20T05:54:58.245367Z","shell.execute_reply.started":"2022-07-20T05:54:58.238003Z","shell.execute_reply":"2022-07-20T05:54:58.244499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"The shape of pred_test\\t\",pred_test.shape,\"\\n\")\nprint(\"The shape of PassengerID\",titanic_test['PassengerId'].shape,\"\\n\")\n","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-20T05:55:00.924613Z","iopub.execute_input":"2022-07-20T05:55:00.925927Z","iopub.status.idle":"2022-07-20T05:55:00.934791Z","shell.execute_reply.started":"2022-07-20T05:55:00.925862Z","shell.execute_reply":"2022-07-20T05:55:00.933248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:03.296117Z","iopub.execute_input":"2022-07-20T05:55:03.296704Z","iopub.status.idle":"2022-07-20T05:55:03.307658Z","shell.execute_reply.started":"2022-07-20T05:55:03.296650Z","shell.execute_reply":"2022-07-20T05:55:03.306373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"titanic_test.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:06.235339Z","iopub.execute_input":"2022-07-20T05:55:06.235826Z","iopub.status.idle":"2022-07-20T05:55:06.245499Z","shell.execute_reply.started":"2022-07-20T05:55:06.235787Z","shell.execute_reply":"2022-07-20T05:55:06.244244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final= pd.DataFrame(data =titanic_test['PassengerId']).join(pd.DataFrame(pred_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:09.867192Z","iopub.execute_input":"2022-07-20T05:55:09.868099Z","iopub.status.idle":"2022-07-20T05:55:09.876583Z","shell.execute_reply.started":"2022-07-20T05:55:09.868047Z","shell.execute_reply":"2022-07-20T05:55:09.874770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:12.137474Z","iopub.execute_input":"2022-07-20T05:55:12.137935Z","iopub.status.idle":"2022-07-20T05:55:12.148383Z","shell.execute_reply.started":"2022-07-20T05:55:12.137901Z","shell.execute_reply":"2022-07-20T05:55:12.147572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:15.010162Z","iopub.execute_input":"2022-07-20T05:55:15.010569Z","iopub.status.idle":"2022-07-20T05:55:15.018334Z","shell.execute_reply.started":"2022-07-20T05:55:15.010536Z","shell.execute_reply":"2022-07-20T05:55:15.017220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final.rename(columns={0:'Survived'})\nprint(dataset_final)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:16.988831Z","iopub.execute_input":"2022-07-20T05:55:16.989225Z","iopub.status.idle":"2022-07-20T05:55:17.001603Z","shell.execute_reply.started":"2022-07-20T05:55:16.989192Z","shell.execute_reply":"2022-07-20T05:55:17.000387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_file = dataset_final.to_csv(\"Titanic_by_koshal.csv\",index=False) ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:20.624146Z","iopub.execute_input":"2022-07-20T05:55:20.625268Z","iopub.status.idle":"2022-07-20T05:55:20.636824Z","shell.execute_reply.started":"2022-07-20T05:55:20.625204Z","shell.execute_reply":"2022-07-20T05:55:20.635613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_file","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:28.090238Z","iopub.execute_input":"2022-07-20T05:55:28.091029Z","iopub.status.idle":"2022-07-20T05:55:28.096856Z","shell.execute_reply.started":"2022-07-20T05:55:28.090983Z","shell.execute_reply":"2022-07-20T05:55:28.095614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Modelling 2 - Random Forest ","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:32.791054Z","iopub.execute_input":"2022-07-20T05:55:32.791547Z","iopub.status.idle":"2022-07-20T05:55:32.948857Z","shell.execute_reply.started":"2022-07-20T05:55:32.791490Z","shell.execute_reply":"2022-07-20T05:55:32.947677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_rf = RandomForestClassifier(random_state=42, n_jobs=-1, max_depth=5,n_estimators=100, oob_score=True)\n\n#%%time\nclassifier_rf.fit(X, y)\n\n# checking the oob score\nprint('checking the oob score',classifier_rf.oob_score_)\n\nrf = RandomForestClassifier(random_state=42, n_jobs=-1)\nparams = {\n    'max_depth': [2,3,5,10,20],\n    'min_samples_leaf': [5,10,20,50,100,200],\n    'n_estimators': [10,25,30,50,100,200]\n}\nfrom sklearn.model_selection import GridSearchCV\n# Instantiate the grid search model\ngrid_search = GridSearchCV(estimator=rf,\n                           param_grid=params,\n                           cv = 4,\n                           n_jobs=-1, verbose=1, scoring=\"accuracy\")\n\ngrid_search.fit(X, y)\n\nprint('Best Score',grid_search.best_score_)\n\nrf_best = grid_search.best_estimator_\nprint(rf_best)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:55:46.797835Z","iopub.execute_input":"2022-07-20T05:55:46.798797Z","iopub.status.idle":"2022-07-20T05:56:57.724234Z","shell.execute_reply.started":"2022-07-20T05:55:46.798744Z","shell.execute_reply":"2022-07-20T05:56:57.722864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classificer_rf2 = RandomForestClassifier(max_depth=2, min_samples_leaf=5, n_estimators=25,\n                       n_jobs=-1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:02.774029Z","iopub.execute_input":"2022-07-20T05:57:02.774463Z","iopub.status.idle":"2022-07-20T05:57:02.780192Z","shell.execute_reply.started":"2022-07-20T05:57:02.774420Z","shell.execute_reply":"2022-07-20T05:57:02.779394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classificer_rf2.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:04.832037Z","iopub.execute_input":"2022-07-20T05:57:04.832639Z","iopub.status.idle":"2022-07-20T05:57:04.956000Z","shell.execute_reply.started":"2022-07-20T05:57:04.832606Z","shell.execute_reply":"2022-07-20T05:57:04.954872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_test = classificer_rf2.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:06.802240Z","iopub.execute_input":"2022-07-20T05:57:06.802641Z","iopub.status.idle":"2022-07-20T05:57:06.911986Z","shell.execute_reply.started":"2022-07-20T05:57:06.802609Z","shell.execute_reply":"2022-07-20T05:57:06.911023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(cr(y_test,predict_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:08.711450Z","iopub.execute_input":"2022-07-20T05:57:08.712290Z","iopub.status.idle":"2022-07-20T05:57:08.721351Z","shell.execute_reply.started":"2022-07-20T05:57:08.712257Z","shell.execute_reply":"2022-07-20T05:57:08.720559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_test2=classificer_rf2.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:10.944403Z","iopub.execute_input":"2022-07-20T05:57:10.945371Z","iopub.status.idle":"2022-07-20T05:57:11.054169Z","shell.execute_reply.started":"2022-07-20T05:57:10.945334Z","shell.execute_reply":"2022-07-20T05:57:11.053003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final= pd.DataFrame(data =titanic_test['PassengerId']).join(pd.DataFrame(predict_test2))","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:13.097970Z","iopub.execute_input":"2022-07-20T05:57:13.098434Z","iopub.status.idle":"2022-07-20T05:57:13.108109Z","shell.execute_reply.started":"2022-07-20T05:57:13.098393Z","shell.execute_reply":"2022-07-20T05:57:13.107097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:15.201036Z","iopub.execute_input":"2022-07-20T05:57:15.201444Z","iopub.status.idle":"2022-07-20T05:57:15.213234Z","shell.execute_reply.started":"2022-07-20T05:57:15.201410Z","shell.execute_reply":"2022-07-20T05:57:15.212023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_final=dataset_final.rename(columns={0:'Survived'})\nprint(dataset_final)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:18.216326Z","iopub.execute_input":"2022-07-20T05:57:18.216751Z","iopub.status.idle":"2022-07-20T05:57:18.227126Z","shell.execute_reply.started":"2022-07-20T05:57:18.216715Z","shell.execute_reply":"2022-07-20T05:57:18.226080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_file = dataset_final.to_csv(\"RandomForest_Titanic_by_koshal.csv\",index=False) ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:21.233833Z","iopub.execute_input":"2022-07-20T05:57:21.234369Z","iopub.status.idle":"2022-07-20T05:57:21.243981Z","shell.execute_reply.started":"2022-07-20T05:57:21.234319Z","shell.execute_reply":"2022-07-20T05:57:21.242426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}