{"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-08-09T11:59:24.633583Z","iopub.execute_input":"2022-08-09T11:59:24.634354Z","iopub.status.idle":"2022-08-09T11:59:24.650358Z","shell.execute_reply.started":"2022-08-09T11:59:24.634252Z","shell.execute_reply":"2022-08-09T11:59:24.649191Z"},"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":{"execution":{"iopub.status.busy":"2022-08-09T11:59:24.736765Z","iopub.execute_input":"2022-08-09T11:59:24.737684Z","iopub.status.idle":"2022-08-09T11:59:24.804620Z","shell.execute_reply.started":"2022-08-09T11:59:24.737634Z","shell.execute_reply":"2022-08-09T11:59:24.803346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:24.840659Z","iopub.execute_input":"2022-08-09T11:59:24.841082Z","iopub.status.idle":"2022-08-09T11:59:24.872322Z","shell.execute_reply.started":"2022-08-09T11:59:24.841047Z","shell.execute_reply":"2022-08-09T11:59:24.871140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:24.946274Z","iopub.execute_input":"2022-08-09T11:59:24.947041Z","iopub.status.idle":"2022-08-09T11:59:24.954335Z","shell.execute_reply.started":"2022-08-09T11:59:24.946997Z","shell.execute_reply":"2022-08-09T11:59:24.953210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.048132Z","iopub.execute_input":"2022-08-09T11:59:25.049011Z","iopub.status.idle":"2022-08-09T11:59:25.066030Z","shell.execute_reply.started":"2022-08-09T11:59:25.048952Z","shell.execute_reply":"2022-08-09T11:59:25.064969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train.dropna()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.316342Z","iopub.execute_input":"2022-08-09T11:59:25.317167Z","iopub.status.idle":"2022-08-09T11:59:25.332535Z","shell.execute_reply.started":"2022-08-09T11:59:25.317105Z","shell.execute_reply":"2022-08-09T11:59:25.331361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.423349Z","iopub.execute_input":"2022-08-09T11:59:25.423993Z","iopub.status.idle":"2022-08-09T11:59:25.435487Z","shell.execute_reply.started":"2022-08-09T11:59:25.423954Z","shell.execute_reply":"2022-08-09T11:59:25.434197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.515781Z","iopub.execute_input":"2022-08-09T11:59:25.516201Z","iopub.status.idle":"2022-08-09T11:59:25.522487Z","shell.execute_reply.started":"2022-08-09T11:59:25.516165Z","shell.execute_reply":"2022-08-09T11:59:25.521511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.611926Z","iopub.execute_input":"2022-08-09T11:59:25.612690Z","iopub.status.idle":"2022-08-09T11:59:25.634326Z","shell.execute_reply.started":"2022-08-09T11:59:25.612650Z","shell.execute_reply":"2022-08-09T11:59:25.633139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Visualization","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nplt.style.use(\"fivethirtyeight\")\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:25.707091Z","iopub.execute_input":"2022-08-09T11:59:25.708080Z","iopub.status.idle":"2022-08-09T11:59:26.237032Z","shell.execute_reply.started":"2022-08-09T11:59:25.708026Z","shell.execute_reply":"2022-08-09T11:59:26.235665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.239131Z","iopub.execute_input":"2022-08-09T11:59:26.239567Z","iopub.status.idle":"2022-08-09T11:59:26.245101Z","shell.execute_reply.started":"2022-08-09T11:59:26.239530Z","shell.execute_reply":"2022-08-09T11:59:26.243711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['HomePlanet'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.246922Z","iopub.execute_input":"2022-08-09T11:59:26.247268Z","iopub.status.idle":"2022-08-09T11:59:26.259813Z","shell.execute_reply.started":"2022-08-09T11:59:26.247237Z","shell.execute_reply":"2022-08-09T11:59:26.258515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index=train['HomePlanet'].value_counts().index\nvalues=train['HomePlanet'].value_counts()\nplt.figure(figsize=(16,8))\nplt.pie(values,labels=index,autopct=\"%1.1f%%\",wedgeprops={'edgecolor':'black'},explode=[0.1,0,0],shadow=True,startangle=200)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.262282Z","iopub.execute_input":"2022-08-09T11:59:26.262661Z","iopub.status.idle":"2022-08-09T11:59:26.441881Z","shell.execute_reply.started":"2022-08-09T11:59:26.262626Z","shell.execute_reply":"2022-08-09T11:59:26.440318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['CryoSleep'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.443871Z","iopub.execute_input":"2022-08-09T11:59:26.445195Z","iopub.status.idle":"2022-08-09T11:59:26.631064Z","shell.execute_reply.started":"2022-08-09T11:59:26.445127Z","shell.execute_reply":"2022-08-09T11:59:26.630168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['Destination'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.632147Z","iopub.execute_input":"2022-08-09T11:59:26.633172Z","iopub.status.idle":"2022-08-09T11:59:26.812961Z","shell.execute_reply.started":"2022-08-09T11:59:26.633135Z","shell.execute_reply":"2022-08-09T11:59:26.811404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(train['Age'],color='darkred')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:26.816502Z","iopub.execute_input":"2022-08-09T11:59:26.817654Z","iopub.status.idle":"2022-08-09T11:59:27.115565Z","shell.execute_reply.started":"2022-08-09T11:59:26.817599Z","shell.execute_reply":"2022-08-09T11:59:27.114659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['VIP']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.116892Z","iopub.execute_input":"2022-08-09T11:59:27.118006Z","iopub.status.idle":"2022-08-09T11:59:27.241281Z","shell.execute_reply.started":"2022-08-09T11:59:27.117956Z","shell.execute_reply":"2022-08-09T11:59:27.239681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['Transported']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.243371Z","iopub.execute_input":"2022-08-09T11:59:27.244895Z","iopub.status.idle":"2022-08-09T11:59:27.433439Z","shell.execute_reply.started":"2022-08-09T11:59:27.244844Z","shell.execute_reply":"2022-08-09T11:59:27.432387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Transported'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.434788Z","iopub.execute_input":"2022-08-09T11:59:27.435214Z","iopub.status.idle":"2022-08-09T11:59:27.444327Z","shell.execute_reply.started":"2022-08-09T11:59:27.435182Z","shell.execute_reply":"2022-08-09T11:59:27.443252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Transported'].value_counts().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.446194Z","iopub.execute_input":"2022-08-09T11:59:27.446575Z","iopub.status.idle":"2022-08-09T11:59:27.457276Z","shell.execute_reply.started":"2022-08-09T11:59:27.446542Z","shell.execute_reply":"2022-08-09T11:59:27.456180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def percentage(x):\n    percentage=100*x/6606\n    return str(percentage)+\"%\"","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.458458Z","iopub.execute_input":"2022-08-09T11:59:27.459404Z","iopub.status.idle":"2022-08-09T11:59:27.465549Z","shell.execute_reply.started":"2022-08-09T11:59:27.459368Z","shell.execute_reply":"2022-08-09T11:59:27.464709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percentage(3327)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.468439Z","iopub.execute_input":"2022-08-09T11:59:27.469414Z","iopub.status.idle":"2022-08-09T11:59:27.481747Z","shell.execute_reply.started":"2022-08-09T11:59:27.469377Z","shell.execute_reply":"2022-08-09T11:59:27.480369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percentage(3279)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.483094Z","iopub.execute_input":"2022-08-09T11:59:27.483534Z","iopub.status.idle":"2022-08-09T11:59:27.493947Z","shell.execute_reply.started":"2022-08-09T11:59:27.483495Z","shell.execute_reply":"2022-08-09T11:59:27.492397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.495559Z","iopub.execute_input":"2022-08-09T11:59:27.496958Z","iopub.status.idle":"2022-08-09T11:59:27.519645Z","shell.execute_reply.started":"2022-08-09T11:59:27.496909Z","shell.execute_reply":"2022-08-09T11:59:27.518811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.520785Z","iopub.execute_input":"2022-08-09T11:59:27.521506Z","iopub.status.idle":"2022-08-09T11:59:27.554191Z","shell.execute_reply.started":"2022-08-09T11:59:27.521463Z","shell.execute_reply":"2022-08-09T11:59:27.553142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=train['HomePlanet'],hue=train['Transported']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.555592Z","iopub.execute_input":"2022-08-09T11:59:27.555921Z","iopub.status.idle":"2022-08-09T11:59:27.764971Z","shell.execute_reply.started":"2022-08-09T11:59:27.555891Z","shell.execute_reply":"2022-08-09T11:59:27.763935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=train['Destination'],hue=train['Transported']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.766670Z","iopub.execute_input":"2022-08-09T11:59:27.767382Z","iopub.status.idle":"2022-08-09T11:59:27.988548Z","shell.execute_reply.started":"2022-08-09T11:59:27.767311Z","shell.execute_reply":"2022-08-09T11:59:27.987329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:27.989961Z","iopub.execute_input":"2022-08-09T11:59:27.990346Z","iopub.status.idle":"2022-08-09T11:59:28.012902Z","shell.execute_reply.started":"2022-08-09T11:59:27.990311Z","shell.execute_reply":"2022-08-09T11:59:28.011617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Feature Engineering","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.017852Z","iopub.execute_input":"2022-08-09T11:59:28.018638Z","iopub.status.idle":"2022-08-09T11:59:28.041443Z","shell.execute_reply.started":"2022-08-09T11:59:28.018585Z","shell.execute_reply":"2022-08-09T11:59:28.039949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**After looking the dataframe, I found that there are people who do not spend any money on the extra services such as RoomService, FoodCourt, ShoppingMall, Spa, VRDeck. So I will add an extra column 'Spendings' which will tell if they spend or not.\n0--zero spendings, 1--spending on any service...**","metadata":{}},{"cell_type":"code","source":"zero=train.loc[(train['RoomService']==0) & (train['FoodCourt']==0) & (train['ShoppingMall']==0) & (train['Spa']==0) & (train['VRDeck']==0)]","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.042955Z","iopub.execute_input":"2022-08-09T11:59:28.043599Z","iopub.status.idle":"2022-08-09T11:59:28.053807Z","shell.execute_reply.started":"2022-08-09T11:59:28.043561Z","shell.execute_reply":"2022-08-09T11:59:28.052507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(zero)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.056062Z","iopub.execute_input":"2022-08-09T11:59:28.056805Z","iopub.status.idle":"2022-08-09T11:59:28.062496Z","shell.execute_reply.started":"2022-08-09T11:59:28.056770Z","shell.execute_reply":"2022-08-09T11:59:28.061654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zero.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.064032Z","iopub.execute_input":"2022-08-09T11:59:28.065041Z","iopub.status.idle":"2022-08-09T11:59:28.090161Z","shell.execute_reply.started":"2022-08-09T11:59:28.065006Z","shell.execute_reply":"2022-08-09T11:59:28.089277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zero['Spendings']=zero['Spendings']=0","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.093311Z","iopub.execute_input":"2022-08-09T11:59:28.093866Z","iopub.status.idle":"2022-08-09T11:59:28.100964Z","shell.execute_reply.started":"2022-08-09T11:59:28.093818Z","shell.execute_reply":"2022-08-09T11:59:28.099643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zero.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.103214Z","iopub.execute_input":"2022-08-09T11:59:28.103801Z","iopub.status.idle":"2022-08-09T11:59:28.126636Z","shell.execute_reply.started":"2022-08-09T11:59:28.103768Z","shell.execute_reply":"2022-08-09T11:59:28.125765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Spendings']=zero['Spendings']","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.166484Z","iopub.execute_input":"2022-08-09T11:59:28.167183Z","iopub.status.idle":"2022-08-09T11:59:28.174018Z","shell.execute_reply.started":"2022-08-09T11:59:28.167134Z","shell.execute_reply":"2022-08-09T11:59:28.172925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Spendings'].fillna(value=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.263553Z","iopub.execute_input":"2022-08-09T11:59:28.263977Z","iopub.status.idle":"2022-08-09T11:59:28.270370Z","shell.execute_reply.started":"2022-08-09T11:59:28.263942Z","shell.execute_reply":"2022-08-09T11:59:28.268882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Spendings']=train['Spendings'].astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.362704Z","iopub.execute_input":"2022-08-09T11:59:28.363544Z","iopub.status.idle":"2022-08-09T11:59:28.370785Z","shell.execute_reply.started":"2022-08-09T11:59:28.363500Z","shell.execute_reply":"2022-08-09T11:59:28.369489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.461290Z","iopub.execute_input":"2022-08-09T11:59:28.462372Z","iopub.status.idle":"2022-08-09T11:59:28.485987Z","shell.execute_reply.started":"2022-08-09T11:59:28.462313Z","shell.execute_reply":"2022-08-09T11:59:28.484811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['Spendings']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.556106Z","iopub.execute_input":"2022-08-09T11:59:28.556559Z","iopub.status.idle":"2022-08-09T11:59:28.725636Z","shell.execute_reply.started":"2022-08-09T11:59:28.556520Z","shell.execute_reply":"2022-08-09T11:59:28.724401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['Spendings'],hue=train['Transported']);","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.727283Z","iopub.execute_input":"2022-08-09T11:59:28.727898Z","iopub.status.idle":"2022-08-09T11:59:28.928595Z","shell.execute_reply.started":"2022-08-09T11:59:28.727861Z","shell.execute_reply":"2022-08-09T11:59:28.927398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.930290Z","iopub.execute_input":"2022-08-09T11:59:28.930737Z","iopub.status.idle":"2022-08-09T11:59:28.938200Z","shell.execute_reply.started":"2022-08-09T11:59:28.930703Z","shell.execute_reply":"2022-08-09T11:59:28.937081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.939502Z","iopub.execute_input":"2022-08-09T11:59:28.940202Z","iopub.status.idle":"2022-08-09T11:59:28.965103Z","shell.execute_reply.started":"2022-08-09T11:59:28.940169Z","shell.execute_reply":"2022-08-09T11:59:28.964016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[['HomePlanet','CryoSleep','Destination','VIP']]=train[['HomePlanet','CryoSleep','Destination','VIP']].astype('str')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.967577Z","iopub.execute_input":"2022-08-09T11:59:28.967913Z","iopub.status.idle":"2022-08-09T11:59:28.977570Z","shell.execute_reply.started":"2022-08-09T11:59:28.967883Z","shell.execute_reply":"2022-08-09T11:59:28.976278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:28.979651Z","iopub.execute_input":"2022-08-09T11:59:28.980204Z","iopub.status.idle":"2022-08-09T11:59:28.991927Z","shell.execute_reply.started":"2022-08-09T11:59:28.980106Z","shell.execute_reply":"2022-08-09T11:59:28.990924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['HomePlanet']=train['HomePlanet'].replace({\"Earth\":0,\"Europa\":1,\"Mars\":2})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.004890Z","iopub.execute_input":"2022-08-09T11:59:29.005598Z","iopub.status.idle":"2022-08-09T11:59:29.016242Z","shell.execute_reply.started":"2022-08-09T11:59:29.005550Z","shell.execute_reply":"2022-08-09T11:59:29.015353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['CryoSleep']=train['CryoSleep'].replace({\"False\":0,\"True\":1})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.084336Z","iopub.execute_input":"2022-08-09T11:59:29.085137Z","iopub.status.idle":"2022-08-09T11:59:29.096689Z","shell.execute_reply.started":"2022-08-09T11:59:29.085086Z","shell.execute_reply":"2022-08-09T11:59:29.095606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Destination'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.156550Z","iopub.execute_input":"2022-08-09T11:59:29.157337Z","iopub.status.idle":"2022-08-09T11:59:29.167067Z","shell.execute_reply.started":"2022-08-09T11:59:29.157283Z","shell.execute_reply":"2022-08-09T11:59:29.165502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Destination']=train['Destination'].replace({\"TRAPPIST-1e\":0,\"PSO J318.5-22\":1,\"55 Cancri e\":2})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.231340Z","iopub.execute_input":"2022-08-09T11:59:29.232184Z","iopub.status.idle":"2022-08-09T11:59:29.244158Z","shell.execute_reply.started":"2022-08-09T11:59:29.232125Z","shell.execute_reply":"2022-08-09T11:59:29.243142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['VIP']=train['VIP'].replace({\"False\":0,\"True\":1})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.300574Z","iopub.execute_input":"2022-08-09T11:59:29.301334Z","iopub.status.idle":"2022-08-09T11:59:29.312044Z","shell.execute_reply.started":"2022-08-09T11:59:29.301284Z","shell.execute_reply":"2022-08-09T11:59:29.310839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.352704Z","iopub.execute_input":"2022-08-09T11:59:29.353490Z","iopub.status.idle":"2022-08-09T11:59:29.376971Z","shell.execute_reply.started":"2022-08-09T11:59:29.353438Z","shell.execute_reply":"2022-08-09T11:59:29.375729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Machine Learning","metadata":{}},{"cell_type":"code","source":"X=train[['HomePlanet','CryoSleep','Destination','Age','VIP','RoomService','FoodCourt','ShoppingMall','Spa','VRDeck','Spendings']]\ny=train['Transported']","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.418625Z","iopub.execute_input":"2022-08-09T11:59:29.419032Z","iopub.status.idle":"2022-08-09T11:59:29.428811Z","shell.execute_reply.started":"2022-08-09T11:59:29.418998Z","shell.execute_reply":"2022-08-09T11:59:29.427788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.519841Z","iopub.execute_input":"2022-08-09T11:59:29.520707Z","iopub.status.idle":"2022-08-09T11:59:29.581675Z","shell.execute_reply.started":"2022-08-09T11:59:29.520663Z","shell.execute_reply":"2022-08-09T11:59:29.580384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.615910Z","iopub.execute_input":"2022-08-09T11:59:29.616746Z","iopub.status.idle":"2022-08-09T11:59:29.625949Z","shell.execute_reply.started":"2022-08-09T11:59:29.616693Z","shell.execute_reply":"2022-08-09T11:59:29.625080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Logistic Regression","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:29.717261Z","iopub.execute_input":"2022-08-09T11:59:29.718289Z","iopub.status.idle":"2022-08-09T11:59:29.741791Z","shell.execute_reply.started":"2022-08-09T11:59:29.718245Z","shell.execute_reply":"2022-08-09T11:59:29.740855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=LogisticRegression()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.016603Z","iopub.execute_input":"2022-08-09T11:59:30.017583Z","iopub.status.idle":"2022-08-09T11:59:30.022598Z","shell.execute_reply.started":"2022-08-09T11:59:30.017527Z","shell.execute_reply":"2022-08-09T11:59:30.021563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.117838Z","iopub.execute_input":"2022-08-09T11:59:30.118666Z","iopub.status.idle":"2022-08-09T11:59:30.269554Z","shell.execute_reply.started":"2022-08-09T11:59:30.118621Z","shell.execute_reply":"2022-08-09T11:59:30.268004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions=model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.277449Z","iopub.execute_input":"2022-08-09T11:59:30.281307Z","iopub.status.idle":"2022-08-09T11:59:30.295152Z","shell.execute_reply.started":"2022-08-09T11:59:30.281243Z","shell.execute_reply":"2022-08-09T11:59:30.294275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.311051Z","iopub.execute_input":"2022-08-09T11:59:30.314961Z","iopub.status.idle":"2022-08-09T11:59:30.336188Z","shell.execute_reply.started":"2022-08-09T11:59:30.314892Z","shell.execute_reply":"2022-08-09T11:59:30.334656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nmodel_2=RandomForestClassifier()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.407019Z","iopub.execute_input":"2022-08-09T11:59:30.411409Z","iopub.status.idle":"2022-08-09T11:59:30.464223Z","shell.execute_reply.started":"2022-08-09T11:59:30.411321Z","shell.execute_reply":"2022-08-09T11:59:30.463167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_2.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:30.500440Z","iopub.execute_input":"2022-08-09T11:59:30.500867Z","iopub.status.idle":"2022-08-09T11:59:31.107807Z","shell.execute_reply.started":"2022-08-09T11:59:30.500830Z","shell.execute_reply":"2022-08-09T11:59:31.106668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_2=model_2.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.109792Z","iopub.execute_input":"2022-08-09T11:59:31.110130Z","iopub.status.idle":"2022-08-09T11:59:31.170667Z","shell.execute_reply.started":"2022-08-09T11:59:31.110101Z","shell.execute_reply":"2022-08-09T11:59:31.169307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_2.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.172301Z","iopub.execute_input":"2022-08-09T11:59:31.172703Z","iopub.status.idle":"2022-08-09T11:59:31.235041Z","shell.execute_reply.started":"2022-08-09T11:59:31.172669Z","shell.execute_reply":"2022-08-09T11:59:31.233925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Decision Tree","metadata":{}},{"cell_type":"code","source":"from sklearn import tree\nmodel_3=tree.DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.237759Z","iopub.execute_input":"2022-08-09T11:59:31.238108Z","iopub.status.idle":"2022-08-09T11:59:31.243025Z","shell.execute_reply.started":"2022-08-09T11:59:31.238076Z","shell.execute_reply":"2022-08-09T11:59:31.241691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_3.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.244750Z","iopub.execute_input":"2022-08-09T11:59:31.245078Z","iopub.status.idle":"2022-08-09T11:59:31.275195Z","shell.execute_reply.started":"2022-08-09T11:59:31.245049Z","shell.execute_reply":"2022-08-09T11:59:31.274378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_3=model_3.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.276883Z","iopub.execute_input":"2022-08-09T11:59:31.278005Z","iopub.status.idle":"2022-08-09T11:59:31.285467Z","shell.execute_reply.started":"2022-08-09T11:59:31.277959Z","shell.execute_reply":"2022-08-09T11:59:31.284708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_3.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.286947Z","iopub.execute_input":"2022-08-09T11:59:31.287628Z","iopub.status.idle":"2022-08-09T11:59:31.300097Z","shell.execute_reply.started":"2022-08-09T11:59:31.287578Z","shell.execute_reply":"2022-08-09T11:59:31.299108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# KNeighborsClassifier","metadata":{}},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nmodel_4=KNeighborsClassifier()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.301378Z","iopub.execute_input":"2022-08-09T11:59:31.301907Z","iopub.status.idle":"2022-08-09T11:59:31.308497Z","shell.execute_reply.started":"2022-08-09T11:59:31.301875Z","shell.execute_reply":"2022-08-09T11:59:31.307550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_4.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.310991Z","iopub.execute_input":"2022-08-09T11:59:31.311314Z","iopub.status.idle":"2022-08-09T11:59:31.330212Z","shell.execute_reply.started":"2022-08-09T11:59:31.311284Z","shell.execute_reply":"2022-08-09T11:59:31.329476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_4=model_4.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.359903Z","iopub.execute_input":"2022-08-09T11:59:31.360581Z","iopub.status.idle":"2022-08-09T11:59:31.470350Z","shell.execute_reply.started":"2022-08-09T11:59:31.360540Z","shell.execute_reply":"2022-08-09T11:59:31.469178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_4.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.472454Z","iopub.execute_input":"2022-08-09T11:59:31.472812Z","iopub.status.idle":"2022-08-09T11:59:31.584109Z","shell.execute_reply.started":"2022-08-09T11:59:31.472772Z","shell.execute_reply":"2022-08-09T11:59:31.582843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# SVM","metadata":{}},{"cell_type":"code","source":"from sklearn.svm import SVC","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.586864Z","iopub.execute_input":"2022-08-09T11:59:31.588068Z","iopub.status.idle":"2022-08-09T11:59:31.592941Z","shell.execute_reply.started":"2022-08-09T11:59:31.588017Z","shell.execute_reply":"2022-08-09T11:59:31.592085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_5=SVC()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.647868Z","iopub.execute_input":"2022-08-09T11:59:31.648396Z","iopub.status.idle":"2022-08-09T11:59:31.653657Z","shell.execute_reply.started":"2022-08-09T11:59:31.648352Z","shell.execute_reply":"2022-08-09T11:59:31.652710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_5.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:31.742891Z","iopub.execute_input":"2022-08-09T11:59:31.743940Z","iopub.status.idle":"2022-08-09T11:59:32.466668Z","shell.execute_reply.started":"2022-08-09T11:59:31.743895Z","shell.execute_reply":"2022-08-09T11:59:32.465331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_5=model_5.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:32.469681Z","iopub.execute_input":"2022-08-09T11:59:32.470167Z","iopub.status.idle":"2022-08-09T11:59:32.777809Z","shell.execute_reply.started":"2022-08-09T11:59:32.470121Z","shell.execute_reply":"2022-08-09T11:59:32.776438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_5.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:32.779503Z","iopub.execute_input":"2022-08-09T11:59:32.780765Z","iopub.status.idle":"2022-08-09T11:59:33.078709Z","shell.execute_reply.started":"2022-08-09T11:59:32.780727Z","shell.execute_reply":"2022-08-09T11:59:33.077529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample=pd.read_csv(\"../input/spaceship-titanic/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.081579Z","iopub.execute_input":"2022-08-09T11:59:33.081950Z","iopub.status.idle":"2022-08-09T11:59:33.092660Z","shell.execute_reply.started":"2022-08-09T11:59:33.081909Z","shell.execute_reply":"2022-08-09T11:59:33.091344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.093895Z","iopub.execute_input":"2022-08-09T11:59:33.094220Z","iopub.status.idle":"2022-08-09T11:59:33.104396Z","shell.execute_reply.started":"2022-08-09T11:59:33.094191Z","shell.execute_reply":"2022-08-09T11:59:33.103229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.106459Z","iopub.execute_input":"2022-08-09T11:59:33.106916Z","iopub.status.idle":"2022-08-09T11:59:33.113732Z","shell.execute_reply.started":"2022-08-09T11:59:33.106868Z","shell.execute_reply":"2022-08-09T11:59:33.112605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Final Model Prediction","metadata":{}},{"cell_type":"code","source":"model.fit(X,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.114924Z","iopub.execute_input":"2022-08-09T11:59:33.115351Z","iopub.status.idle":"2022-08-09T11:59:33.281107Z","shell.execute_reply.started":"2022-08-09T11:59:33.115309Z","shell.execute_reply":"2022-08-09T11:59:33.279583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Now I will have to clean test dataset as well...**","metadata":{}},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.283173Z","iopub.execute_input":"2022-08-09T11:59:33.284530Z","iopub.status.idle":"2022-08-09T11:59:33.303090Z","shell.execute_reply.started":"2022-08-09T11:59:33.284469Z","shell.execute_reply":"2022-08-09T11:59:33.301623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test['Age'].mean())\nprint(test['RoomService'].mean())\nprint(test['FoodCourt'].mean())\nprint(test['ShoppingMall'].mean())\nprint(test['Spa'].mean())\nprint(test['VRDeck'].mean())","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.305510Z","iopub.execute_input":"2022-08-09T11:59:33.306443Z","iopub.status.idle":"2022-08-09T11:59:33.321201Z","shell.execute_reply.started":"2022-08-09T11:59:33.306367Z","shell.execute_reply":"2022-08-09T11:59:33.319964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Age'].fillna(value=28.65,inplace=True)\ntest['RoomService'].fillna(value=219.26,inplace=True)\ntest['FoodCourt'].fillna(value=439.48,inplace=True)\ntest['ShoppingMall'].fillna(value=177.29,inplace=True)\ntest['Spa'].fillna(value=303.05,inplace=True)\ntest['VRDeck'].fillna(value=310.71,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.329261Z","iopub.execute_input":"2022-08-09T11:59:33.330322Z","iopub.status.idle":"2022-08-09T11:59:33.344893Z","shell.execute_reply.started":"2022-08-09T11:59:33.330249Z","shell.execute_reply":"2022-08-09T11:59:33.343039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['HomePlanet'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.347693Z","iopub.execute_input":"2022-08-09T11:59:33.348840Z","iopub.status.idle":"2022-08-09T11:59:33.363250Z","shell.execute_reply.started":"2022-08-09T11:59:33.348774Z","shell.execute_reply":"2022-08-09T11:59:33.361485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['CryoSleep'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.365732Z","iopub.execute_input":"2022-08-09T11:59:33.366740Z","iopub.status.idle":"2022-08-09T11:59:33.381676Z","shell.execute_reply.started":"2022-08-09T11:59:33.366680Z","shell.execute_reply":"2022-08-09T11:59:33.379828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Destination'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.384108Z","iopub.execute_input":"2022-08-09T11:59:33.385077Z","iopub.status.idle":"2022-08-09T11:59:33.397905Z","shell.execute_reply.started":"2022-08-09T11:59:33.385016Z","shell.execute_reply":"2022-08-09T11:59:33.396697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['VIP'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.399359Z","iopub.execute_input":"2022-08-09T11:59:33.400061Z","iopub.status.idle":"2022-08-09T11:59:33.408726Z","shell.execute_reply.started":"2022-08-09T11:59:33.400012Z","shell.execute_reply":"2022-08-09T11:59:33.407399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['HomePlanet'].fillna(value='Earth',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.410509Z","iopub.execute_input":"2022-08-09T11:59:33.411357Z","iopub.status.idle":"2022-08-09T11:59:33.418446Z","shell.execute_reply.started":"2022-08-09T11:59:33.411313Z","shell.execute_reply":"2022-08-09T11:59:33.417338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['CryoSleep'].fillna(value='False',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.420074Z","iopub.execute_input":"2022-08-09T11:59:33.420695Z","iopub.status.idle":"2022-08-09T11:59:33.430852Z","shell.execute_reply.started":"2022-08-09T11:59:33.420660Z","shell.execute_reply":"2022-08-09T11:59:33.429529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Destination'].fillna(value='TRAPPIST-1e',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.432653Z","iopub.execute_input":"2022-08-09T11:59:33.433307Z","iopub.status.idle":"2022-08-09T11:59:33.440363Z","shell.execute_reply.started":"2022-08-09T11:59:33.433270Z","shell.execute_reply":"2022-08-09T11:59:33.439366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['VIP'].fillna(value='False',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.441818Z","iopub.execute_input":"2022-08-09T11:59:33.442650Z","iopub.status.idle":"2022-08-09T11:59:33.451522Z","shell.execute_reply.started":"2022-08-09T11:59:33.442616Z","shell.execute_reply":"2022-08-09T11:59:33.450604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test[['HomePlanet','CryoSleep','Destination','VIP']]=test[['HomePlanet','CryoSleep','Destination','VIP']].astype('str')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.452835Z","iopub.execute_input":"2022-08-09T11:59:33.453986Z","iopub.status.idle":"2022-08-09T11:59:33.464604Z","shell.execute_reply.started":"2022-08-09T11:59:33.453951Z","shell.execute_reply":"2022-08-09T11:59:33.463483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['HomePlanet']=test['HomePlanet'].replace({\"Earth\":0,\"Europa\":1,\"Mars\":2})\ntest['CryoSleep']=test['CryoSleep'].replace({\"False\":0,\"True\":1})\ntest['Destination']=test['Destination'].replace({\"TRAPPIST-1e\":0,\"PSO J318.5-22\":1,\"55 Cancri e\":2})\ntest['VIP']=test['VIP'].replace({\"False\":0,\"True\":1})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.465966Z","iopub.execute_input":"2022-08-09T11:59:33.466652Z","iopub.status.idle":"2022-08-09T11:59:33.486898Z","shell.execute_reply.started":"2022-08-09T11:59:33.466613Z","shell.execute_reply":"2022-08-09T11:59:33.485932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.488278Z","iopub.execute_input":"2022-08-09T11:59:33.489058Z","iopub.status.idle":"2022-08-09T11:59:33.507158Z","shell.execute_reply.started":"2022-08-09T11:59:33.489023Z","shell.execute_reply":"2022-08-09T11:59:33.506004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Adding spendings column in test dataset as well...**","metadata":{}},{"cell_type":"code","source":"zero_test=test.loc[(test['RoomService']==0) & (test['FoodCourt']==0) & (test['ShoppingMall']==0) & (test['Spa']==0) & (test['VRDeck']==0)]","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.508616Z","iopub.execute_input":"2022-08-09T11:59:33.509149Z","iopub.status.idle":"2022-08-09T11:59:33.519380Z","shell.execute_reply.started":"2022-08-09T11:59:33.509114Z","shell.execute_reply":"2022-08-09T11:59:33.518456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zero_test['Spendings']=zero_test['Spendings']=0","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.520778Z","iopub.execute_input":"2022-08-09T11:59:33.521780Z","iopub.status.idle":"2022-08-09T11:59:33.528213Z","shell.execute_reply.started":"2022-08-09T11:59:33.521722Z","shell.execute_reply":"2022-08-09T11:59:33.527335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Spendings']=zero_test['Spendings']","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.529740Z","iopub.execute_input":"2022-08-09T11:59:33.530574Z","iopub.status.idle":"2022-08-09T11:59:33.538552Z","shell.execute_reply.started":"2022-08-09T11:59:33.530524Z","shell.execute_reply":"2022-08-09T11:59:33.537809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Spendings'].fillna(value=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.540043Z","iopub.execute_input":"2022-08-09T11:59:33.540363Z","iopub.status.idle":"2022-08-09T11:59:33.548063Z","shell.execute_reply.started":"2022-08-09T11:59:33.540324Z","shell.execute_reply":"2022-08-09T11:59:33.546982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Spendings']=test['Spendings'].astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.549813Z","iopub.execute_input":"2022-08-09T11:59:33.550229Z","iopub.status.idle":"2022-08-09T11:59:33.560252Z","shell.execute_reply.started":"2022-08-09T11:59:33.550187Z","shell.execute_reply":"2022-08-09T11:59:33.559087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=test[['HomePlanet','CryoSleep','Destination','Age','VIP','RoomService','FoodCourt','ShoppingMall','Spa','VRDeck','Spendings']]","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.561702Z","iopub.execute_input":"2022-08-09T11:59:33.562203Z","iopub.status.idle":"2022-08-09T11:59:33.572660Z","shell.execute_reply.started":"2022-08-09T11:59:33.562171Z","shell.execute_reply":"2022-08-09T11:59:33.571594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.577128Z","iopub.execute_input":"2022-08-09T11:59:33.577736Z","iopub.status.idle":"2022-08-09T11:59:33.748316Z","shell.execute_reply.started":"2022-08-09T11:59:33.577701Z","shell.execute_reply":"2022-08-09T11:59:33.746766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_predictions=model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.755205Z","iopub.execute_input":"2022-08-09T11:59:33.759780Z","iopub.status.idle":"2022-08-09T11:59:33.773399Z","shell.execute_reply.started":"2022-08-09T11:59:33.759699Z","shell.execute_reply":"2022-08-09T11:59:33.771739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.781055Z","iopub.execute_input":"2022-08-09T11:59:33.785037Z","iopub.status.idle":"2022-08-09T11:59:33.808162Z","shell.execute_reply.started":"2022-08-09T11:59:33.784960Z","shell.execute_reply":"2022-08-09T11:59:33.806512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.DataFrame({'PassengerId':sample['PassengerId'],'Transported':final_predictions})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.814986Z","iopub.execute_input":"2022-08-09T11:59:33.816318Z","iopub.status.idle":"2022-08-09T11:59:33.830232Z","shell.execute_reply.started":"2022-08-09T11:59:33.816255Z","shell.execute_reply":"2022-08-09T11:59:33.828662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:59:33.832958Z","iopub.execute_input":"2022-08-09T11:59:33.834104Z","iopub.status.idle":"2022-08-09T11:59:33.860056Z","shell.execute_reply.started":"2022-08-09T11:59:33.833908Z","shell.execute_reply":"2022-08-09T11:59:33.858485Z"},"trusted":true},"execution_count":null,"outputs":[]}]}