{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-17T07:06:58.825875Z","iopub.execute_input":"2022-07-17T07:06:58.826344Z","iopub.status.idle":"2022-07-17T07:06:58.836854Z","shell.execute_reply.started":"2022-07-17T07:06:58.826307Z","shell.execute_reply":"2022-07-17T07:06:58.835358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/titanic/train.csv')\ntest = pd.read_csv('../input/titanic/test.csv')\nsubmit = pd.read_csv('../input/titanic/gender_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:06:59.062820Z","iopub.execute_input":"2022-07-17T07:06:59.063700Z","iopub.status.idle":"2022-07-17T07:06:59.087504Z","shell.execute_reply.started":"2022-07-17T07:06:59.063660Z","shell.execute_reply":"2022-07-17T07:06:59.085737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:06:59.293973Z","iopub.execute_input":"2022-07-17T07:06:59.294508Z","iopub.status.idle":"2022-07-17T07:06:59.312995Z","shell.execute_reply.started":"2022-07-17T07:06:59.294464Z","shell.execute_reply":"2022-07-17T07:06:59.312029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:06:59.525419Z","iopub.execute_input":"2022-07-17T07:06:59.526570Z","iopub.status.idle":"2022-07-17T07:06:59.544603Z","shell.execute_reply.started":"2022-07-17T07:06:59.526527Z","shell.execute_reply":"2022-07-17T07:06:59.543341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:06:59.751089Z","iopub.execute_input":"2022-07-17T07:06:59.751843Z","iopub.status.idle":"2022-07-17T07:06:59.762734Z","shell.execute_reply.started":"2022-07-17T07:06:59.751775Z","shell.execute_reply":"2022-07-17T07:06:59.761783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:06:59.946986Z","iopub.execute_input":"2022-07-17T07:06:59.947438Z","iopub.status.idle":"2022-07-17T07:06:59.963726Z","shell.execute_reply.started":"2022-07-17T07:06:59.947399Z","shell.execute_reply":"2022-07-17T07:06:59.962307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:00.179819Z","iopub.execute_input":"2022-07-17T07:07:00.181408Z","iopub.status.idle":"2022-07-17T07:07:00.197684Z","shell.execute_reply.started":"2022-07-17T07:07:00.181332Z","shell.execute_reply":"2022-07-17T07:07:00.196353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = pd.DataFrame(test['PassengerId'])","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:00.342540Z","iopub.execute_input":"2022-07-17T07:07:00.342959Z","iopub.status.idle":"2022-07-17T07:07:00.348532Z","shell.execute_reply.started":"2022-07-17T07:07:00.342925Z","shell.execute_reply":"2022-07-17T07:07:00.347432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('Cabin', axis = 1, inplace = True)\ntest.drop('Cabin', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:00.541356Z","iopub.execute_input":"2022-07-17T07:07:00.542128Z","iopub.status.idle":"2022-07-17T07:07:00.549194Z","shell.execute_reply.started":"2022-07-17T07:07:00.542087Z","shell.execute_reply":"2022-07-17T07:07:00.548231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:00.702722Z","iopub.execute_input":"2022-07-17T07:07:00.703130Z","iopub.status.idle":"2022-07-17T07:07:00.708832Z","shell.execute_reply.started":"2022-07-17T07:07:00.703093Z","shell.execute_reply":"2022-07-17T07:07:00.707532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import category_encoders as ce\nencoder= ce.BaseNEncoder(cols=['Name'],return_df=True,base=10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:00.964036Z","iopub.execute_input":"2022-07-17T07:07:00.964458Z","iopub.status.idle":"2022-07-17T07:07:00.970347Z","shell.execute_reply.started":"2022-07-17T07:07:00.964420Z","shell.execute_reply":"2022-07-17T07:07:00.969075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = encoder.fit_transform(train)\ntest = encoder.fit_transform(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:01.196176Z","iopub.execute_input":"2022-07-17T07:07:01.196949Z","iopub.status.idle":"2022-07-17T07:07:01.248102Z","shell.execute_reply.started":"2022-07-17T07:07:01.196908Z","shell.execute_reply":"2022-07-17T07:07:01.247319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encode = LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:01.379687Z","iopub.execute_input":"2022-07-17T07:07:01.380510Z","iopub.status.idle":"2022-07-17T07:07:01.384434Z","shell.execute_reply.started":"2022-07-17T07:07:01.380477Z","shell.execute_reply":"2022-07-17T07:07:01.383507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Sex'] = encode.fit_transform(train['Sex'])\ntrain['Ticket'] = encode.fit_transform(train['Ticket'])\ntrain['Embarked'] = encode.fit_transform(train['Embarked'])\ntest['Sex'] = encode.fit_transform(test['Sex'])\ntest['Ticket'] = encode.fit_transform(test['Ticket'])\ntest['Embarked'] = encode.fit_transform(test['Embarked'])","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:01.581360Z","iopub.execute_input":"2022-07-17T07:07:01.581923Z","iopub.status.idle":"2022-07-17T07:07:01.594319Z","shell.execute_reply.started":"2022-07-17T07:07:01.581890Z","shell.execute_reply":"2022-07-17T07:07:01.593218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.interpolate()\ntest = test.interpolate()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:01.743878Z","iopub.execute_input":"2022-07-17T07:07:01.744943Z","iopub.status.idle":"2022-07-17T07:07:01.754318Z","shell.execute_reply.started":"2022-07-17T07:07:01.744884Z","shell.execute_reply":"2022-07-17T07:07:01.753307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:01.928578Z","iopub.execute_input":"2022-07-17T07:07:01.929000Z","iopub.status.idle":"2022-07-17T07:07:01.937756Z","shell.execute_reply.started":"2022-07-17T07:07:01.928961Z","shell.execute_reply":"2022-07-17T07:07:01.936582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (50,50))\nsns.set_theme(font_scale=3)\nsns.heatmap(train.corr(), annot = True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:02.088161Z","iopub.execute_input":"2022-07-17T07:07:02.088574Z","iopub.status.idle":"2022-07-17T07:07:03.577758Z","shell.execute_reply.started":"2022-07-17T07:07:02.088540Z","shell.execute_reply":"2022-07-17T07:07:03.576447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:03.580220Z","iopub.execute_input":"2022-07-17T07:07:03.581155Z","iopub.status.idle":"2022-07-17T07:07:03.596105Z","shell.execute_reply.started":"2022-07-17T07:07:03.581075Z","shell.execute_reply":"2022-07-17T07:07:03.595287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.set_theme(font_scale=1)\nsns.histplot(x = 'PassengerId', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:03.597571Z","iopub.execute_input":"2022-07-17T07:07:03.598168Z","iopub.status.idle":"2022-07-17T07:07:03.941632Z","shell.execute_reply.started":"2022-07-17T07:07:03.598131Z","shell.execute_reply":"2022-07-17T07:07:03.940537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('PassengerId', axis = 1, inplace = True)\ntest.drop('PassengerId', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:03.946138Z","iopub.execute_input":"2022-07-17T07:07:03.946755Z","iopub.status.idle":"2022-07-17T07:07:03.954131Z","shell.execute_reply.started":"2022-07-17T07:07:03.946705Z","shell.execute_reply":"2022-07-17T07:07:03.953271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\n#sns.pairplot(data = train, diag_kind = 'kde')\nsns.catplot(x = 'Name_0', hue = 'Survived', data = train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:03.955539Z","iopub.execute_input":"2022-07-17T07:07:03.956515Z","iopub.status.idle":"2022-07-17T07:07:04.466250Z","shell.execute_reply.started":"2022-07-17T07:07:03.956478Z","shell.execute_reply":"2022-07-17T07:07:04.465366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('Name_0', axis = 1, inplace = True)\ntest.drop('Name_0', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:04.468330Z","iopub.execute_input":"2022-07-17T07:07:04.469760Z","iopub.status.idle":"2022-07-17T07:07:04.481773Z","shell.execute_reply.started":"2022-07-17T07:07:04.469721Z","shell.execute_reply":"2022-07-17T07:07:04.475753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.catplot(x = 'Name_1', hue = 'Survived', data = train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:04.485770Z","iopub.execute_input":"2022-07-17T07:07:04.486697Z","iopub.status.idle":"2022-07-17T07:07:05.067293Z","shell.execute_reply.started":"2022-07-17T07:07:04.486649Z","shell.execute_reply":"2022-07-17T07:07:05.064148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('Name_1', axis = 1, inplace = True)\ntest.drop('Name_1', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:05.068602Z","iopub.execute_input":"2022-07-17T07:07:05.068920Z","iopub.status.idle":"2022-07-17T07:07:05.076871Z","shell.execute_reply.started":"2022-07-17T07:07:05.068889Z","shell.execute_reply":"2022-07-17T07:07:05.075522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.catplot(x = 'Name_2', hue = 'Survived', data = train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:05.078295Z","iopub.execute_input":"2022-07-17T07:07:05.079906Z","iopub.status.idle":"2022-07-17T07:07:05.619069Z","shell.execute_reply.started":"2022-07-17T07:07:05.079855Z","shell.execute_reply":"2022-07-17T07:07:05.617975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Name_2', axis = 1, inplace = True)\ntest.drop('Name_2', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:04:27.779909Z","iopub.execute_input":"2022-07-17T07:04:27.780916Z","iopub.status.idle":"2022-07-17T07:04:27.789566Z","shell.execute_reply.started":"2022-07-17T07:04:27.780872Z","shell.execute_reply":"2022-07-17T07:04:27.788075Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.catplot(x = 'Pclass', hue = 'Survived', data = train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:05.624091Z","iopub.execute_input":"2022-07-17T07:07:05.624589Z","iopub.status.idle":"2022-07-17T07:07:06.023914Z","shell.execute_reply.started":"2022-07-17T07:07:05.624539Z","shell.execute_reply":"2022-07-17T07:07:06.022563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Pclass', axis = 1, inplace = True)\ntest.drop('Pclass', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T05:58:00.295775Z","iopub.execute_input":"2022-07-17T05:58:00.296158Z","iopub.status.idle":"2022-07-17T05:58:00.303971Z","shell.execute_reply.started":"2022-07-17T05:58:00.296121Z","shell.execute_reply":"2022-07-17T05:58:00.302607Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.catplot(x = 'Sex', hue = 'Survived', data = train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:06.025870Z","iopub.execute_input":"2022-07-17T07:07:06.026360Z","iopub.status.idle":"2022-07-17T07:07:06.390801Z","shell.execute_reply.started":"2022-07-17T07:07:06.026312Z","shell.execute_reply":"2022-07-17T07:07:06.389538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Sex', axis = 1, inplace = True)\ntest.drop('Sex', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T05:58:00.659761Z","iopub.execute_input":"2022-07-17T05:58:00.660105Z","iopub.status.idle":"2022-07-17T05:58:00.667762Z","shell.execute_reply.started":"2022-07-17T05:58:00.660073Z","shell.execute_reply":"2022-07-17T05:58:00.666655Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'Age', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:06.392720Z","iopub.execute_input":"2022-07-17T07:07:06.393072Z","iopub.status.idle":"2022-07-17T07:07:06.809496Z","shell.execute_reply.started":"2022-07-17T07:07:06.393039Z","shell.execute_reply":"2022-07-17T07:07:06.808341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('Age', axis = 1, inplace = True)\ntest.drop('Age', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:06.811414Z","iopub.execute_input":"2022-07-17T07:07:06.812480Z","iopub.status.idle":"2022-07-17T07:07:06.820461Z","shell.execute_reply.started":"2022-07-17T07:07:06.812426Z","shell.execute_reply":"2022-07-17T07:07:06.819505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'SibSp', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:06.821788Z","iopub.execute_input":"2022-07-17T07:07:06.822512Z","iopub.status.idle":"2022-07-17T07:07:07.316827Z","shell.execute_reply.started":"2022-07-17T07:07:06.822468Z","shell.execute_reply":"2022-07-17T07:07:07.314703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('SibSp', axis = 1, inplace = True)\ntest.drop('SibSp', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:07.318368Z","iopub.execute_input":"2022-07-17T07:07:07.318716Z","iopub.status.idle":"2022-07-17T07:07:07.325694Z","shell.execute_reply.started":"2022-07-17T07:07:07.318684Z","shell.execute_reply":"2022-07-17T07:07:07.324550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'Parch', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:07.327583Z","iopub.execute_input":"2022-07-17T07:07:07.328028Z","iopub.status.idle":"2022-07-17T07:07:07.682562Z","shell.execute_reply.started":"2022-07-17T07:07:07.327986Z","shell.execute_reply":"2022-07-17T07:07:07.681103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Parch', axis = 1, inplace = True)\ntest.drop('Parch', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T05:50:31.437287Z","iopub.execute_input":"2022-07-17T05:50:31.437990Z","iopub.status.idle":"2022-07-17T05:50:31.445515Z","shell.execute_reply.started":"2022-07-17T05:50:31.437955Z","shell.execute_reply":"2022-07-17T05:50:31.444236Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'Ticket', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:07.684095Z","iopub.execute_input":"2022-07-17T07:07:07.685341Z","iopub.status.idle":"2022-07-17T07:07:08.047178Z","shell.execute_reply.started":"2022-07-17T07:07:07.685274Z","shell.execute_reply":"2022-07-17T07:07:08.046095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Ticket', axis = 1, inplace = True)\ntest.drop('Ticket', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T05:58:02.323373Z","iopub.execute_input":"2022-07-17T05:58:02.323702Z","iopub.status.idle":"2022-07-17T05:58:02.332031Z","shell.execute_reply.started":"2022-07-17T05:58:02.323671Z","shell.execute_reply":"2022-07-17T05:58:02.330617Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'Fare', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:08.048501Z","iopub.execute_input":"2022-07-17T07:07:08.048807Z","iopub.status.idle":"2022-07-17T07:07:08.790310Z","shell.execute_reply.started":"2022-07-17T07:07:08.048779Z","shell.execute_reply":"2022-07-17T07:07:08.789124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,7))\nsns.histplot(x = 'Embarked', hue = 'Survived', data = train)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:08.791924Z","iopub.execute_input":"2022-07-17T07:07:08.792337Z","iopub.status.idle":"2022-07-17T07:07:09.173791Z","shell.execute_reply.started":"2022-07-17T07:07:08.792299Z","shell.execute_reply":"2022-07-17T07:07:09.172357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label = pd.DataFrame(train['Survived'])\ntrain.drop('Survived', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.175386Z","iopub.execute_input":"2022-07-17T07:07:09.176463Z","iopub.status.idle":"2022-07-17T07:07:09.185795Z","shell.execute_reply.started":"2022-07-17T07:07:09.176419Z","shell.execute_reply":"2022-07-17T07:07:09.184464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train.drop('Embarked', axis = 1, inplace = True)\ntest.drop('Embarked', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T05:58:03.852116Z","iopub.execute_input":"2022-07-17T05:58:03.852462Z","iopub.status.idle":"2022-07-17T05:58:03.866624Z","shell.execute_reply.started":"2022-07-17T05:58:03.852430Z","shell.execute_reply":"2022-07-17T05:58:03.865426Z"}}},{"cell_type":"code","source":"train.info(), test.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.187339Z","iopub.execute_input":"2022-07-17T07:07:09.187821Z","iopub.status.idle":"2022-07-17T07:07:09.218616Z","shell.execute_reply.started":"2022-07-17T07:07:09.187778Z","shell.execute_reply":"2022-07-17T07:07:09.217487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t = pd.DataFrame(train['Pclass'])\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.223698Z","iopub.execute_input":"2022-07-17T07:07:09.224042Z","iopub.status.idle":"2022-07-17T07:07:09.229787Z","shell.execute_reply.started":"2022-07-17T07:07:09.224012Z","shell.execute_reply":"2022-07-17T07:07:09.228620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nscaler = MinMaxScaler(feature_range = (0,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.231459Z","iopub.execute_input":"2022-07-17T07:07:09.231870Z","iopub.status.idle":"2022-07-17T07:07:09.243777Z","shell.execute_reply.started":"2022-07-17T07:07:09.231808Z","shell.execute_reply":"2022-07-17T07:07:09.242548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = scaler.fit_transform(train)\ntest = scaler.fit_transform(test)\nlabel = np.array(label)\nlabel = scaler.fit_transform(label.reshape(-1,1))\ntrain, label","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.245113Z","iopub.execute_input":"2022-07-17T07:07:09.246060Z","iopub.status.idle":"2022-07-17T07:07:09.283191Z","shell.execute_reply.started":"2022-07-17T07:07:09.246015Z","shell.execute_reply":"2022-07-17T07:07:09.282059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfrom xgboost import XGBClassifier\nfrom sklearn.linear_model import LogisticRegression, LinearRegression\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.ensemble import VotingClassifier, AdaBoostClassifier\nfrom sklearn.svm import SVC\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.tree import DecisionTreeClassifier","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.284774Z","iopub.execute_input":"2022-07-17T07:07:09.285217Z","iopub.status.idle":"2022-07-17T07:07:09.292609Z","shell.execute_reply.started":"2022-07-17T07:07:09.285175Z","shell.execute_reply":"2022-07-17T07:07:09.291233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_valid, Y_train, Y_valid = train_test_split(train, label, test_size = 0.2, random_state = 1)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.294393Z","iopub.execute_input":"2022-07-17T07:07:09.294869Z","iopub.status.idle":"2022-07-17T07:07:09.305230Z","shell.execute_reply.started":"2022-07-17T07:07:09.294820Z","shell.execute_reply":"2022-07-17T07:07:09.304332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_1 = LogisticRegression()\nmodel_2 = XGBClassifier()\nmodel_3 = RandomForestClassifier()\nmodel_4 = SVC()\nmodel_5 = KNeighborsClassifier()\nmodel_6 = MLPClassifier()\nmodel_7 = GradientBoostingClassifier()\nmodel_8 = GaussianNB()\nmodel_9 = DecisionTreeClassifier()\nmodel_10 = AdaBoostClassifier()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.306987Z","iopub.execute_input":"2022-07-17T07:07:09.307391Z","iopub.status.idle":"2022-07-17T07:07:09.319531Z","shell.execute_reply.started":"2022-07-17T07:07:09.307350Z","shell.execute_reply":"2022-07-17T07:07:09.318286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, mean_absolute_error, mean_squared_error, precision_score, recall_score, f1_score","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.321197Z","iopub.execute_input":"2022-07-17T07:07:09.321596Z","iopub.status.idle":"2022-07-17T07:07:09.330732Z","shell.execute_reply.started":"2022-07-17T07:07:09.321562Z","shell.execute_reply":"2022-07-17T07:07:09.329476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = [model_1, model_2, model_3, model_4, model_5, model_6, model_7, model_8, model_9, model_10]\n#model = [model_1, model_2, model_3, model_4, model_6, model_7, model_8]\npred = []\nfor i in range(len(model)):\n    model[i].fit(X_train, Y_train)\n    pred.append(model[i].predict(X_valid))\n    print(accuracy_score(pred[i], Y_valid))","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:09.332628Z","iopub.execute_input":"2022-07-17T07:07:09.332997Z","iopub.status.idle":"2022-07-17T07:07:11.499271Z","shell.execute_reply.started":"2022-07-17T07:07:09.332963Z","shell.execute_reply":"2022-07-17T07:07:11.498428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_model = VotingClassifier( estimators=[ ('1',model_1), ('2', model_2), ('3', model_3),('6', model_6),('7', model_7) , ('9', model_9), ('10',model_10)], voting='hard')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:11.501051Z","iopub.execute_input":"2022-07-17T07:07:11.501649Z","iopub.status.idle":"2022-07-17T07:07:11.508788Z","shell.execute_reply.started":"2022-07-17T07:07:11.501600Z","shell.execute_reply":"2022-07-17T07:07:11.507633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"model_2.fit(train, label)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T15:29:46.211184Z","iopub.execute_input":"2022-07-16T15:29:46.211488Z","iopub.status.idle":"2022-07-16T15:29:46.567782Z","shell.execute_reply.started":"2022-07-16T15:29:46.211459Z","shell.execute_reply":"2022-07-16T15:29:46.566341Z"}}},{"cell_type":"markdown","source":"pred = model_2.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T15:29:46.570119Z","iopub.execute_input":"2022-07-16T15:29:46.570624Z","iopub.status.idle":"2022-07-16T15:29:46.579841Z","shell.execute_reply.started":"2022-07-16T15:29:46.570583Z","shell.execute_reply":"2022-07-16T15:29:46.579085Z"}}},{"cell_type":"code","source":"final_model.fit(train,label)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:11.510092Z","iopub.execute_input":"2022-07-17T07:07:11.510455Z","iopub.status.idle":"2022-07-17T07:07:13.983192Z","shell.execute_reply.started":"2022-07-17T07:07:11.510424Z","shell.execute_reply":"2022-07-17T07:07:13.981922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = final_model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:13.984824Z","iopub.execute_input":"2022-07-17T07:07:13.985326Z","iopub.status.idle":"2022-07-17T07:07:14.053592Z","shell.execute_reply.started":"2022-07-17T07:07:13.985277Z","shell.execute_reply":"2022-07-17T07:07:14.052223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"pred.astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T15:43:54.355794Z","iopub.execute_input":"2022-07-16T15:43:54.356053Z","iopub.status.idle":"2022-07-16T15:43:54.362578Z","shell.execute_reply.started":"2022-07-16T15:43:54.356027Z","shell.execute_reply":"2022-07-16T15:43:54.361732Z"}}},{"cell_type":"code","source":"df = pd.DataFrame(pred, columns = ['Survived'])\ndf = a.join(df)\ndf['Survived'] = df['Survived'].astype(int)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:14.055328Z","iopub.execute_input":"2022-07-17T07:07:14.055988Z","iopub.status.idle":"2022-07-17T07:07:14.073544Z","shell.execute_reply.started":"2022-07-17T07:07:14.055943Z","shell.execute_reply":"2022-07-17T07:07:14.072398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T07:07:14.075360Z","iopub.execute_input":"2022-07-17T07:07:14.076099Z","iopub.status.idle":"2022-07-17T07:07:14.089838Z","shell.execute_reply.started":"2022-07-17T07:07:14.076052Z","shell.execute_reply":"2022-07-17T07:07:14.088517Z"},"trusted":true},"execution_count":null,"outputs":[]}]}