{"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":"markdown","source":"# Data preprocessing","metadata":{"id":"zyyu5WPhiYGM"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"id":"27Q4rJMHiXOo","execution":{"iopub.status.busy":"2022-08-12T06:33:43.657082Z","iopub.execute_input":"2022-08-12T06:33:43.657599Z","iopub.status.idle":"2022-08-12T06:33:43.665490Z","shell.execute_reply.started":"2022-08-12T06:33:43.657553Z","shell.execute_reply":"2022-08-12T06:33:43.664310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/spaceship-titanic/train.csv')\ntest = pd.read_csv('../input/spaceship-titanic/test.csv')","metadata":{"id":"ALADrGt1izMI","execution":{"iopub.status.busy":"2022-08-12T06:33:43.715873Z","iopub.execute_input":"2022-08-12T06:33:43.716296Z","iopub.status.idle":"2022-08-12T06:33:43.784791Z","shell.execute_reply.started":"2022-08-12T06:33:43.716262Z","shell.execute_reply":"2022-08-12T06:33:43.783248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"id":"A7dt5Uf1i37t","execution":{"iopub.status.busy":"2022-08-12T06:33:43.788320Z","iopub.execute_input":"2022-08-12T06:33:43.788856Z","iopub.status.idle":"2022-08-12T06:33:43.815562Z","shell.execute_reply.started":"2022-08-12T06:33:43.788803Z","shell.execute_reply":"2022-08-12T06:33:43.814252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop('PassengerId', axis=1)\ntest = test.drop('PassengerId', axis=1)\n\ntrain = train.drop('Name', axis=1)\ntest = test.drop('Name', axis=1)","metadata":{"id":"yovV5g7LloTV","execution":{"iopub.status.busy":"2022-08-12T06:33:43.818036Z","iopub.execute_input":"2022-08-12T06:33:43.818884Z","iopub.status.idle":"2022-08-12T06:33:43.839369Z","shell.execute_reply.started":"2022-08-12T06:33:43.818831Z","shell.execute_reply":"2022-08-12T06:33:43.838111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.Transported.value_counts() #The target variable has no imbalance","metadata":{"id":"m1HQDzvxpYZT","outputId":"2093378d-022a-422a-bc4f-5df7a65ff95d","execution":{"iopub.status.busy":"2022-08-12T06:33:43.856693Z","iopub.execute_input":"2022-08-12T06:33:43.857606Z","iopub.status.idle":"2022-08-12T06:33:43.868336Z","shell.execute_reply.started":"2022-08-12T06:33:43.857549Z","shell.execute_reply":"2022-08-12T06:33:43.866840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Fill nan values","metadata":{"id":"Z0NgMIihkCzI"}},{"cell_type":"code","source":"train.info() #need to fillna: HomePlanet, CryoSleep, Destination, Age, VIP, RoomService, FoodCourt, ShoppingMall, Spa, VRDeck","metadata":{"id":"q5W9PQ-ji7Qt","outputId":"2e5ba1c7-b659-4570-cdac-da1a201d2f20","execution":{"iopub.status.busy":"2022-08-12T06:33:43.881938Z","iopub.execute_input":"2022-08-12T06:33:43.882381Z","iopub.status.idle":"2022-08-12T06:33:43.900544Z","shell.execute_reply.started":"2022-08-12T06:33:43.882345Z","shell.execute_reply":"2022-08-12T06:33:43.899583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"id":"13DAmHPiklcK","outputId":"377d02f4-61b2-4de1-bbc5-803455b0b4ca","execution":{"iopub.status.busy":"2022-08-12T06:33:43.907433Z","iopub.execute_input":"2022-08-12T06:33:43.908074Z","iopub.status.idle":"2022-08-12T06:33:43.921832Z","shell.execute_reply.started":"2022-08-12T06:33:43.908037Z","shell.execute_reply":"2022-08-12T06:33:43.920751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *Cabin*","metadata":{"id":"QGFpOvrs5-_r"}},{"cell_type":"code","source":"s = train['Cabin'].str.split('/')\ndeck = []\nside = []\nnumb = []\nfor i in s.values:\n  if type(i) == float: \n    deck.append(np.nan)\n    side.append(np.nan)\n    numb.append(np.nan)\n  else:\n    deck.append(i[0])\n    side.append(i[2])\n    numb.append(i[1])\ntrain['Deck'] = deck\ntrain['Side'] = side\ntrain['Numb'] = numb\ntrain = train.drop('Cabin', axis=1)\n\ns = test['Cabin'].str.split('/')\ndeck = []\nside = []\nnumb = []\nfor i in s.values:\n  if type(i) == float: \n    deck.append(np.nan)\n    side.append(np.nan)\n    numb.append(np.nan)\n  else:\n    deck.append(i[0])\n    side.append(i[2])\n    numb.append(i[1])\ntest['Deck'] = deck\ntest['Side'] = side\ntest['Numb'] = numb\ntest = test.drop('Cabin', axis=1)","metadata":{"id":"taW9rsxw4MDU","execution":{"iopub.status.busy":"2022-08-12T06:33:43.965884Z","iopub.execute_input":"2022-08-12T06:33:43.966776Z","iopub.status.idle":"2022-08-12T06:33:44.019224Z","shell.execute_reply.started":"2022-08-12T06:33:43.966722Z","shell.execute_reply":"2022-08-12T06:33:44.017555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.Deck.value_counts()","metadata":{"id":"6-sEU7YK58wH","outputId":"35f2e330-5994-457d-a5a3-b79d28d46551","execution":{"iopub.status.busy":"2022-08-12T06:33:44.025158Z","iopub.execute_input":"2022-08-12T06:33:44.025617Z","iopub.status.idle":"2022-08-12T06:33:44.038683Z","shell.execute_reply.started":"2022-08-12T06:33:44.025581Z","shell.execute_reply":"2022-08-12T06:33:44.036953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.Deck.value_counts()","metadata":{"id":"z9vT4AHS6I6U","outputId":"f6d46afa-db25-4e13-e237-ad24f9688c4e","execution":{"iopub.status.busy":"2022-08-12T06:33:44.045272Z","iopub.execute_input":"2022-08-12T06:33:44.045776Z","iopub.status.idle":"2022-08-12T06:33:44.059780Z","shell.execute_reply.started":"2022-08-12T06:33:44.045730Z","shell.execute_reply":"2022-08-12T06:33:44.058254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Deck'] = train.Deck.fillna('F')\ntest['Deck'] = test.Deck.fillna('F')","metadata":{"id":"GsISH6U96MJj","execution":{"iopub.status.busy":"2022-08-12T06:33:44.069118Z","iopub.execute_input":"2022-08-12T06:33:44.069652Z","iopub.status.idle":"2022-08-12T06:33:44.082002Z","shell.execute_reply.started":"2022-08-12T06:33:44.069607Z","shell.execute_reply":"2022-08-12T06:33:44.079958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.Side.value_counts()","metadata":{"id":"fScfph0r6QuL","outputId":"114402fd-8560-46a3-8557-4bb65a008efc","execution":{"iopub.status.busy":"2022-08-12T06:33:44.085380Z","iopub.execute_input":"2022-08-12T06:33:44.085958Z","iopub.status.idle":"2022-08-12T06:33:44.101419Z","shell.execute_reply.started":"2022-08-12T06:33:44.085909Z","shell.execute_reply":"2022-08-12T06:33:44.099506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.Side.value_counts()","metadata":{"id":"UstG8U1B6S1h","outputId":"f1a276a3-1021-4a1a-c727-dd3dcb073e68","execution":{"iopub.status.busy":"2022-08-12T06:33:44.103934Z","iopub.execute_input":"2022-08-12T06:33:44.104680Z","iopub.status.idle":"2022-08-12T06:33:44.119633Z","shell.execute_reply.started":"2022-08-12T06:33:44.104640Z","shell.execute_reply":"2022-08-12T06:33:44.118374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Side'] = train.Side.fillna('S')\ntest['Side'] = test.Side.fillna('S')","metadata":{"id":"IvWNMLk-6XJ8","execution":{"iopub.status.busy":"2022-08-12T06:33:44.123851Z","iopub.execute_input":"2022-08-12T06:33:44.124324Z","iopub.status.idle":"2022-08-12T06:33:44.137562Z","shell.execute_reply.started":"2022-08-12T06:33:44.124257Z","shell.execute_reply":"2022-08-12T06:33:44.135707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.Numb.value_counts()","metadata":{"id":"ydqH0x1bEGik","outputId":"5ed6e116-bf20-414a-b707-f54ec29ba459","execution":{"iopub.status.busy":"2022-08-12T06:33:44.161025Z","iopub.execute_input":"2022-08-12T06:33:44.162386Z","iopub.status.idle":"2022-08-12T06:33:44.180404Z","shell.execute_reply.started":"2022-08-12T06:33:44.162295Z","shell.execute_reply":"2022-08-12T06:33:44.178600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.Numb.value_counts()","metadata":{"id":"FoYU14b-EMJU","outputId":"b62c69df-1f72-49b7-a9b3-b13da2e98897","execution":{"iopub.status.busy":"2022-08-12T06:33:44.205026Z","iopub.execute_input":"2022-08-12T06:33:44.206622Z","iopub.status.idle":"2022-08-12T06:33:44.224545Z","shell.execute_reply.started":"2022-08-12T06:33:44.206541Z","shell.execute_reply":"2022-08-12T06:33:44.223225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Numb'] = train.Numb.fillna(28)\ntest['Numb'] = test.Numb.fillna(21)","metadata":{"id":"VhfYU2qyEJz_","execution":{"iopub.status.busy":"2022-08-12T06:33:44.227916Z","iopub.execute_input":"2022-08-12T06:33:44.228371Z","iopub.status.idle":"2022-08-12T06:33:44.239340Z","shell.execute_reply.started":"2022-08-12T06:33:44.228332Z","shell.execute_reply":"2022-08-12T06:33:44.237470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Numb'] = np.array(train.Numb.values, dtype=int)\ntest['Numb'] = np.array(test.Numb.values, dtype=int)","metadata":{"id":"vj1A0jOIWO6Y","execution":{"iopub.status.busy":"2022-08-12T06:33:44.256566Z","iopub.execute_input":"2022-08-12T06:33:44.257030Z","iopub.status.idle":"2022-08-12T06:33:44.269002Z","shell.execute_reply.started":"2022-08-12T06:33:44.256993Z","shell.execute_reply":"2022-08-12T06:33:44.267200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *HomePlanet*","metadata":{"id":"MixHXLHAkhHJ"}},{"cell_type":"code","source":"print(train.HomePlanet.value_counts(), '\\n')\nprint(test.HomePlanet.value_counts())","metadata":{"id":"sBNCIi6UjNsV","outputId":"fe8153e4-ec49-425f-d852-870b399086b5","execution":{"iopub.status.busy":"2022-08-12T06:33:44.290231Z","iopub.execute_input":"2022-08-12T06:33:44.291408Z","iopub.status.idle":"2022-08-12T06:33:44.305167Z","shell.execute_reply.started":"2022-08-12T06:33:44.291350Z","shell.execute_reply":"2022-08-12T06:33:44.303230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['HomePlanet'] = train.HomePlanet.fillna('Earth')\ntest['HomePlanet'] = test.HomePlanet.fillna('Earth')","metadata":{"id":"Oon0gUehkjhb","execution":{"iopub.status.busy":"2022-08-12T06:33:44.316007Z","iopub.execute_input":"2022-08-12T06:33:44.316498Z","iopub.status.idle":"2022-08-12T06:33:44.326728Z","shell.execute_reply.started":"2022-08-12T06:33:44.316460Z","shell.execute_reply":"2022-08-12T06:33:44.324945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *CryoSleep*","metadata":{"id":"uLzJuou9lH4P"}},{"cell_type":"code","source":"print(train.CryoSleep.value_counts(), '\\n')\nprint(test.CryoSleep.value_counts())","metadata":{"id":"ENOxgqVSlN61","outputId":"1b5e9c2f-896f-447d-d770-699dc6d0d567","execution":{"iopub.status.busy":"2022-08-12T06:33:44.354234Z","iopub.execute_input":"2022-08-12T06:33:44.354703Z","iopub.status.idle":"2022-08-12T06:33:44.364860Z","shell.execute_reply.started":"2022-08-12T06:33:44.354663Z","shell.execute_reply":"2022-08-12T06:33:44.363619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['CryoSleep'] = train.CryoSleep.fillna(False)\ntest['CryoSleep'] = test.CryoSleep.fillna(False)","metadata":{"id":"338xVbQZlOAF","execution":{"iopub.status.busy":"2022-08-12T06:33:44.398676Z","iopub.execute_input":"2022-08-12T06:33:44.399564Z","iopub.status.idle":"2022-08-12T06:33:44.412355Z","shell.execute_reply.started":"2022-08-12T06:33:44.399522Z","shell.execute_reply":"2022-08-12T06:33:44.411248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *Destination*","metadata":{"id":"TyrE_u0XlXMu"}},{"cell_type":"code","source":"print(train.Destination.value_counts(), '\\n')\nprint(test.Destination.value_counts())","metadata":{"id":"IXw1IvuLlaHT","outputId":"d52cd4bf-376f-44a7-9884-f5f0c65acc22","execution":{"iopub.status.busy":"2022-08-12T06:33:44.420200Z","iopub.execute_input":"2022-08-12T06:33:44.420662Z","iopub.status.idle":"2022-08-12T06:33:44.432013Z","shell.execute_reply.started":"2022-08-12T06:33:44.420624Z","shell.execute_reply":"2022-08-12T06:33:44.430499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Destination'] = train.Destination.fillna('TRAPPIST-1e')\ntest['Destination'] = test.Destination.fillna('TRAPPIST-1e')","metadata":{"id":"9ijif_0HlaJl","execution":{"iopub.status.busy":"2022-08-12T06:33:44.441722Z","iopub.execute_input":"2022-08-12T06:33:44.442276Z","iopub.status.idle":"2022-08-12T06:33:44.452813Z","shell.execute_reply.started":"2022-08-12T06:33:44.442230Z","shell.execute_reply":"2022-08-12T06:33:44.451229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *Age*","metadata":{"id":"w1yZhlWmmJ0m"}},{"cell_type":"code","source":"train.Age.hist()\ntrain.Age.mode()","metadata":{"id":"58ladDr_mMZy","outputId":"ca8ba0c6-f849-4674-9cf3-f5c2ffd55f66","execution":{"iopub.status.busy":"2022-08-12T06:33:44.478927Z","iopub.execute_input":"2022-08-12T06:33:44.481595Z","iopub.status.idle":"2022-08-12T06:33:44.765566Z","shell.execute_reply.started":"2022-08-12T06:33:44.481523Z","shell.execute_reply":"2022-08-12T06:33:44.762795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.Age.hist()\ntest.Age.mode()","metadata":{"id":"CqJLs8DTmNbO","outputId":"0d63d3ab-2bdc-415d-dc97-0062619fffb8","execution":{"iopub.status.busy":"2022-08-12T06:33:44.767614Z","iopub.execute_input":"2022-08-12T06:33:44.768557Z","iopub.status.idle":"2022-08-12T06:33:44.983816Z","shell.execute_reply.started":"2022-08-12T06:33:44.768521Z","shell.execute_reply":"2022-08-12T06:33:44.981800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Age'] = train.Age.fillna(24.0)\ntest['Age'] = test.Age.fillna(18.0)","metadata":{"id":"27ipCZMkmMb-","execution":{"iopub.status.busy":"2022-08-12T06:33:44.985170Z","iopub.execute_input":"2022-08-12T06:33:44.985685Z","iopub.status.idle":"2022-08-12T06:33:44.992065Z","shell.execute_reply.started":"2022-08-12T06:33:44.985653Z","shell.execute_reply":"2022-08-12T06:33:44.990757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *VIP*","metadata":{"id":"CGGfANZzmlXn"}},{"cell_type":"code","source":"print(train.VIP.value_counts(), '\\n')\nprint(test.VIP.value_counts())","metadata":{"id":"NUC_X2Rmmopc","outputId":"0fd3cb02-dff2-4256-9e0f-756bba563063","execution":{"iopub.status.busy":"2022-08-12T06:33:44.995013Z","iopub.execute_input":"2022-08-12T06:33:44.995486Z","iopub.status.idle":"2022-08-12T06:33:45.011175Z","shell.execute_reply.started":"2022-08-12T06:33:44.995442Z","shell.execute_reply":"2022-08-12T06:33:45.009260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['VIP'] = train.VIP.fillna(False)\ntest['VIP'] = test.VIP.fillna(False)","metadata":{"id":"5JfokBk2morz","execution":{"iopub.status.busy":"2022-08-12T06:33:45.013337Z","iopub.execute_input":"2022-08-12T06:33:45.014970Z","iopub.status.idle":"2022-08-12T06:33:45.031491Z","shell.execute_reply.started":"2022-08-12T06:33:45.014918Z","shell.execute_reply":"2022-08-12T06:33:45.029392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *RoomService*","metadata":{"id":"zoqmzsOfm2zB"}},{"cell_type":"code","source":"train.RoomService.hist()\ntrain.RoomService.median()","metadata":{"id":"wZU5mOOjm5uc","outputId":"3797590b-5cd1-48f0-ddb3-1d225b88f126","execution":{"iopub.status.busy":"2022-08-12T06:33:45.033440Z","iopub.execute_input":"2022-08-12T06:33:45.033927Z","iopub.status.idle":"2022-08-12T06:33:45.269288Z","shell.execute_reply.started":"2022-08-12T06:33:45.033885Z","shell.execute_reply":"2022-08-12T06:33:45.266514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.RoomService.hist()\ntest.RoomService.median()","metadata":{"id":"BR06JSS6m5yA","outputId":"bb890059-1ede-417d-a013-62e8cd7f4ad4","execution":{"iopub.status.busy":"2022-08-12T06:33:45.270823Z","iopub.execute_input":"2022-08-12T06:33:45.271253Z","iopub.status.idle":"2022-08-12T06:33:45.513598Z","shell.execute_reply.started":"2022-08-12T06:33:45.271216Z","shell.execute_reply":"2022-08-12T06:33:45.511545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['RoomService'] = train.RoomService.fillna(0.0)\ntest['RoomService'] = test.RoomService.fillna(0.0)","metadata":{"id":"hufb8_HqnsG_","execution":{"iopub.status.busy":"2022-08-12T06:33:45.515667Z","iopub.execute_input":"2022-08-12T06:33:45.516204Z","iopub.status.idle":"2022-08-12T06:33:45.524926Z","shell.execute_reply.started":"2022-08-12T06:33:45.516153Z","shell.execute_reply":"2022-08-12T06:33:45.523444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *FoodCourt*","metadata":{"id":"E6nAULqsnzJe"}},{"cell_type":"code","source":"train.FoodCourt.hist()\ntrain.FoodCourt.median()","metadata":{"id":"pA71r0d_n2wF","outputId":"a80d28a1-d06f-4273-c45b-212afbc755d8","execution":{"iopub.status.busy":"2022-08-12T06:33:45.526957Z","iopub.execute_input":"2022-08-12T06:33:45.527750Z","iopub.status.idle":"2022-08-12T06:33:45.779175Z","shell.execute_reply.started":"2022-08-12T06:33:45.527699Z","shell.execute_reply":"2022-08-12T06:33:45.777632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.FoodCourt.hist()\ntest.FoodCourt.median()","metadata":{"id":"9WuL3d5On2yj","outputId":"96d18a2a-9c1c-4171-8b02-d8f16f41c081","execution":{"iopub.status.busy":"2022-08-12T06:33:45.784921Z","iopub.execute_input":"2022-08-12T06:33:45.785384Z","iopub.status.idle":"2022-08-12T06:33:46.036093Z","shell.execute_reply.started":"2022-08-12T06:33:45.785345Z","shell.execute_reply":"2022-08-12T06:33:46.033718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['FoodCourt'] = train.FoodCourt.fillna(0.0)\ntest['FoodCourt'] = test.FoodCourt.fillna(0.0)","metadata":{"id":"_CDFj-Pyn21H","execution":{"iopub.status.busy":"2022-08-12T06:33:46.037678Z","iopub.execute_input":"2022-08-12T06:33:46.038718Z","iopub.status.idle":"2022-08-12T06:33:46.049540Z","shell.execute_reply.started":"2022-08-12T06:33:46.038637Z","shell.execute_reply":"2022-08-12T06:33:46.048078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *ShoppingMall*","metadata":{"id":"l85X_ZRloB2W"}},{"cell_type":"code","source":"train.ShoppingMall.hist()\ntrain.ShoppingMall.median()","metadata":{"id":"qfKVcCM-oC5l","outputId":"a87b63a1-1e6b-44cc-85b2-a19bf0a447fb","execution":{"iopub.status.busy":"2022-08-12T06:33:46.051542Z","iopub.execute_input":"2022-08-12T06:33:46.052607Z","iopub.status.idle":"2022-08-12T06:33:46.297043Z","shell.execute_reply.started":"2022-08-12T06:33:46.052559Z","shell.execute_reply":"2022-08-12T06:33:46.295713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.ShoppingMall.hist()\ntest.ShoppingMall.median()","metadata":{"id":"tkZ_4jBWoC8D","outputId":"22e8490c-443c-47c1-986f-fee9cf22ceec","execution":{"iopub.status.busy":"2022-08-12T06:33:46.298804Z","iopub.execute_input":"2022-08-12T06:33:46.299749Z","iopub.status.idle":"2022-08-12T06:33:46.510811Z","shell.execute_reply.started":"2022-08-12T06:33:46.299705Z","shell.execute_reply":"2022-08-12T06:33:46.509428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['ShoppingMall'] = train.ShoppingMall.fillna(0.0)\ntest['ShoppingMall'] = test.ShoppingMall.fillna(0.0)","metadata":{"id":"OLa7ipnToC-e","execution":{"iopub.status.busy":"2022-08-12T06:33:46.512521Z","iopub.execute_input":"2022-08-12T06:33:46.513754Z","iopub.status.idle":"2022-08-12T06:33:46.521917Z","shell.execute_reply.started":"2022-08-12T06:33:46.513716Z","shell.execute_reply":"2022-08-12T06:33:46.520422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *Spa*","metadata":{"id":"c4EmAaD3oLmk"}},{"cell_type":"code","source":"train.Spa.hist()\ntrain.Spa.median()","metadata":{"id":"o9qXTa1roMfu","outputId":"450af6d4-7e73-4e51-f741-2d90b350f474","execution":{"iopub.status.busy":"2022-08-12T06:33:46.527655Z","iopub.execute_input":"2022-08-12T06:33:46.528177Z","iopub.status.idle":"2022-08-12T06:33:46.756790Z","shell.execute_reply.started":"2022-08-12T06:33:46.528111Z","shell.execute_reply":"2022-08-12T06:33:46.755532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.Spa.hist()\ntest.Spa.median()","metadata":{"id":"2ku5cUjaoMj7","outputId":"0b0b7862-3563-4119-abb9-31bf9212e4fd","execution":{"iopub.status.busy":"2022-08-12T06:33:46.758848Z","iopub.execute_input":"2022-08-12T06:33:46.759345Z","iopub.status.idle":"2022-08-12T06:33:47.282937Z","shell.execute_reply.started":"2022-08-12T06:33:46.759304Z","shell.execute_reply":"2022-08-12T06:33:47.281930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Spa'] = train.Spa.fillna(0.0)\ntest['Spa'] = test.Spa.fillna(0.0)","metadata":{"id":"eeAeWucdoMr-","execution":{"iopub.status.busy":"2022-08-12T06:33:47.284415Z","iopub.execute_input":"2022-08-12T06:33:47.285697Z","iopub.status.idle":"2022-08-12T06:33:47.294073Z","shell.execute_reply.started":"2022-08-12T06:33:47.285648Z","shell.execute_reply":"2022-08-12T06:33:47.292701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### *VRDeck*","metadata":{"id":"9rgYBpW-oVcQ"}},{"cell_type":"code","source":"train.VRDeck.hist()\ntrain.VRDeck.median()","metadata":{"id":"WSQWA2TIoWbB","outputId":"661520e5-abc3-442a-c405-db673d53d575","execution":{"iopub.status.busy":"2022-08-12T06:33:47.296160Z","iopub.execute_input":"2022-08-12T06:33:47.296619Z","iopub.status.idle":"2022-08-12T06:33:47.549222Z","shell.execute_reply.started":"2022-08-12T06:33:47.296575Z","shell.execute_reply":"2022-08-12T06:33:47.548317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.VRDeck.hist()\ntest.VRDeck.median()","metadata":{"id":"6A8HfQkloWdk","outputId":"e1668eda-cdfc-4af9-ebd9-51f9f0b34da3","execution":{"iopub.status.busy":"2022-08-12T06:33:47.550339Z","iopub.execute_input":"2022-08-12T06:33:47.551082Z","iopub.status.idle":"2022-08-12T06:33:47.767028Z","shell.execute_reply.started":"2022-08-12T06:33:47.551048Z","shell.execute_reply":"2022-08-12T06:33:47.765887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['VRDeck'] = train.VRDeck.fillna(0.0)\ntest['VRDeck'] = test.VRDeck.fillna(0.0)","metadata":{"id":"TYv8dLl6oWjK","execution":{"iopub.status.busy":"2022-08-12T06:33:47.768488Z","iopub.execute_input":"2022-08-12T06:33:47.768992Z","iopub.status.idle":"2022-08-12T06:33:47.776507Z","shell.execute_reply.started":"2022-08-12T06:33:47.768959Z","shell.execute_reply":"2022-08-12T06:33:47.775273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## *New features*","metadata":{"id":"RV7FbGBaUHBZ"}},{"cell_type":"code","source":"train['Index'] = 100\ntrain.loc[train['Age'] <= 10, 'Index'] = 1\ntrain.loc[(train['Age'] <= 20) & (train['Age'] > 10), 'Index'] = 2\ntrain.loc[(train['Age'] <= 30) & (train['Age'] > 20), 'Index'] = 3\ntrain.loc[(train['Age'] <= 40) & (train['Age'] > 30), 'Index'] = 4\ntrain.loc[(train['Age'] <= 50) & (train['Age'] > 40), 'Index'] = 5\ntrain.loc[(train['Age'] <= 60) & (train['Age'] > 50), 'Index'] = 6\ntrain.loc[(train['Age'] <= 70) & (train['Age'] > 60), 'Index'] = 7\ntrain.loc[(train['Age'] <= 80) & (train['Age'] > 70), 'Index'] = 8\n\ntest['Index'] = 100\ntest.loc[test['Age'] <= 10, 'Index'] = 1\ntest.loc[(test['Age'] <= 20) & (test['Age'] > 10), 'Index'] = 2\ntest.loc[(test['Age'] <= 30) & (test['Age'] > 20), 'Index'] = 3\ntest.loc[(test['Age'] <= 40) & (test['Age'] > 30), 'Index'] = 4\ntest.loc[(test['Age'] <= 50) & (test['Age'] > 40), 'Index'] = 5\ntest.loc[(test['Age'] <= 60) & (test['Age'] > 50), 'Index'] = 6\ntest.loc[(test['Age'] <= 70) & (test['Age'] > 60), 'Index'] = 7\ntest.loc[(test['Age'] <= 80) & (test['Age'] > 70), 'Index'] = 8","metadata":{"id":"jU5OzHPlUGPm","execution":{"iopub.status.busy":"2022-08-12T06:33:47.778437Z","iopub.execute_input":"2022-08-12T06:33:47.779278Z","iopub.status.idle":"2022-08-12T06:33:47.810474Z","shell.execute_reply.started":"2022-08-12T06:33:47.779232Z","shell.execute_reply":"2022-08-12T06:33:47.809602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Summary'] = train['RoomService'] + train['FoodCourt'] + train['ShoppingMall'] + train['Spa'] + train['VRDeck']\ntest['Summary'] = test['RoomService'] + test['FoodCourt'] + test['ShoppingMall'] + test['Spa'] + test['VRDeck']","metadata":{"id":"vk8pFV2oUJik","execution":{"iopub.status.busy":"2022-08-12T06:33:47.811897Z","iopub.execute_input":"2022-08-12T06:33:47.812769Z","iopub.status.idle":"2022-08-12T06:33:47.824770Z","shell.execute_reply.started":"2022-08-12T06:33:47.812719Z","shell.execute_reply":"2022-08-12T06:33:47.823449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## One-hot encoding","metadata":{"id":"w62vXth7oglh"}},{"cell_type":"code","source":"train.head()","metadata":{"id":"FgvOeFK0ojta","outputId":"e0e3c100-804f-4aef-a366-9183e57c55bd","execution":{"iopub.status.busy":"2022-08-12T06:33:47.826503Z","iopub.execute_input":"2022-08-12T06:33:47.827506Z","iopub.status.idle":"2022-08-12T06:33:47.856418Z","shell.execute_reply.started":"2022-08-12T06:33:47.827460Z","shell.execute_reply":"2022-08-12T06:33:47.855211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def encode_and_bind(original_dataframe, feature_to_encode):\n    dummies = pd.get_dummies(original_dataframe[[feature_to_encode]])\n    res = pd.concat([original_dataframe, dummies], axis=1)\n    return(res)","metadata":{"id":"wwwdD_Mvow2Y","execution":{"iopub.status.busy":"2022-08-12T06:33:47.858505Z","iopub.execute_input":"2022-08-12T06:33:47.859093Z","iopub.status.idle":"2022-08-12T06:33:47.866691Z","shell.execute_reply.started":"2022-08-12T06:33:47.859043Z","shell.execute_reply":"2022-08-12T06:33:47.865627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for feature in ['HomePlanet', 'Destination', 'Deck', 'Side']:\n  train = encode_and_bind(train, feature).drop(feature, axis=1)\n  test = encode_and_bind(test, feature).drop(feature, axis=1)","metadata":{"id":"VUgYDOrBow-Z","execution":{"iopub.status.busy":"2022-08-12T06:33:47.868696Z","iopub.execute_input":"2022-08-12T06:33:47.870943Z","iopub.status.idle":"2022-08-12T06:33:47.947767Z","shell.execute_reply.started":"2022-08-12T06:33:47.870883Z","shell.execute_reply":"2022-08-12T06:33:47.946248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns","metadata":{"id":"3JsQadyUpA43","outputId":"0251b401-edc8-4209-f00d-6cda8afe684a","execution":{"iopub.status.busy":"2022-08-12T06:33:47.949689Z","iopub.execute_input":"2022-08-12T06:33:47.950253Z","iopub.status.idle":"2022-08-12T06:33:47.957991Z","shell.execute_reply.started":"2022-08-12T06:33:47.950214Z","shell.execute_reply":"2022-08-12T06:33:47.957039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = train.corr()\ncorr.style.background_gradient(cmap='coolwarm')","metadata":{"id":"GoTWjAFcpGTV","outputId":"7321db1f-724d-43ee-d653-ea4af7253163","execution":{"iopub.status.busy":"2022-08-12T06:33:47.959266Z","iopub.execute_input":"2022-08-12T06:33:47.959959Z","iopub.status.idle":"2022-08-12T06:33:48.080708Z","shell.execute_reply.started":"2022-08-12T06:33:47.959922Z","shell.execute_reply":"2022-08-12T06:33:48.079306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = test.corr()\ncorr.style.background_gradient(cmap='coolwarm')","metadata":{"id":"iq9E2J25pS34","outputId":"ea52145b-378a-4c8e-e280-2e02116953e6","execution":{"iopub.status.busy":"2022-08-12T06:33:48.088977Z","iopub.execute_input":"2022-08-12T06:33:48.089499Z","iopub.status.idle":"2022-08-12T06:33:48.188170Z","shell.execute_reply.started":"2022-08-12T06:33:48.089459Z","shell.execute_reply":"2022-08-12T06:33:48.186693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## *Feature importance value*","metadata":{"id":"Id-2i_OWPIEF"}},{"cell_type":"markdown","source":"!The code below was taken from [here](https://notebooks.githubusercontent.com/view/ipynb?browser=chrome&color_mode=auto&commit=7d6e09ef2f470298832c2a16ed55701cac90c612&device=unknown&enc_url=68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f67616f78783634332f574f452d49562f376436653039656632663437303239383833326332613136656435353730316361633930633631322f574f4525323025324225323049562532302d25323043616c46756e6374696f6e732e6970796e62&logged_in=false&nwo=gaoxx643%2FWOE-IV&path=WOE+%2B+IV+-+CalFunctions.ipynb&platform=android&repository_id=158003321&repository_type=Repository&version=99)!","metadata":{"id":"YiX0yqOZRm0e"}},{"cell_type":"code","source":"#feature importance value def\nimport pandas.core.algorithms as algos\nfrom pandas import Series\nimport scipy.stats.stats as stats\nimport re\nimport traceback\nimport string\n\nmax_bin = 7\nforce_bin = 3\n\ndef mono_bin(Y, X, n = max_bin):\n    \n    df1 = pd.DataFrame({\"X\": X, \"Y\": Y})\n    justmiss = df1[['X','Y']][df1.X.isnull()]\n    notmiss = df1[['X','Y']][df1.X.notnull()]\n    r = 0\n    while np.abs(r) < 1:\n        try:\n            d1 = pd.DataFrame({\"X\": notmiss.X, \"Y\": notmiss.Y, \"Bucket\": pd.qcut(notmiss.X, n)})\n            d2 = d1.groupby('Bucket', as_index=True)\n            r, p = stats.spearmanr(d2.mean().X, d2.mean().Y)\n            n = n - 1 \n        except Exception as e:\n            n = n - 1\n\n    if len(d2) == 1:\n        n = force_bin         \n        bins = np.quantile(notmiss.X, np.linspace(0, 1, n))\n        if len(np.unique(bins)) == 2:\n            bins = np.insert(bins, 0, 1)\n            bins[1] = bins[1]-(bins[1]/2)\n        d1 = pd.DataFrame({\"X\": notmiss.X, \"Y\": notmiss.Y, \"Bucket\": pd.cut(notmiss.X, np.unique(bins),include_lowest=True)}) \n        d2 = d1.groupby('Bucket', as_index=True)\n    \n    d3 = pd.DataFrame({},index=[])\n    d3[\"MIN_VALUE\"] = d2.min().X\n    d3[\"MAX_VALUE\"] = d2.max().X\n    d3[\"COUNT\"] = d2.count().Y\n    d3[\"EVENT\"] = d2.sum().Y\n    d3[\"NONEVENT\"] = d2.count().Y - d2.sum().Y\n    d3=d3.reset_index(drop=True)\n    \n    if len(justmiss.index) > 0:\n        d4 = pd.DataFrame({'MIN_VALUE':np.nan},index=[0])\n        d4[\"MAX_VALUE\"] = np.nan\n        d4[\"COUNT\"] = justmiss.count().Y\n        d4[\"EVENT\"] = justmiss.sum().Y\n        d4[\"NONEVENT\"] = justmiss.count().Y - justmiss.sum().Y\n        d3 = d3.append(d4,ignore_index=True)\n    \n    d3[\"EVENT_RATE\"] = d3.EVENT/d3.COUNT\n    d3[\"NON_EVENT_RATE\"] = d3.NONEVENT/d3.COUNT\n    d3[\"DIST_EVENT\"] = d3.EVENT/d3.sum().EVENT\n    d3[\"DIST_NON_EVENT\"] = d3.NONEVENT/d3.sum().NONEVENT\n    d3[\"WOE\"] = np.log(d3.DIST_EVENT/d3.DIST_NON_EVENT)\n    d3[\"IV\"] = (d3.DIST_EVENT-d3.DIST_NON_EVENT)*np.log(d3.DIST_EVENT/d3.DIST_NON_EVENT)\n    d3[\"VAR_NAME\"] = \"VAR\"\n    d3 = d3[['VAR_NAME','MIN_VALUE', 'MAX_VALUE', 'COUNT', 'EVENT', 'EVENT_RATE', 'NONEVENT', 'NON_EVENT_RATE', 'DIST_EVENT','DIST_NON_EVENT','WOE', 'IV']]       \n    d3 = d3.replace([np.inf, -np.inf], 0)\n    d3.IV = d3.IV.sum()\n    \n    return(d3)\n\ndef char_bin(Y, X):\n        \n    df1 = pd.DataFrame({\"X\": X, \"Y\": Y})\n    justmiss = df1[['X','Y']][df1.X.isnull()]\n    notmiss = df1[['X','Y']][df1.X.notnull()]    \n    df2 = notmiss.groupby('X',as_index=True)\n    \n    d3 = pd.DataFrame({},index=[])\n    d3[\"COUNT\"] = df2.count().Y\n    d3[\"MIN_VALUE\"] = df2.sum().Y.index\n    d3[\"MAX_VALUE\"] = d3[\"MIN_VALUE\"]\n    d3[\"EVENT\"] = df2.sum().Y\n    d3[\"NONEVENT\"] = df2.count().Y - df2.sum().Y\n    \n    if len(justmiss.index) > 0:\n        d4 = pd.DataFrame({'MIN_VALUE':np.nan},index=[0])\n        d4[\"MAX_VALUE\"] = np.nan\n        d4[\"COUNT\"] = justmiss.count().Y\n        d4[\"EVENT\"] = justmiss.sum().Y\n        d4[\"NONEVENT\"] = justmiss.count().Y - justmiss.sum().Y\n        d3 = d3.append(d4,ignore_index=True)\n    \n    d3[\"EVENT_RATE\"] = d3.EVENT/d3.COUNT\n    d3[\"NON_EVENT_RATE\"] = d3.NONEVENT/d3.COUNT\n    d3[\"DIST_EVENT\"] = d3.EVENT/d3.sum().EVENT\n    d3[\"DIST_NON_EVENT\"] = d3.NONEVENT/d3.sum().NONEVENT\n    d3[\"WOE\"] = np.log(d3.DIST_EVENT/d3.DIST_NON_EVENT)\n    d3[\"IV\"] = (d3.DIST_EVENT-d3.DIST_NON_EVENT)*np.log(d3.DIST_EVENT/d3.DIST_NON_EVENT)\n    d3[\"VAR_NAME\"] = \"VAR\"\n    d3 = d3[['VAR_NAME','MIN_VALUE', 'MAX_VALUE', 'COUNT', 'EVENT', 'EVENT_RATE', 'NONEVENT', 'NON_EVENT_RATE', 'DIST_EVENT','DIST_NON_EVENT','WOE', 'IV']]      \n    d3 = d3.replace([np.inf, -np.inf], 0)\n    d3.IV = d3.IV.sum()\n    d3 = d3.reset_index(drop=True)\n    \n    return(d3)\n\ndef data_vars(df1, target):\n    \n    stack = traceback.extract_stack()\n    filename, lineno, function_name, code = stack[-2]\n    vars_name = re.compile(r'\\((.*?)\\).*$').search(code).groups()[0]\n    final = (re.findall(r\"[\\w']+\", vars_name))[-1]\n    \n    x = df1.dtypes.index\n    count = -1\n    \n    for i in x:\n        if i.upper() not in (final.upper()):\n            if np.issubdtype(df1[i], np.number) and len(Series.unique(df1[i])) > 2:\n                conv = mono_bin(target, df1[i])\n                conv[\"VAR_NAME\"] = i\n                count = count + 1\n            else:\n                conv = char_bin(target, df1[i])\n                conv[\"VAR_NAME\"] = i            \n                count = count + 1\n                \n            if count == 0:\n                iv_df = conv\n            else:\n                iv_df = iv_df.append(conv,ignore_index=True)\n    \n    iv = pd.DataFrame({'IV':iv_df.groupby('VAR_NAME').IV.max()})\n    iv = iv.reset_index()\n    return(iv_df,iv)","metadata":{"id":"wL2_90B2PMPx","execution":{"iopub.status.busy":"2022-08-12T06:33:48.190330Z","iopub.execute_input":"2022-08-12T06:33:48.191770Z","iopub.status.idle":"2022-08-12T06:33:48.237749Z","shell.execute_reply.started":"2022-08-12T06:33:48.191700Z","shell.execute_reply":"2022-08-12T06:33:48.236696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_iv, IV = data_vars(train, train.Transported)\nIV.sort_values(by='IV',ascending=False)","metadata":{"id":"EvNhf_ZGPOYL","outputId":"960dbaab-5551-4897-8170-5bd92f6f8a2c","execution":{"iopub.status.busy":"2022-08-12T06:33:48.239050Z","iopub.execute_input":"2022-08-12T06:33:48.239714Z","iopub.status.idle":"2022-08-12T06:33:49.184434Z","shell.execute_reply.started":"2022-08-12T06:33:48.239673Z","shell.execute_reply":"2022-08-12T06:33:49.183065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#drop Age, Destination_PSO J318.5-22, Deck_A due to low feature importance value\ntrain = train.drop('Age', axis=1)\ntest = test.drop('Age', axis=1)\n\ntrain = train.drop('Destination_PSO J318.5-22', axis=1)\ntest = test.drop('Destination_PSO J318.5-22', axis=1)\n\ntrain = train.drop('Deck_A', axis=1)\ntest = test.drop('Deck_A', axis=1)","metadata":{"id":"4zA7OHuwPQFd","execution":{"iopub.status.busy":"2022-08-12T06:33:49.186352Z","iopub.execute_input":"2022-08-12T06:33:49.186744Z","iopub.status.idle":"2022-08-12T06:33:49.202479Z","shell.execute_reply.started":"2022-08-12T06:33:49.186709Z","shell.execute_reply":"2022-08-12T06:33:49.201077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# *CatBoost*","metadata":{"id":"BPcwBiD49Noa"}},{"cell_type":"code","source":"!pip install catboost","metadata":{"id":"ULfe8vv69M73","execution":{"iopub.status.busy":"2022-08-12T06:33:49.204873Z","iopub.execute_input":"2022-08-12T06:33:49.205502Z","iopub.status.idle":"2022-08-12T06:34:00.363109Z","shell.execute_reply.started":"2022-08-12T06:33:49.205462Z","shell.execute_reply":"2022-08-12T06:34:00.361608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(train.drop('Transported', axis=1), train.Transported, random_state = 42, test_size = 0.3)","metadata":{"id":"9Odes6b9_ipV","execution":{"iopub.status.busy":"2022-08-12T06:34:00.364797Z","iopub.execute_input":"2022-08-12T06:34:00.366047Z","iopub.status.idle":"2022-08-12T06:34:00.383281Z","shell.execute_reply.started":"2022-08-12T06:34:00.365994Z","shell.execute_reply":"2022-08-12T06:34:00.381776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from catboost import CatBoostClassifier","metadata":{"id":"lgWBaiEe9Z5b","execution":{"iopub.status.busy":"2022-08-12T06:34:00.385055Z","iopub.execute_input":"2022-08-12T06:34:00.388530Z","iopub.status.idle":"2022-08-12T06:34:00.394407Z","shell.execute_reply.started":"2022-08-12T06:34:00.388473Z","shell.execute_reply":"2022-08-12T06:34:00.392595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cbc = CatBoostClassifier(verbose=0, n_estimators=5000)","metadata":{"id":"5E10oXob9bzb","execution":{"iopub.status.busy":"2022-08-12T06:34:00.395883Z","iopub.execute_input":"2022-08-12T06:34:00.396324Z","iopub.status.idle":"2022-08-12T06:34:00.407446Z","shell.execute_reply.started":"2022-08-12T06:34:00.396289Z","shell.execute_reply":"2022-08-12T06:34:00.406154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cbc.fit(X_train, y_train)","metadata":{"id":"nzV0TvK_9dU1","execution":{"iopub.status.busy":"2022-08-12T06:34:00.410218Z","iopub.execute_input":"2022-08-12T06:34:00.411343Z","iopub.status.idle":"2022-08-12T06:34:11.335839Z","shell.execute_reply.started":"2022-08-12T06:34:00.411295Z","shell.execute_reply":"2022-08-12T06:34:11.334322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = cbc.predict(X_test)\npred[pred == 'False'] = False\npred[pred == 'True'] = True\npred = np.array(pred, dtype=bool)\naccuracy_score(y_test, pred)","metadata":{"id":"JCgOCVqw9etS","execution":{"iopub.status.busy":"2022-08-12T06:34:11.337569Z","iopub.execute_input":"2022-08-12T06:34:11.338624Z","iopub.status.idle":"2022-08-12T06:34:11.362017Z","shell.execute_reply.started":"2022-08-12T06:34:11.338588Z","shell.execute_reply":"2022-08-12T06:34:11.360461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = cbc.predict(test)\nsubmission[submission == 'False'] = False\nsubmission[submission == 'True'] = True\nsubmission = np.array(submission, dtype=bool)\nsubmission_df = pd.DataFrame(pd.read_csv('../input/spaceship-titanic/test.csv')['PassengerId'], columns=['PassengerId'])\nsubmission_df['Transported'] = submission\nsubmission_df.head()","metadata":{"id":"DQJ0I1w4-ud6","outputId":"5a7df37d-a65a-42f8-ee14-0e1a8ffe3fb3","execution":{"iopub.status.busy":"2022-08-12T06:34:11.364085Z","iopub.execute_input":"2022-08-12T06:34:11.365390Z","iopub.status.idle":"2022-08-12T06:34:11.419469Z","shell.execute_reply.started":"2022-08-12T06:34:11.365326Z","shell.execute_reply":"2022-08-12T06:34:11.418285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('submission.csv', index=False)","metadata":{"id":"PC_HrV2Y-4e9","execution":{"iopub.status.busy":"2022-08-12T06:34:11.421085Z","iopub.execute_input":"2022-08-12T06:34:11.421531Z","iopub.status.idle":"2022-08-12T06:34:11.438438Z","shell.execute_reply.started":"2022-08-12T06:34:11.421489Z","shell.execute_reply":"2022-08-12T06:34:11.436940Z"},"trusted":true},"execution_count":null,"outputs":[]}]}