{"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-24T09:47:05.064313Z","iopub.execute_input":"2022-07-24T09:47:05.064827Z","iopub.status.idle":"2022-07-24T09:47:05.073603Z","shell.execute_reply.started":"2022-07-24T09:47:05.064787Z","shell.execute_reply":"2022-07-24T09:47:05.072500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('../input/spaceship-titanic/train.csv')\ntest_data = pd.read_csv('../input/spaceship-titanic/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.158333Z","iopub.execute_input":"2022-07-24T09:47:05.158724Z","iopub.status.idle":"2022-07-24T09:47:05.215415Z","shell.execute_reply.started":"2022-07-24T09:47:05.158689Z","shell.execute_reply":"2022-07-24T09:47:05.214188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.260951Z","iopub.execute_input":"2022-07-24T09:47:05.261675Z","iopub.status.idle":"2022-07-24T09:47:05.285413Z","shell.execute_reply.started":"2022-07-24T09:47:05.261608Z","shell.execute_reply":"2022-07-24T09:47:05.284201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['Destination'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.371062Z","iopub.execute_input":"2022-07-24T09:47:05.371493Z","iopub.status.idle":"2022-07-24T09:47:05.381342Z","shell.execute_reply.started":"2022-07-24T09:47:05.371459Z","shell.execute_reply":"2022-07-24T09:47:05.380174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.size","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.458378Z","iopub.execute_input":"2022-07-24T09:47:05.459137Z","iopub.status.idle":"2022-07-24T09:47:05.466894Z","shell.execute_reply.started":"2022-07-24T09:47:05.459061Z","shell.execute_reply":"2022-07-24T09:47:05.465675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:48.871446Z","iopub.execute_input":"2022-07-23T17:28:48.872098Z","iopub.status.idle":"2022-07-23T17:28:48.893453Z","shell.execute_reply.started":"2022-07-23T17:28:48.872042Z","shell.execute_reply":"2022-07-23T17:28:48.892530Z"}}},{"cell_type":"markdown","source":"s = train_data.isnull().sum()\ns","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:48.895002Z","iopub.execute_input":"2022-07-23T17:28:48.895986Z","iopub.status.idle":"2022-07-23T17:28:48.912652Z","shell.execute_reply.started":"2022-07-23T17:28:48.895949Z","shell.execute_reply":"2022-07-23T17:28:48.911260Z"}}},{"cell_type":"markdown","source":"T = pd.DataFrame()\n\nT['0'] = test_data.Cabin.str.split('/', n=1, expand = True)[0]\nT['1'] = test_data.Cabin.str.split('/', n=2, expand = True)[1]\nT['2'] = test_data.Cabin.str.split('/', n=2, expand = True)[2]\n\nT.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:49.019739Z","iopub.execute_input":"2022-07-23T17:28:49.020147Z","iopub.status.idle":"2022-07-23T17:28:49.065020Z","shell.execute_reply.started":"2022-07-23T17:28:49.020113Z","shell.execute_reply":"2022-07-23T17:28:49.063927Z"}}},{"cell_type":"markdown","source":"T.size","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:49.177370Z","iopub.execute_input":"2022-07-23T17:28:49.177821Z","iopub.status.idle":"2022-07-23T17:28:49.185134Z","shell.execute_reply.started":"2022-07-23T17:28:49.177786Z","shell.execute_reply":"2022-07-23T17:28:49.184038Z"}}},{"cell_type":"code","source":"test_data.size","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.558295Z","iopub.execute_input":"2022-07-24T09:47:05.559484Z","iopub.status.idle":"2022-07-24T09:47:05.567582Z","shell.execute_reply.started":"2022-07-24T09:47:05.559434Z","shell.execute_reply":"2022-07-24T09:47:05.566590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"T.fillna(method = 'pad')","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:49.283860Z","iopub.execute_input":"2022-07-23T17:28:49.284457Z","iopub.status.idle":"2022-07-23T17:28:49.302107Z","shell.execute_reply.started":"2022-07-23T17:28:49.284423Z","shell.execute_reply":"2022-07-23T17:28:49.301173Z"}}},{"cell_type":"markdown","source":"T['1'] = T['1'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:49.372558Z","iopub.execute_input":"2022-07-23T17:28:49.373007Z","iopub.status.idle":"2022-07-23T17:28:49.410146Z","shell.execute_reply.started":"2022-07-23T17:28:49.372973Z","shell.execute_reply":"2022-07-23T17:28:49.408842Z"}}},{"cell_type":"markdown","source":"train_data = train_data.join(X, how = 'left')\ntest_data = test_data.join(T, how = 'left')\ntrain_data.drop('Cabin', axis = 1, inplace = True)\ntest_data.drop('Cabin', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-23T17:28:49.583147Z","iopub.execute_input":"2022-07-23T17:28:49.583814Z","iopub.status.idle":"2022-07-23T17:28:49.602397Z","shell.execute_reply.started":"2022-07-23T17:28:49.583779Z","shell.execute_reply":"2022-07-23T17:28:49.601405Z"}}},{"cell_type":"code","source":"train_data.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.650436Z","iopub.execute_input":"2022-07-24T09:47:05.651243Z","iopub.status.idle":"2022-07-24T09:47:05.675546Z","shell.execute_reply.started":"2022-07-24T09:47:05.651196Z","shell.execute_reply":"2022-07-24T09:47:05.674211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train_data.dropna(inplace = True)\nlabel = train_data['Transported']\n\na = pd.DataFrame(test_data['PassengerId'])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.738538Z","iopub.execute_input":"2022-07-24T09:47:05.738930Z","iopub.status.idle":"2022-07-24T09:47:05.746140Z","shell.execute_reply.started":"2022-07-24T09:47:05.738898Z","shell.execute_reply":"2022-07-24T09:47:05.744922Z"},"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_data, label, test_size = 0.2, random_state = 1)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.825639Z","iopub.execute_input":"2022-07-24T09:47:05.826372Z","iopub.status.idle":"2022-07-24T09:47:05.836532Z","shell.execute_reply.started":"2022-07-24T09:47:05.826318Z","shell.execute_reply":"2022-07-24T09:47:05.835653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:05.918865Z","iopub.execute_input":"2022-07-24T09:47:05.919320Z","iopub.status.idle":"2022-07-24T09:47:05.926971Z","shell.execute_reply.started":"2022-07-24T09:47:05.919285Z","shell.execute_reply":"2022-07-24T09:47:05.925791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.DataFrame()\n\nX['Cabin_0'] = X_train.Cabin.str.split('/', n=1, expand = True)[0]\nX['Cabin_1'] = X_train.Cabin.str.split('/', n=2, expand = True)[1]\nX['Cabin_2'] = X_train.Cabin.str.split('/', n=2, expand = True)[2]\n\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.010849Z","iopub.execute_input":"2022-07-24T09:47:06.011706Z","iopub.status.idle":"2022-07-24T09:47:06.073237Z","shell.execute_reply.started":"2022-07-24T09:47:06.011648Z","shell.execute_reply":"2022-07-24T09:47:06.071745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.join(X, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.091724Z","iopub.execute_input":"2022-07-24T09:47:06.092205Z","iopub.status.idle":"2022-07-24T09:47:06.103955Z","shell.execute_reply.started":"2022-07-24T09:47:06.092167Z","shell.execute_reply":"2022-07-24T09:47:06.102469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.DataFrame()\n\nX['Passenger_0'] = X_train.PassengerId.str.split('_', n=1, expand = True)[0]\nX['Passenger_1'] = X_train.PassengerId.str.split('_', n=1, expand = True)[1]\n\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.182356Z","iopub.execute_input":"2022-07-24T09:47:06.183302Z","iopub.status.idle":"2022-07-24T09:47:06.228336Z","shell.execute_reply.started":"2022-07-24T09:47:06.183260Z","shell.execute_reply":"2022-07-24T09:47:06.227270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.join(X, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.268870Z","iopub.execute_input":"2022-07-24T09:47:06.269398Z","iopub.status.idle":"2022-07-24T09:47:06.281049Z","shell.execute_reply.started":"2022-07-24T09:47:06.269357Z","shell.execute_reply":"2022-07-24T09:47:06.279530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop('Cabin', axis = 1, inplace = True)\nX_train.drop('PassengerId', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.353654Z","iopub.execute_input":"2022-07-24T09:47:06.354054Z","iopub.status.idle":"2022-07-24T09:47:06.371597Z","shell.execute_reply.started":"2022-07-24T09:47:06.354023Z","shell.execute_reply":"2022-07-24T09:47:06.370081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.467384Z","iopub.execute_input":"2022-07-24T09:47:06.467857Z","iopub.status.idle":"2022-07-24T09:47:06.495740Z","shell.execute_reply.started":"2022-07-24T09:47:06.467821Z","shell.execute_reply":"2022-07-24T09:47:06.494156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.DataFrame()\n\nX['Cabin_0'] = X_valid.Cabin.str.split('/', n=1, expand = True)[0]\nX['Cabin_1'] = X_valid.Cabin.str.split('/', n=2, expand = True)[1]\nX['Cabin_2'] = X_valid.Cabin.str.split('/', n=2, expand = True)[2]\n\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.541827Z","iopub.execute_input":"2022-07-24T09:47:06.543191Z","iopub.status.idle":"2022-07-24T09:47:06.568474Z","shell.execute_reply.started":"2022-07-24T09:47:06.543149Z","shell.execute_reply":"2022-07-24T09:47:06.567633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid = X_valid.join(X, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.628970Z","iopub.execute_input":"2022-07-24T09:47:06.630140Z","iopub.status.idle":"2022-07-24T09:47:06.640375Z","shell.execute_reply.started":"2022-07-24T09:47:06.630082Z","shell.execute_reply":"2022-07-24T09:47:06.638879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y = pd.DataFrame()\n\nY['Passenger_0'] = X_valid.PassengerId.str.split('-', n=1, expand = True)[0]\nY['Passenger_1'] = X_valid.PassengerId.str.split('_', n=1, expand = True)[1]\n\nY.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.721235Z","iopub.execute_input":"2022-07-24T09:47:06.722718Z","iopub.status.idle":"2022-07-24T09:47:06.745987Z","shell.execute_reply.started":"2022-07-24T09:47:06.722656Z","shell.execute_reply":"2022-07-24T09:47:06.744736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid = X_valid.join(Y, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.821736Z","iopub.execute_input":"2022-07-24T09:47:06.822226Z","iopub.status.idle":"2022-07-24T09:47:06.832840Z","shell.execute_reply.started":"2022-07-24T09:47:06.822188Z","shell.execute_reply":"2022-07-24T09:47:06.831304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.drop('Cabin', axis = 1, inplace = True)\nX_valid.drop('PassengerId', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:06.910010Z","iopub.execute_input":"2022-07-24T09:47:06.910919Z","iopub.status.idle":"2022-07-24T09:47:06.923613Z","shell.execute_reply.started":"2022-07-24T09:47:06.910873Z","shell.execute_reply":"2022-07-24T09:47:06.922168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.DataFrame()\n\nX['Cabin_0'] = test_data.Cabin.str.split('/', n=1, expand = True)[0]\nX['Cabin_1'] = test_data.Cabin.str.split('/', n=2, expand = True)[1]\nX['Cabin_2'] = test_data.Cabin.str.split('/', n=2, expand = True)[2]\n\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.025183Z","iopub.execute_input":"2022-07-24T09:47:07.026231Z","iopub.status.idle":"2022-07-24T09:47:07.069571Z","shell.execute_reply.started":"2022-07-24T09:47:07.026165Z","shell.execute_reply":"2022-07-24T09:47:07.067994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = test_data.join(X, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.116540Z","iopub.execute_input":"2022-07-24T09:47:07.116939Z","iopub.status.idle":"2022-07-24T09:47:07.127158Z","shell.execute_reply.started":"2022-07-24T09:47:07.116907Z","shell.execute_reply":"2022-07-24T09:47:07.125367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.DataFrame()\n\nX['Passenger_0'] = test_data.PassengerId.str.split('_', n=1, expand = True)[0]\nX['Passenger_1'] = test_data.PassengerId.str.split('_', n=1, expand = True)[1]\n\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.230776Z","iopub.execute_input":"2022-07-24T09:47:07.231506Z","iopub.status.idle":"2022-07-24T09:47:07.262071Z","shell.execute_reply.started":"2022-07-24T09:47:07.231458Z","shell.execute_reply":"2022-07-24T09:47:07.260898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = test_data.join(X, how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.376052Z","iopub.execute_input":"2022-07-24T09:47:07.377278Z","iopub.status.idle":"2022-07-24T09:47:07.386779Z","shell.execute_reply.started":"2022-07-24T09:47:07.377219Z","shell.execute_reply":"2022-07-24T09:47:07.384664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.drop('Cabin', axis = 1, inplace = True)\ntest_data.drop('PassengerId', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.524814Z","iopub.execute_input":"2022-07-24T09:47:07.525564Z","iopub.status.idle":"2022-07-24T09:47:07.537974Z","shell.execute_reply.started":"2022-07-24T09:47:07.525501Z","shell.execute_reply":"2022-07-24T09:47:07.536871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column = ['Cabin_0', 'Cabin_1', 'Cabin_2']\nfor i in column:\n    X_train[i] = X_train[i].fillna(method = 'pad')\n    X_valid[i] = X_valid[i].fillna(method = 'pad')\n    test_data[i] = test_data[i].fillna(method = 'pad')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.638764Z","iopub.execute_input":"2022-07-24T09:47:07.639570Z","iopub.status.idle":"2022-07-24T09:47:07.660289Z","shell.execute_reply.started":"2022-07-24T09:47:07.639518Z","shell.execute_reply":"2022-07-24T09:47:07.658542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column = ['Passenger_0', 'Passenger_1', 'Cabin_1']","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.724890Z","iopub.execute_input":"2022-07-24T09:47:07.725621Z","iopub.status.idle":"2022-07-24T09:47:07.731731Z","shell.execute_reply.started":"2022-07-24T09:47:07.725569Z","shell.execute_reply":"2022-07-24T09:47:07.730738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in column:\n    X_train[i] = X_train[i].astype(int)\n    X_valid[i] = X_valid[i].astype(int)\n    test_data[i] = test_data[i].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.833421Z","iopub.execute_input":"2022-07-24T09:47:07.833887Z","iopub.status.idle":"2022-07-24T09:47:07.861080Z","shell.execute_reply.started":"2022-07-24T09:47:07.833852Z","shell.execute_reply":"2022-07-24T09:47:07.859973Z"},"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)\n\n#Fit and Transform Data\nX_train = encoder.fit_transform(X_train)\nX_valid = encoder.fit_transform(X_valid)\ntest_data = encoder.fit_transform(test_data)\n\n#encoder= ce.BaseNEncoder(cols=['PassengerId'],return_df=True,base=10)\n\n#Fit and Transform Data\n#X_train = encoder.fit_transform(X_train)\n#X_valid = encoder.fit_transform(X_valid)\n#test_data = encoder.fit_transform(test_data)\n\nX_train['HomePlanet'].replace({'Europa':0, 'Earth':1, 'Mars':2}, inplace = True)\nX_train['Destination'].replace({'TRAPPIST-1e':0, 'PSO J318.5-22':1, '55 Cancri e':2}, inplace = True)\nX_valid['HomePlanet'].replace({'Europa':0, 'Earth':1, 'Mars':2}, inplace = True)\nX_valid['Destination'].replace({'TRAPPIST-1e':0, 'PSO J318.5-22':1, '55 Cancri e':2}, inplace = True)\ntest_data['HomePlanet'].replace({'Europa':0, 'Earth':1, 'Mars':2}, inplace = True)\ntest_data['Destination'].replace({'TRAPPIST-1e':0, 'PSO J318.5-22':1, '55 Cancri e':2}, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:07.942681Z","iopub.execute_input":"2022-07-24T09:47:07.943225Z","iopub.status.idle":"2022-07-24T09:47:08.168739Z","shell.execute_reply.started":"2022-07-24T09:47:07.943187Z","shell.execute_reply":"2022-07-24T09:47:08.167462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\nfeature = ['Name']\nfor i in feature:\n    X_train.drop(i, axis = 1, inplace = True)\n    X_valid.drop(i, axis = 1, inplace = True)\n    test_data.drop(i, axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:14:33.338011Z","iopub.execute_input":"2022-07-24T09:14:33.338445Z","iopub.status.idle":"2022-07-24T09:14:33.350946Z","shell.execute_reply.started":"2022-07-24T09:14:33.338412Z","shell.execute_reply":"2022-07-24T09:14:33.349805Z"}}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nlb = LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.171240Z","iopub.execute_input":"2022-07-24T09:47:08.171907Z","iopub.status.idle":"2022-07-24T09:47:08.177662Z","shell.execute_reply.started":"2022-07-24T09:47:08.171860Z","shell.execute_reply":"2022-07-24T09:47:08.176389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column = ['CryoSleep', 'VIP', 'Cabin_0', 'Cabin_2']\nfor i in column:\n    X_train[i] = lb.fit_transform(X_train[i])\n    X_valid[i] = lb.fit_transform(X_valid[i])\n    test_data[i] = lb.fit_transform(test_data[i])\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.178949Z","iopub.execute_input":"2022-07-24T09:47:08.179298Z","iopub.status.idle":"2022-07-24T09:47:08.215796Z","shell.execute_reply.started":"2022-07-24T09:47:08.179266Z","shell.execute_reply":"2022-07-24T09:47:08.213517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train['Transported'] = lb.fit_transform(X_train['Transported'])\nX_valid['Transported'] = lb.fit_transform(X_valid['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.219998Z","iopub.execute_input":"2022-07-24T09:47:08.220859Z","iopub.status.idle":"2022-07-24T09:47:08.228800Z","shell.execute_reply.started":"2022-07-24T09:47:08.220812Z","shell.execute_reply":"2022-07-24T09:47:08.227565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"lb.fit(X_train['CryoSleep'])\nX_train['CryoSleep'] = lb.transform(X_train['CryoSleep'])\nlb.fit(X_valid['CryoSleep'])\nX_valid['CryoSleep'] = lb.transform(X_valid['CryoSleep'])\nlb.fit(X_train['0'])\nX_train['0'] = lb.transform(X_train['0'])\nlb.fit(X_train['Transported'])\nX_train['Transported'] = lb.transform(X_train['Transported'])\nlb.fit(X_valid['0'])\nX_valid['0'] = lb.transform(X_valid['0'])\nlb.fit(X_valid['Transported'])\nX_valid['Transported'] = lb.transform(X_valid['Transported'])\nlb.fit(test_data['CryoSleep'])\ntest_data['CryoSleep'] = lb.transform(test_data['CryoSleep'])\nlb.fit(test_data['0'])\ntest_data['0'] = lb.transform(test_data['0'])\nlb.fit(X_train['VIP'])\nX_train['VIP'] = lb.transform(X_train['VIP'])\nlb.fit(X_valid['VIP'])\nX_valid['VIP'] = lb.transform(X_valid['VIP'])\nlb.fit(test_data['VIP'])\ntest_data['VIP'] = lb.transform(test_data['VIP'])\nlb.fit(X_train['2'])\nX_train['2'] = lb.transform(X_train['2'])\nlb.fit(X_valid['2'])\nX_valid['2'] = lb.transform(X_valid['2'])\nlb.fit(test_data['2'])\ntest_data['2'] = lb.transform(test_data['2'])\n#lb.fit(X_train['1'])\n#X_train['1'] = lb.transform(X_train['1'])\n#lb.fit(X_valid['1'])\n#X_valid['1'] = lb.transform(X_valid['1'])\n#lb.fit(test_data['1'])\n#test_data['1'] = lb.transform(test_data['1'])","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:05:16.031590Z","iopub.execute_input":"2022-07-23T18:05:16.032256Z","iopub.status.idle":"2022-07-23T18:05:16.123259Z","shell.execute_reply.started":"2022-07-23T18:05:16.032220Z","shell.execute_reply":"2022-07-23T18:05:16.120965Z"}}},{"cell_type":"code","source":"missing_val_count_by_column_train = (X_train.isnull().sum())\nprint(missing_val_count_by_column_train[missing_val_count_by_column_train > 0])\nmissing_val_count_by_column_valid = (X_valid.isnull().sum())\nprint(missing_val_count_by_column_valid[missing_val_count_by_column_valid > 0])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.310827Z","iopub.execute_input":"2022-07-24T09:47:08.312266Z","iopub.status.idle":"2022-07-24T09:47:08.328560Z","shell.execute_reply.started":"2022-07-24T09:47:08.312210Z","shell.execute_reply":"2022-07-24T09:47:08.327197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_val_count_by_column = (test_data.isnull().sum())\nprint(missing_val_count_by_column[missing_val_count_by_column > 0])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.400955Z","iopub.execute_input":"2022-07-24T09:47:08.401341Z","iopub.status.idle":"2022-07-24T09:47:08.411959Z","shell.execute_reply.started":"2022-07-24T09:47:08.401313Z","shell.execute_reply":"2022-07-24T09:47:08.410784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_names = ['HomePlanet', 'ShoppingMall', 'RoomService', 'Age', 'Destination','Spa', 'VRDeck','FoodCourt']","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.511144Z","iopub.execute_input":"2022-07-24T09:47:08.512279Z","iopub.status.idle":"2022-07-24T09:47:08.518829Z","shell.execute_reply.started":"2022-07-24T09:47:08.512228Z","shell.execute_reply":"2022-07-24T09:47:08.517484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train_data = train_data.interpolate()\ntest_data = test_data.interpolate()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T08:15:28.299113Z","iopub.execute_input":"2022-07-17T08:15:28.299676Z","iopub.status.idle":"2022-07-17T08:15:28.313504Z","shell.execute_reply.started":"2022-07-17T08:15:28.299645Z","shell.execute_reply":"2022-07-17T08:15:28.312056Z"}}},{"cell_type":"markdown","source":"x = train_data['Age'].mode()[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:14:47.502954Z","iopub.execute_input":"2022-07-17T15:14:47.503525Z","iopub.status.idle":"2022-07-17T15:14:47.509126Z","shell.execute_reply.started":"2022-07-17T15:14:47.503493Z","shell.execute_reply":"2022-07-17T15:14:47.508250Z"}}},{"cell_type":"code","source":"for i in column_names:\n    X_train[i].replace(np.NaN, X_train[i].mean(), inplace =True)\n    X_valid[i].replace(np.NaN, X_valid[i].mean(), inplace =True)\n    test_data[i].replace(np.NaN, test_data[i].mean(), inplace =True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.612093Z","iopub.execute_input":"2022-07-24T09:47:08.612816Z","iopub.status.idle":"2022-07-24T09:47:08.635146Z","shell.execute_reply.started":"2022-07-24T09:47:08.612781Z","shell.execute_reply":"2022-07-24T09:47:08.633616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\n","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.701951Z","iopub.execute_input":"2022-07-24T09:47:08.702867Z","iopub.status.idle":"2022-07-24T09:47:08.711587Z","shell.execute_reply.started":"2022-07-24T09:47:08.702820Z","shell.execute_reply":"2022-07-24T09:47:08.710684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Name_0', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:08.792598Z","iopub.execute_input":"2022-07-24T09:47:08.793346Z","iopub.status.idle":"2022-07-24T09:47:09.211910Z","shell.execute_reply.started":"2022-07-24T09:47:08.793312Z","shell.execute_reply":"2022-07-24T09:47:09.210285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop('Name_0', axis = 1, inplace = True)\nX_valid.drop('Name_0', axis = 1, inplace = True)\ntest_data.drop('Name_0', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:09.214681Z","iopub.execute_input":"2022-07-24T09:47:09.215095Z","iopub.status.idle":"2022-07-24T09:47:09.228209Z","shell.execute_reply.started":"2022-07-24T09:47:09.215059Z","shell.execute_reply":"2022-07-24T09:47:09.226891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Name_1', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:09.229795Z","iopub.execute_input":"2022-07-24T09:47:09.230277Z","iopub.status.idle":"2022-07-24T09:47:09.739848Z","shell.execute_reply.started":"2022-07-24T09:47:09.230244Z","shell.execute_reply":"2022-07-24T09:47:09.738637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Name_2', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:09.742652Z","iopub.execute_input":"2022-07-24T09:47:09.743660Z","iopub.status.idle":"2022-07-24T09:47:10.260455Z","shell.execute_reply.started":"2022-07-24T09:47:09.743616Z","shell.execute_reply":"2022-07-24T09:47:10.259450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Name_3', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:10.261735Z","iopub.execute_input":"2022-07-24T09:47:10.262956Z","iopub.status.idle":"2022-07-24T09:47:12.137804Z","shell.execute_reply.started":"2022-07-24T09:47:10.262913Z","shell.execute_reply":"2022-07-24T09:47:12.136360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Passenger_1', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:12.139795Z","iopub.execute_input":"2022-07-24T09:47:12.140184Z","iopub.status.idle":"2022-07-24T09:47:12.642832Z","shell.execute_reply.started":"2022-07-24T09:47:12.140149Z","shell.execute_reply":"2022-07-24T09:47:12.641285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"X_train.drop('Passenger_1', axis = 1, inplace = True)\nX_valid.drop('Passenger_1', axis = 1, inplace = True)\ntest_data.drop('Passenger_1', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T07:54:09.851864Z","iopub.execute_input":"2022-07-24T07:54:09.852217Z","iopub.status.idle":"2022-07-24T07:54:09.861976Z","shell.execute_reply.started":"2022-07-24T07:54:09.852186Z","shell.execute_reply":"2022-07-24T07:54:09.861093Z"}}},{"cell_type":"code","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'Passenger_0', hue = 'Transported', data = X_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:12.644568Z","iopub.execute_input":"2022-07-24T09:47:12.645183Z","iopub.status.idle":"2022-07-24T09:47:13.062189Z","shell.execute_reply.started":"2022-07-24T09:47:12.645147Z","shell.execute_reply":"2022-07-24T09:47:13.060802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"X_train.drop('Passenger_0', axis = 1, inplace = True)\nX_valid.drop('Passenger_0', axis = 1, inplace = True)\ntest_data.drop('Passenger_0', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:14:39.133335Z","iopub.execute_input":"2022-07-24T09:14:39.134630Z","iopub.status.idle":"2022-07-24T09:14:39.146817Z","shell.execute_reply.started":"2022-07-24T09:14:39.134577Z","shell.execute_reply":"2022-07-24T09:14:39.145379Z"}}},{"cell_type":"code","source":"sns.catplot(x = 'Cabin_0', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:13.064089Z","iopub.execute_input":"2022-07-24T09:47:13.064434Z","iopub.status.idle":"2022-07-24T09:47:13.572920Z","shell.execute_reply.started":"2022-07-24T09:47:13.064405Z","shell.execute_reply":"2022-07-24T09:47:13.571320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'Cabin_1', hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:13.574665Z","iopub.execute_input":"2022-07-24T09:47:13.575475Z","iopub.status.idle":"2022-07-24T09:47:14.014709Z","shell.execute_reply.started":"2022-07-24T09:47:13.575426Z","shell.execute_reply":"2022-07-24T09:47:14.013291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'Cabin_2', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:14.019358Z","iopub.execute_input":"2022-07-24T09:47:14.019793Z","iopub.status.idle":"2022-07-24T09:47:14.437585Z","shell.execute_reply.started":"2022-07-24T09:47:14.019758Z","shell.execute_reply":"2022-07-24T09:47:14.435948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'HomePlanet', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:14.441257Z","iopub.execute_input":"2022-07-24T09:47:14.441963Z","iopub.status.idle":"2022-07-24T09:47:14.911418Z","shell.execute_reply.started":"2022-07-24T09:47:14.441929Z","shell.execute_reply":"2022-07-24T09:47:14.909775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"sns.pairplot(X_train)\nsns.pairplot(X_valid)","metadata":{"execution":{"iopub.status.busy":"2022-07-23T07:56:03.142150Z","iopub.execute_input":"2022-07-23T07:56:03.145025Z","iopub.status.idle":"2022-07-23T07:56:52.671917Z","shell.execute_reply.started":"2022-07-23T07:56:03.144975Z","shell.execute_reply":"2022-07-23T07:56:52.670763Z"}}},{"cell_type":"code","source":"sns.catplot(x = 'Destination', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:14.914007Z","iopub.execute_input":"2022-07-24T09:47:14.914518Z","iopub.status.idle":"2022-07-24T09:47:15.373090Z","shell.execute_reply.started":"2022-07-24T09:47:14.914468Z","shell.execute_reply":"2022-07-24T09:47:15.371844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.catplot(x = 'VIP', hue = 'Transported', data = X_train, kind = 'count')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:15.375156Z","iopub.execute_input":"2022-07-24T09:47:15.375482Z","iopub.status.idle":"2022-07-24T09:47:15.794165Z","shell.execute_reply.started":"2022-07-24T09:47:15.375453Z","shell.execute_reply":"2022-07-24T09:47:15.792741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop('VIP', axis = 1, inplace = True)\nX_valid.drop('VIP', axis = 1, inplace = True)\ntest_data.drop('VIP', axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:15.796001Z","iopub.execute_input":"2022-07-24T09:47:15.796545Z","iopub.status.idle":"2022-07-24T09:47:15.809421Z","shell.execute_reply.started":"2022-07-24T09:47:15.796472Z","shell.execute_reply":"2022-07-24T09:47:15.808375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.relplot(x=\"Transported\", y=\"RoomService\", data=X_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:15.811279Z","iopub.execute_input":"2022-07-24T09:47:15.812557Z","iopub.status.idle":"2022-07-24T09:47:16.266993Z","shell.execute_reply.started":"2022-07-24T09:47:15.812490Z","shell.execute_reply":"2022-07-24T09:47:16.265341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'RoomService' ,hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:21:54.704882Z","iopub.execute_input":"2022-07-23T18:21:54.705315Z","iopub.status.idle":"2022-07-23T18:22:09.069658Z","shell.execute_reply.started":"2022-07-23T18:21:54.705277Z","shell.execute_reply":"2022-07-23T18:22:09.068639Z"}}},{"cell_type":"markdown","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'FoodCourt' ,hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:22:09.071139Z","iopub.execute_input":"2022-07-23T18:22:09.071493Z","iopub.status.idle":"2022-07-23T18:22:27.066479Z","shell.execute_reply.started":"2022-07-23T18:22:09.071462Z","shell.execute_reply":"2022-07-23T18:22:27.065181Z"}}},{"cell_type":"markdown","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'ShoppingMall' ,hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:22:27.068420Z","iopub.execute_input":"2022-07-23T18:22:27.069599Z","iopub.status.idle":"2022-07-23T18:23:12.510483Z","shell.execute_reply.started":"2022-07-23T18:22:27.069543Z","shell.execute_reply":"2022-07-23T18:23:12.509544Z"}}},{"cell_type":"markdown","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'Spa' ,hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:23:12.512012Z","iopub.execute_input":"2022-07-23T18:23:12.512630Z","iopub.status.idle":"2022-07-23T18:23:30.966902Z","shell.execute_reply.started":"2022-07-23T18:23:12.512591Z","shell.execute_reply":"2022-07-23T18:23:30.965603Z"}}},{"cell_type":"markdown","source":"plt.figure(figsize = (20, 7))\nsns.histplot(x = 'VRDeck' ,hue = 'Transported', data = X_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-23T18:23:30.968569Z","iopub.execute_input":"2022-07-23T18:23:30.968953Z","iopub.status.idle":"2022-07-23T18:23:54.901696Z","shell.execute_reply.started":"2022-07-23T18:23:30.968918Z","shell.execute_reply":"2022-07-23T18:23:54.900413Z"}}},{"cell_type":"markdown","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-07-14T07:33:51.139334Z","iopub.execute_input":"2022-07-14T07:33:51.139882Z","iopub.status.idle":"2022-07-14T07:33:51.315934Z","shell.execute_reply.started":"2022-07-14T07:33:51.139853Z","shell.execute_reply":"2022-07-14T07:33:51.314643Z"}}},{"cell_type":"code","source":"X_train.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:16.269480Z","iopub.execute_input":"2022-07-24T09:47:16.269929Z","iopub.status.idle":"2022-07-24T09:47:16.296852Z","shell.execute_reply.started":"2022-07-24T09:47:16.269885Z","shell.execute_reply":"2022-07-24T09:47:16.295429Z"},"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-24T09:47:16.298787Z","iopub.execute_input":"2022-07-24T09:47:16.299348Z","iopub.status.idle":"2022-07-24T09:47:16.307926Z","shell.execute_reply.started":"2022-07-24T09:47:16.299310Z","shell.execute_reply":"2022-07-24T09:47:16.306288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (70,70))\nsns.set_theme(font_scale = 1)\nsns.heatmap(X_train.corr(), annot = True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:16.309449Z","iopub.execute_input":"2022-07-24T09:47:16.309884Z","iopub.status.idle":"2022-07-24T09:47:18.828015Z","shell.execute_reply.started":"2022-07-24T09:47:16.309849Z","shell.execute_reply":"2022-07-24T09:47:18.825982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"column = ['PassengerId_0','PassengerId_1','VIP', 'PassengerId_2', 'Cabin', 'Age', 'FoodCourt', 'ShoppingMall', 'Name_0', 'Name_1', 'Name_2', 'Name_3']\nfor i in column:\n    train_data.drop([i], axis = 1, inplace = True)\n    test_data.drop([i], axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T08:10:44.232897Z","iopub.execute_input":"2022-07-17T08:10:44.233172Z","iopub.status.idle":"2022-07-17T08:10:44.258905Z","shell.execute_reply.started":"2022-07-17T08:10:44.233144Z","shell.execute_reply":"2022-07-17T08:10:44.257503Z"}}},{"cell_type":"code","source":"X_train.drop(['Transported'], axis = 1, inplace = True)\nX_valid.drop(['Transported'], axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:18.830774Z","iopub.execute_input":"2022-07-24T09:47:18.831468Z","iopub.status.idle":"2022-07-24T09:47:18.843287Z","shell.execute_reply.started":"2022-07-24T09:47:18.831416Z","shell.execute_reply":"2022-07-24T09:47:18.841472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"column = ['PassengerId_0', 'PassengerId_1','PassengerId_2', 'PassengerId_3','VIP','Name_0', 'Name_1', 'Name_2','Name_3'] \nfor i in column: \n    train_data.drop([i], axis = 1, inplace = True) \n    test_data.drop([i], axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:14:51.847395Z","iopub.execute_input":"2022-07-17T15:14:51.847866Z","iopub.status.idle":"2022-07-17T15:14:51.871402Z","shell.execute_reply.started":"2022-07-17T15:14:51.847829Z","shell.execute_reply":"2022-07-17T15:14:51.870524Z"}}},{"cell_type":"code","source":"X_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:18.844640Z","iopub.execute_input":"2022-07-24T09:47:18.844989Z","iopub.status.idle":"2022-07-24T09:47:18.865880Z","shell.execute_reply.started":"2022-07-24T09:47:18.844958Z","shell.execute_reply":"2022-07-24T09:47:18.864411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"from sklearn import feature_selection","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:14:51.888522Z","iopub.execute_input":"2022-07-17T15:14:51.889016Z","iopub.status.idle":"2022-07-17T15:14:51.894762Z","shell.execute_reply.started":"2022-07-17T15:14:51.888971Z","shell.execute_reply":"2022-07-17T15:14:51.893581Z"}}},{"cell_type":"markdown","source":"for col in train_data.columns:\n    le = LabelEncoder()\n    train_data[col] = le.fit_transform(train_data[col])","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:00:42.196219Z","iopub.execute_input":"2022-07-17T15:00:42.196642Z","iopub.status.idle":"2022-07-17T15:00:42.224730Z","shell.execute_reply.started":"2022-07-17T15:00:42.196600Z","shell.execute_reply":"2022-07-17T15:00:42.223379Z"}}},{"cell_type":"markdown","source":"chi2, pval = feature_selection.chi2(train_data.drop('Transported', axis = 1), train_data.Transported )\nchi2","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:00:42.226062Z","iopub.execute_input":"2022-07-17T15:00:42.227024Z","iopub.status.idle":"2022-07-17T15:00:42.243984Z","shell.execute_reply.started":"2022-07-17T15:00:42.226972Z","shell.execute_reply":"2022-07-17T15:00:42.242451Z"}}},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nscaler = MinMaxScaler(feature_range = (0,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:18.868217Z","iopub.execute_input":"2022-07-24T09:47:18.869078Z","iopub.status.idle":"2022-07-24T09:47:18.875868Z","shell.execute_reply.started":"2022-07-24T09:47:18.869023Z","shell.execute_reply":"2022-07-24T09:47:18.874201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = scaler.fit_transform(X_train)\nX_valid = scaler.fit_transform(X_valid)\ntest = scaler.fit_transform(test_data)\nlabel = np.array(label)\nlabel = scaler.fit_transform(label.reshape(-1,1))\n#Y_valid = scaler.fit_transform(label.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:18.878066Z","iopub.execute_input":"2022-07-24T09:47:18.878996Z","iopub.status.idle":"2022-07-24T09:47:18.903501Z","shell.execute_reply.started":"2022-07-24T09:47:18.878941Z","shell.execute_reply":"2022-07-24T09:47:18.902090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"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-24T09:47:18.905438Z","iopub.execute_input":"2022-07-24T09:47:18.905799Z","iopub.status.idle":"2022-07-24T09:47:18.913767Z","shell.execute_reply.started":"2022-07-24T09:47:18.905766Z","shell.execute_reply":"2022-07-24T09:47:18.911946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_1 = LogisticRegression()\nmodel_2 = XGBClassifier(n_estimators = 100, random_state = 0)\nmodel_3 = RandomForestClassifier(n_estimators = 500, random_state = 0)\nmodel_4 = SVC(kernel = 'poly')\nmodel_5 = KNeighborsClassifier()\nmodel_6 = MLPClassifier(hidden_layer_sizes=(150,), learning_rate='adaptive', max_iter = 200, validation_fraction=0.10, learning_rate_init = 0.001)\nmodel_7 = GradientBoostingClassifier(n_estimators = 125, random_state = 0)\nmodel_8 = GaussianNB()\nmodel_9 = DecisionTreeClassifier()\nmodel_10 = AdaBoostClassifier(n_estimators = 50, random_state = 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:18.915660Z","iopub.execute_input":"2022-07-24T09:47:18.916639Z","iopub.status.idle":"2022-07-24T09:47:18.928147Z","shell.execute_reply.started":"2022-07-24T09:47:18.916557Z","shell.execute_reply":"2022-07-24T09:47:18.926818Z"},"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-24T09:47:18.930179Z","iopub.execute_input":"2022-07-24T09:47:18.931542Z","iopub.status.idle":"2022-07-24T09:47:18.941020Z","shell.execute_reply.started":"2022-07-24T09:47:18.931491Z","shell.execute_reply":"2022-07-24T09:47:18.939678Z"},"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-24T09:47:18.943453Z","iopub.execute_input":"2022-07-24T09:47:18.943989Z","iopub.status.idle":"2022-07-24T09:47:48.817647Z","shell.execute_reply.started":"2022-07-24T09:47:18.943940Z","shell.execute_reply":"2022-07-24T09:47:48.816258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"from sklearn.model_selection import cross_val_score","metadata":{"execution":{"iopub.status.busy":"2022-07-22T17:40:37.814656Z","iopub.execute_input":"2022-07-22T17:40:37.815598Z","iopub.status.idle":"2022-07-22T17:40:37.820754Z","shell.execute_reply.started":"2022-07-22T17:40:37.815557Z","shell.execute_reply":"2022-07-22T17:40:37.819500Z"}}},{"cell_type":"markdown","source":"def get_score(n):\n    model = MLPClassifier(hidden_layer_sizes=(150,), learning_rate='adaptive', max_iter = 200, validation_fraction=0.10, learning_rate_init = n)\n    model.fit(X_train, Y_train)\n    pred = model.predict(X_valid)\n    score = accuracy_score(Y_valid, pred)\n    return score","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:44:18.217277Z","iopub.execute_input":"2022-07-24T09:44:18.217771Z","iopub.status.idle":"2022-07-24T09:44:18.229364Z","shell.execute_reply.started":"2022-07-24T09:44:18.217733Z","shell.execute_reply":"2022-07-24T09:44:18.227717Z"}}},{"cell_type":"markdown","source":"results = {}\n\nfor i in [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400]:\n    results[i] = get_score(i)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:36:19.164376Z","iopub.execute_input":"2022-07-24T09:36:19.164900Z","iopub.status.idle":"2022-07-24T09:41:52.817413Z","shell.execute_reply.started":"2022-07-24T09:36:19.164821Z","shell.execute_reply":"2022-07-24T09:41:52.815942Z"}}},{"cell_type":"markdown","source":"results = {}\nfor i in [.1, .11, .12, .13, .14, .15, .16, .17]:\n    results[i] = get_score(i)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T08:47:14.886206Z","iopub.execute_input":"2022-07-24T08:47:14.886572Z","iopub.status.idle":"2022-07-24T08:49:25.052144Z","shell.execute_reply.started":"2022-07-24T08:47:14.886543Z","shell.execute_reply":"2022-07-24T08:49:25.050738Z"}}},{"cell_type":"markdown","source":"results = {}\nfor i in [.001, .002, .003, .004]:\n    results[i] = get_score(i)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:44:23.216618Z","iopub.execute_input":"2022-07-24T09:44:23.217053Z","iopub.status.idle":"2022-07-24T09:45:30.887129Z","shell.execute_reply.started":"2022-07-24T09:44:23.217020Z","shell.execute_reply":"2022-07-24T09:45:30.885634Z"}}},{"cell_type":"markdown","source":"for i in ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed']:\n    print(get_score(i))","metadata":{"execution":{"iopub.status.busy":"2022-07-23T13:48:26.286334Z","iopub.execute_input":"2022-07-23T13:48:26.286810Z","iopub.status.idle":"2022-07-23T13:48:35.947369Z","shell.execute_reply.started":"2022-07-23T13:48:26.286766Z","shell.execute_reply":"2022-07-23T13:48:35.944870Z"}}},{"cell_type":"markdown","source":"import matplotlib.pyplot as plt\n%matplotlib inline\n\nplt.plot(list(results.keys()), list(results.values()))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:45:30.890084Z","iopub.execute_input":"2022-07-24T09:45:30.891024Z","iopub.status.idle":"2022-07-24T09:45:31.141384Z","shell.execute_reply.started":"2022-07-24T09:45:30.890946Z","shell.execute_reply":"2022-07-24T09:45:31.140002Z"}}},{"cell_type":"markdown","source":"add = 0\nfor i in pred:\n    add = add + i\npred = add/len(model)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T07:22:00.985757Z","iopub.execute_input":"2022-07-14T07:22:00.986109Z","iopub.status.idle":"2022-07-14T07:22:00.991143Z","shell.execute_reply.started":"2022-07-14T07:22:00.986074Z","shell.execute_reply":"2022-07-14T07:22:00.990111Z"}}},{"cell_type":"code","source":"final_model = VotingClassifier( estimators=[('rf', model_3),('XGB', model_2), ('gb', model_7), ('nn', model_6), ('ada', model_10)], voting='hard')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:48.819829Z","iopub.execute_input":"2022-07-24T09:47:48.820774Z","iopub.status.idle":"2022-07-24T09:47:48.828532Z","shell.execute_reply.started":"2022-07-24T09:47:48.820722Z","shell.execute_reply":"2022-07-24T09:47:48.827201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_model.fit(X_train, Y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:47:48.836301Z","iopub.execute_input":"2022-07-24T09:47:48.837088Z","iopub.status.idle":"2022-07-24T09:48:15.582014Z","shell.execute_reply.started":"2022-07-24T09:47:48.837048Z","shell.execute_reply":"2022-07-24T09:48:15.580522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = final_model.predict(X_valid)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:15.583736Z","iopub.execute_input":"2022-07-24T09:48:15.584167Z","iopub.status.idle":"2022-07-24T09:48:15.965781Z","shell.execute_reply.started":"2022-07-24T09:48:15.584101Z","shell.execute_reply":"2022-07-24T09:48:15.964278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:15.967440Z","iopub.execute_input":"2022-07-24T09:48:15.967868Z","iopub.status.idle":"2022-07-24T09:48:15.981536Z","shell.execute_reply.started":"2022-07-24T09:48:15.967824Z","shell.execute_reply":"2022-07-24T09:48:15.979964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_valid","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:15.985545Z","iopub.execute_input":"2022-07-24T09:48:15.987863Z","iopub.status.idle":"2022-07-24T09:48:16.018027Z","shell.execute_reply.started":"2022-07-24T09:48:15.987799Z","shell.execute_reply":"2022-07-24T09:48:16.016362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_valid = Y_valid>0.5","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:16.020725Z","iopub.execute_input":"2022-07-24T09:48:16.021244Z","iopub.status.idle":"2022-07-24T09:48:16.028380Z","shell.execute_reply.started":"2022-07-24T09:48:16.021207Z","shell.execute_reply":"2022-07-24T09:48:16.026847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Y_valid","metadata":{"execution":{"iopub.status.busy":"2022-07-22T16:21:59.203168Z","iopub.execute_input":"2022-07-22T16:21:59.203631Z","iopub.status.idle":"2022-07-22T16:21:59.218216Z","shell.execute_reply.started":"2022-07-22T16:21:59.203583Z","shell.execute_reply":"2022-07-22T16:21:59.216821Z"}}},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, mean_absolute_error, mean_squared_error, precision_score, recall_score, f1_score\npred = pred > 0.5\naccuracy_score(Y_valid, pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:16.030822Z","iopub.execute_input":"2022-07-24T09:48:16.031613Z","iopub.status.idle":"2022-07-24T09:48:16.046478Z","shell.execute_reply.started":"2022-07-24T09:48:16.031569Z","shell.execute_reply":"2022-07-24T09:48:16.045459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"final_model.fit(train_data, label)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:10:57.924331Z","iopub.execute_input":"2022-07-17T15:10:57.925303Z"}}},{"cell_type":"code","source":"pred = final_model.predict(test)\n#rounded_predictions = np.argmax(pred, axis = -1)\n#rounded_predictions = rounded_predictions > 0.5\npred = pred > 0.5\ndf = pd.DataFrame(pred, columns = ['Transported'])\ndf = a.join(df)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:16.048133Z","iopub.execute_input":"2022-07-24T09:48:16.048487Z","iopub.status.idle":"2022-07-24T09:48:16.752760Z","shell.execute_reply.started":"2022-07-24T09:48:16.048455Z","shell.execute_reply":"2022-07-24T09:48:16.751441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T09:48:16.754467Z","iopub.execute_input":"2022-07-24T09:48:16.754851Z","iopub.status.idle":"2022-07-24T09:48:16.773223Z","shell.execute_reply.started":"2022-07-24T09:48:16.754817Z","shell.execute_reply":"2022-07-24T09:48:16.771872Z"},"trusted":true},"execution_count":null,"outputs":[]}]}