{"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":"# Importing basic libraries \nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:48.372245Z","iopub.execute_input":"2022-08-05T15:12:48.372830Z","iopub.status.idle":"2022-08-05T15:12:49.075133Z","shell.execute_reply.started":"2022-08-05T15:12:48.372786Z","shell.execute_reply":"2022-08-05T15:12:49.073780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"../input/spaceship-titanic/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.077289Z","iopub.execute_input":"2022-08-05T15:12:49.077996Z","iopub.status.idle":"2022-08-05T15:12:49.136753Z","shell.execute_reply.started":"2022-08-05T15:12:49.077955Z","shell.execute_reply":"2022-08-05T15:12:49.135419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.138612Z","iopub.execute_input":"2022-08-05T15:12:49.139394Z","iopub.status.idle":"2022-08-05T15:12:49.177842Z","shell.execute_reply.started":"2022-08-05T15:12:49.139339Z","shell.execute_reply":"2022-08-05T15:12:49.176763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.180230Z","iopub.execute_input":"2022-08-05T15:12:49.180641Z","iopub.status.idle":"2022-08-05T15:12:49.216339Z","shell.execute_reply.started":"2022-08-05T15:12:49.180605Z","shell.execute_reply":"2022-08-05T15:12:49.214785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.218211Z","iopub.execute_input":"2022-08-05T15:12:49.218583Z","iopub.status.idle":"2022-08-05T15:12:49.258969Z","shell.execute_reply.started":"2022-08-05T15:12:49.218550Z","shell.execute_reply":"2022-08-05T15:12:49.257688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.260511Z","iopub.execute_input":"2022-08-05T15:12:49.260892Z","iopub.status.idle":"2022-08-05T15:12:49.283427Z","shell.execute_reply.started":"2022-08-05T15:12:49.260857Z","shell.execute_reply":"2022-08-05T15:12:49.282259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data-Preprocessing","metadata":{}},{"cell_type":"markdown","source":"### Columns \"Name\" ,\"PassengerID \" are insignificant for our prediction. Therefore, dropping these columns","metadata":{}},{"cell_type":"code","source":"data.drop([\"Name\",\"PassengerId\"], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.285226Z","iopub.execute_input":"2022-08-05T15:12:49.285700Z","iopub.status.idle":"2022-08-05T15:12:49.296926Z","shell.execute_reply.started":"2022-08-05T15:12:49.285639Z","shell.execute_reply":"2022-08-05T15:12:49.295647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Handling Missing values","metadata":{}},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.298984Z","iopub.execute_input":"2022-08-05T15:12:49.299358Z","iopub.status.idle":"2022-08-05T15:12:49.315978Z","shell.execute_reply.started":"2022-08-05T15:12:49.299315Z","shell.execute_reply":"2022-08-05T15:12:49.314776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting count plot between two features with annotaion\nplt.figure(figsize=(15,8))\nplots = sns.countplot(x=\"HomePlanet\", hue=\"Destination\", data=data)\nplt.xlabel(\"DIFFERENT HOME PLANETS\",fontsize= 20)\nplt.ylabel(\"COUNT\", fontsize= 20)\n\nfor bar in plots.patches:\n    plots.annotate(format(bar.get_height(), '.2f'),(bar.get_x() + bar.get_width() / 2,bar.get_height()), \n                   ha='center', va='center',size=15, xytext=(0, 8),textcoords='offset points')   ","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.317607Z","iopub.execute_input":"2022-08-05T15:12:49.318362Z","iopub.status.idle":"2022-08-05T15:12:49.680162Z","shell.execute_reply.started":"2022-08-05T15:12:49.318326Z","shell.execute_reply":"2022-08-05T15:12:49.678959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Majority of the people are travelling from Planet \"Earth\" to Planet \"TRAPPIST-1e\". Hence,we will replace missing values in \"HomePlanet\" & \"Destination\" with \"Earth\" and \"TRAPPIST-1e\" respectively.  ","metadata":{}},{"cell_type":"code","source":"data[\"HomePlanet\"].fillna(\"Earth\",inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.684015Z","iopub.execute_input":"2022-08-05T15:12:49.684535Z","iopub.status.idle":"2022-08-05T15:12:49.691894Z","shell.execute_reply.started":"2022-08-05T15:12:49.684492Z","shell.execute_reply":"2022-08-05T15:12:49.690685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"Destination\"].fillna(\"TRAPPIST-1e\",inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.693991Z","iopub.execute_input":"2022-08-05T15:12:49.695111Z","iopub.status.idle":"2022-08-05T15:12:49.705869Z","shell.execute_reply.started":"2022-08-05T15:12:49.695059Z","shell.execute_reply":"2022-08-05T15:12:49.704779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"CryoSleep\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.707361Z","iopub.execute_input":"2022-08-05T15:12:49.708075Z","iopub.status.idle":"2022-08-05T15:12:49.725333Z","shell.execute_reply.started":"2022-08-05T15:12:49.708020Z","shell.execute_reply":"2022-08-05T15:12:49.724096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"CryoSleep\"].fillna(data[\"CryoSleep\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.726842Z","iopub.execute_input":"2022-08-05T15:12:49.728282Z","iopub.status.idle":"2022-08-05T15:12:49.739426Z","shell.execute_reply.started":"2022-08-05T15:12:49.728226Z","shell.execute_reply":"2022-08-05T15:12:49.738140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"Age\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.741270Z","iopub.execute_input":"2022-08-05T15:12:49.742410Z","iopub.status.idle":"2022-08-05T15:12:49.758845Z","shell.execute_reply.started":"2022-08-05T15:12:49.742358Z","shell.execute_reply":"2022-08-05T15:12:49.757751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"Age\"].fillna(data[\"Age\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.760362Z","iopub.execute_input":"2022-08-05T15:12:49.761115Z","iopub.status.idle":"2022-08-05T15:12:49.769394Z","shell.execute_reply.started":"2022-08-05T15:12:49.761077Z","shell.execute_reply":"2022-08-05T15:12:49.768254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"VIP\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.770696Z","iopub.execute_input":"2022-08-05T15:12:49.771070Z","iopub.status.idle":"2022-08-05T15:12:49.786184Z","shell.execute_reply.started":"2022-08-05T15:12:49.771035Z","shell.execute_reply":"2022-08-05T15:12:49.784523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"VIP\"].fillna(data[\"VIP\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.788165Z","iopub.execute_input":"2022-08-05T15:12:49.789095Z","iopub.status.idle":"2022-08-05T15:12:49.797576Z","shell.execute_reply.started":"2022-08-05T15:12:49.789056Z","shell.execute_reply":"2022-08-05T15:12:49.796287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Separating Deck,Cabin,and Port side values and storing them in new columns","metadata":{}},{"cell_type":"code","source":"cabin_data = data[\"Cabin\"].str.split(\"/\", n=2, expand=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.799290Z","iopub.execute_input":"2022-08-05T15:12:49.800549Z","iopub.status.idle":"2022-08-05T15:12:49.827815Z","shell.execute_reply.started":"2022-08-05T15:12:49.800502Z","shell.execute_reply":"2022-08-05T15:12:49.826363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_data","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.829283Z","iopub.execute_input":"2022-08-05T15:12:49.830113Z","iopub.status.idle":"2022-08-05T15:12:49.848747Z","shell.execute_reply.started":"2022-08-05T15:12:49.830062Z","shell.execute_reply":"2022-08-05T15:12:49.847420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"Deck\"]=cabin_data[0]\ndata[\"Number\"]=cabin_data[1]\ndata[\"Side\"]=cabin_data[2]","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.850641Z","iopub.execute_input":"2022-08-05T15:12:49.851575Z","iopub.status.idle":"2022-08-05T15:12:49.861267Z","shell.execute_reply.started":"2022-08-05T15:12:49.851522Z","shell.execute_reply":"2022-08-05T15:12:49.860165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(\"Cabin\", axis=1,inplace=True)   # Dropping columns \"cabin\"","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.862784Z","iopub.execute_input":"2022-08-05T15:12:49.863347Z","iopub.status.idle":"2022-08-05T15:12:49.874658Z","shell.execute_reply.started":"2022-08-05T15:12:49.863311Z","shell.execute_reply":"2022-08-05T15:12:49.873769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.876186Z","iopub.execute_input":"2022-08-05T15:12:49.878595Z","iopub.status.idle":"2022-08-05T15:12:49.901664Z","shell.execute_reply.started":"2022-08-05T15:12:49.878547Z","shell.execute_reply":"2022-08-05T15:12:49.900430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Filling the missing values with mode\ndata[\"Deck\"].fillna(data[\"Deck\"].mode()[0], inplace=True)\ndata[\"Side\"].fillna(data[\"Side\"].mode()[0], inplace=True)\ndata[\"Number\"].fillna(data[\"Number\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.903090Z","iopub.execute_input":"2022-08-05T15:12:49.904296Z","iopub.status.idle":"2022-08-05T15:12:49.919744Z","shell.execute_reply.started":"2022-08-05T15:12:49.904249Z","shell.execute_reply":"2022-08-05T15:12:49.918760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"RoomService\"].fillna(data[\"RoomService\"].median(), inplace=True)\ndata[\"FoodCourt\"].fillna(data[\"FoodCourt\"].median(), inplace=True)\ndata[\"ShoppingMall\"].fillna(data[\"ShoppingMall\"].median(), inplace=True)\ndata[\"Spa\"].fillna(data[\"Spa\"].median(), inplace=True)\ndata[\"VRDeck\"].fillna(data[\"VRDeck\"].median(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.921422Z","iopub.execute_input":"2022-08-05T15:12:49.921942Z","iopub.status.idle":"2022-08-05T15:12:49.940025Z","shell.execute_reply.started":"2022-08-05T15:12:49.921893Z","shell.execute_reply":"2022-08-05T15:12:49.938772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.941618Z","iopub.execute_input":"2022-08-05T15:12:49.942982Z","iopub.status.idle":"2022-08-05T15:12:49.957026Z","shell.execute_reply.started":"2022-08-05T15:12:49.942930Z","shell.execute_reply":"2022-08-05T15:12:49.955763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Label-encoding","metadata":{}},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.958405Z","iopub.execute_input":"2022-08-05T15:12:49.959212Z","iopub.status.idle":"2022-08-05T15:12:49.982849Z","shell.execute_reply.started":"2022-08-05T15:12:49.959164Z","shell.execute_reply":"2022-08-05T15:12:49.981739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dividing Age values into groups\nlst=[data]\nfor column in lst:\n    column.loc[(column['Age']>=0) & (column['Age']<=1), \"Age_category\"]=\"Infant\"\n    column.loc[(column['Age']>=2) & (column['Age']<=4), \"Age_category\"]=\"Toddler\"\n    column.loc[(column['Age']>=5) & (column['Age']<=12), \"Age_category\"]=\"Child\"\n    column.loc[(column['Age']>=13) & (column['Age']<=19), \"Age_category\"]=\"Teen\"\n    column.loc[(column['Age']>=20) & (column['Age']<=39), \"Age_category\"]=\"Adult\"\n    column.loc[(column['Age']>=40) & (column['Age']<=59), \"Age_category\"]=\"Middle Age Adult\"\n    column.loc[(column['Age']>=60) ,\"Age_category\"]=\"Senior Adult\"\n\ndata['Age_category'] = data['Age_category'].astype(\"category\")\n","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:49.984421Z","iopub.execute_input":"2022-08-05T15:12:49.984960Z","iopub.status.idle":"2022-08-05T15:12:50.008000Z","shell.execute_reply.started":"2022-08-05T15:12:49.984924Z","shell.execute_reply":"2022-08-05T15:12:50.006429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(\"Age\", axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.016517Z","iopub.execute_input":"2022-08-05T15:12:50.017169Z","iopub.status.idle":"2022-08-05T15:12:50.023682Z","shell.execute_reply.started":"2022-08-05T15:12:50.017129Z","shell.execute_reply":"2022-08-05T15:12:50.022737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data = data.copy()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.024827Z","iopub.execute_input":"2022-08-05T15:12:50.025581Z","iopub.status.idle":"2022-08-05T15:12:50.038744Z","shell.execute_reply.started":"2022-08-05T15:12:50.025543Z","shell.execute_reply":"2022-08-05T15:12:50.037212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lst_of_col=['HomePlanet', 'CryoSleep', 'Destination', 'VIP',\n       'Transported', 'Deck', 'Side', 'Age_category']\nfor i in lst_of_col:\n    new_data[i]=new_data[i].astype(\"category\")\n    new_data[i]=new_data[i].cat.codes ","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.040029Z","iopub.execute_input":"2022-08-05T15:12:50.040412Z","iopub.status.idle":"2022-08-05T15:12:50.070615Z","shell.execute_reply.started":"2022-08-05T15:12:50.040377Z","shell.execute_reply":"2022-08-05T15:12:50.069373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_encoded_data = new_data.copy()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.072158Z","iopub.execute_input":"2022-08-05T15:12:50.072841Z","iopub.status.idle":"2022-08-05T15:12:50.079915Z","shell.execute_reply.started":"2022-08-05T15:12:50.072800Z","shell.execute_reply":"2022-08-05T15:12:50.078521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data[\"Number\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.081625Z","iopub.execute_input":"2022-08-05T15:12:50.082468Z","iopub.status.idle":"2022-08-05T15:12:50.098511Z","shell.execute_reply.started":"2022-08-05T15:12:50.082431Z","shell.execute_reply":"2022-08-05T15:12:50.097559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# one hot encoding\nlst_of_col_two=['HomePlanet','Destination','Deck','Age_category']\nfor i in lst_of_col_two:\n    new_data=pd.get_dummies(new_data, columns=[i],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.099696Z","iopub.execute_input":"2022-08-05T15:12:50.100629Z","iopub.status.idle":"2022-08-05T15:12:50.130361Z","shell.execute_reply.started":"2022-08-05T15:12:50.100590Z","shell.execute_reply":"2022-08-05T15:12:50.129166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.132065Z","iopub.execute_input":"2022-08-05T15:12:50.132471Z","iopub.status.idle":"2022-08-05T15:12:50.160090Z","shell.execute_reply.started":"2022-08-05T15:12:50.132409Z","shell.execute_reply":"2022-08-05T15:12:50.158987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Seprating dependent and independent variables\nX = new_data.drop(\"Transported\", axis=1)\ny= new_data[\"Transported\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.161862Z","iopub.execute_input":"2022-08-05T15:12:50.162305Z","iopub.status.idle":"2022-08-05T15:12:50.172877Z","shell.execute_reply.started":"2022-08-05T15:12:50.162268Z","shell.execute_reply":"2022-08-05T15:12:50.171037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# standardization\nfrom sklearn.preprocessing import StandardScaler\nsc = StandardScaler()\nX_scaled = sc.fit_transform(X)\nX_scaled","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.175124Z","iopub.execute_input":"2022-08-05T15:12:50.176053Z","iopub.status.idle":"2022-08-05T15:12:50.307006Z","shell.execute_reply.started":"2022-08-05T15:12:50.176013Z","shell.execute_reply":"2022-08-05T15:12:50.305754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_scaled = pd.DataFrame(X_scaled)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.309258Z","iopub.execute_input":"2022-08-05T15:12:50.309827Z","iopub.status.idle":"2022-08-05T15:12:50.315769Z","shell.execute_reply.started":"2022-08-05T15:12:50.309776Z","shell.execute_reply":"2022-08-05T15:12:50.314393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_scaled","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.317961Z","iopub.execute_input":"2022-08-05T15:12:50.318710Z","iopub.status.idle":"2022-08-05T15:12:50.356227Z","shell.execute_reply.started":"2022-08-05T15:12:50.318623Z","shell.execute_reply":"2022-08-05T15:12:50.355042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking for imbalanced \ny.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.359707Z","iopub.execute_input":"2022-08-05T15:12:50.360743Z","iopub.status.idle":"2022-08-05T15:12:50.369578Z","shell.execute_reply.started":"2022-08-05T15:12:50.360692Z","shell.execute_reply":"2022-08-05T15:12:50.368522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Target variable is well balance. ","metadata":{}},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.371245Z","iopub.execute_input":"2022-08-05T15:12:50.372004Z","iopub.status.idle":"2022-08-05T15:12:50.396085Z","shell.execute_reply.started":"2022-08-05T15:12:50.371957Z","shell.execute_reply":"2022-08-05T15:12:50.394862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting correlational matrix\nplt.figure(figsize=(15,8))\ncorr = data.corr()\nsns.heatmap(corr,annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.397452Z","iopub.execute_input":"2022-08-05T15:12:50.398052Z","iopub.status.idle":"2022-08-05T15:12:50.998306Z","shell.execute_reply.started":"2022-08-05T15:12:50.398015Z","shell.execute_reply":"2022-08-05T15:12:50.996999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Observations:-\n* Highest positive correlation can be seen between columns \"CryoSleep\"and\"Transported\".\n* Highest negative correlation can be seen between columns \"RoomService\"and\"Transported\".","metadata":{}},{"cell_type":"code","source":"# Plotting count plot between \"Deck\" and \"HomePlanet\"\nplt.figure(figsize=(15,8))\nplots = sns.countplot(x=\"Deck\", hue=\"HomePlanet\", data=data, palette='spring')\nplt.xticks(fontsize=15)\nplt.xlabel(\"DIFFERENT DECKS\",fontsize= 20)\nplt.ylabel(\"COUNT\", fontsize= 20)\n\nfor bar in plots.patches:\n    plots.annotate(format(bar.get_height()),(bar.get_x() + bar.get_width() / 2,bar.get_height()), \n                   ha='center', va='center',size=10, xytext=(0, 8),textcoords='offset points')   ","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:50.999971Z","iopub.execute_input":"2022-08-05T15:12:51.000654Z","iopub.status.idle":"2022-08-05T15:12:51.421212Z","shell.execute_reply.started":"2022-08-05T15:12:51.000604Z","shell.execute_reply":"2022-08-05T15:12:51.419762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Highest no. of people are staying on deck 'G'. \n### Only 5 people are staying on Deck 'T'.","metadata":{}},{"cell_type":"code","source":"# to get ouput after filtering values in two columns / conditon based filtering\nfilter1 = data[\"Deck\"].isin([\"T\"])\n#filter2 = credit_data[\"Dependents\"]=='0'\ndf1=data[filter1]\n#df1.Dependents.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:51.422982Z","iopub.execute_input":"2022-08-05T15:12:51.423432Z","iopub.status.idle":"2022-08-05T15:12:51.431631Z","shell.execute_reply.started":"2022-08-05T15:12:51.423386Z","shell.execute_reply":"2022-08-05T15:12:51.429851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting count plot between \"CryoSleep\" and \"Transported\"\nplt.figure(figsize=(15,8))\nplots = sns.countplot(x=\"CryoSleep\", hue=\"Transported\", data=data, palette=\"nipy_spectral\")\nplt.xticks(fontsize=15)\nplt.xlabel(\"People transported or not\",fontsize= 20)\nplt.ylabel(\"COUNT\", fontsize= 20)\n\nfor bar in plots.patches:\n    plots.annotate(format(bar.get_height()),(bar.get_x() + bar.get_width() / 2,bar.get_height()), \n                   ha='center', va='center',size=15, xytext=(0, 8),textcoords='offset points')   ","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:51.433721Z","iopub.execute_input":"2022-08-05T15:12:51.434304Z","iopub.status.idle":"2022-08-05T15:12:51.707413Z","shell.execute_reply.started":"2022-08-05T15:12:51.434255Z","shell.execute_reply":"2022-08-05T15:12:51.706129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting count plot between \"Destination\" and \"Transported\"\nplt.figure(figsize=(10,6))\nplots = sns.countplot( x = \"Destination\", hue=\"Transported\",data=data, palette=\"mako\")\nplt.xticks(fontsize=10)\nplt.xlabel(\"Different Destination Planets\",fontsize=15)\nplt.ylabel(\"Count\",fontsize=15)\n\nfor bar in plots.patches:\n    plots.annotate(format(bar.get_height()),(bar.get_x() + bar.get_width() / 2,bar.get_height()), \n                   ha='center', va='center',size=15, xytext=(0, 8),textcoords='offset points')","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:51.709215Z","iopub.execute_input":"2022-08-05T15:12:51.709624Z","iopub.status.idle":"2022-08-05T15:12:51.987400Z","shell.execute_reply.started":"2022-08-05T15:12:51.709589Z","shell.execute_reply":"2022-08-05T15:12:51.986027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Max. people are travelling to planet \"TRAPPIST-1e\"","metadata":{}},{"cell_type":"markdown","source":"# test-train-split","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.25, random_state=111)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:51.988828Z","iopub.execute_input":"2022-08-05T15:12:51.989306Z","iopub.status.idle":"2022-08-05T15:12:52.070275Z","shell.execute_reply.started":"2022-08-05T15:12:51.989259Z","shell.execute_reply":"2022-08-05T15:12:52.069123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Using XgBoost Algorithm","metadata":{}},{"cell_type":"code","source":"from xgboost import XGBClassifier\nxgb = XGBClassifier()\nxgb.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:52.072277Z","iopub.execute_input":"2022-08-05T15:12:52.072647Z","iopub.status.idle":"2022-08-05T15:12:53.963931Z","shell.execute_reply.started":"2022-08-05T15:12:52.072616Z","shell.execute_reply":"2022-08-05T15:12:53.962872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predicting using the model","metadata":{}},{"cell_type":"code","source":"y_pred_xgb_train = xgb.predict(X_train)\ny_pred_xgb_test = xgb.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:53.966983Z","iopub.execute_input":"2022-08-05T15:12:53.967489Z","iopub.status.idle":"2022-08-05T15:12:53.995350Z","shell.execute_reply.started":"2022-08-05T15:12:53.967438Z","shell.execute_reply":"2022-08-05T15:12:53.994434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Evaluation metrics","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import classification_report, confusion_matrix, accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:53.996569Z","iopub.execute_input":"2022-08-05T15:12:53.997458Z","iopub.status.idle":"2022-08-05T15:12:54.002642Z","shell.execute_reply.started":"2022-08-05T15:12:53.997415Z","shell.execute_reply":"2022-08-05T15:12:54.001628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_train, y_pred_xgb_train))\nprint(\"=\"*60)\nprint(classification_report(y_test, y_pred_xgb_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.004360Z","iopub.execute_input":"2022-08-05T15:12:54.005049Z","iopub.status.idle":"2022-08-05T15:12:54.039860Z","shell.execute_reply.started":"2022-08-05T15:12:54.005009Z","shell.execute_reply":"2022-08-05T15:12:54.038785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_train, y_pred_xgb_train))\nprint(\"=\"*20)\nprint(confusion_matrix(y_test, y_pred_xgb_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.041008Z","iopub.execute_input":"2022-08-05T15:12:54.042040Z","iopub.status.idle":"2022-08-05T15:12:54.055442Z","shell.execute_reply.started":"2022-08-05T15:12:54.042001Z","shell.execute_reply":"2022-08-05T15:12:54.053658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(y_train, y_pred_xgb_train))\nprint(\"=\"*20)\nprint(accuracy_score(y_test, y_pred_xgb_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.057216Z","iopub.execute_input":"2022-08-05T15:12:54.057806Z","iopub.status.idle":"2022-08-05T15:12:54.066704Z","shell.execute_reply.started":"2022-08-05T15:12:54.057755Z","shell.execute_reply":"2022-08-05T15:12:54.065747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## We are getting an accuracy of 80.12% using Xgboost algorithm","metadata":{}},{"cell_type":"code","source":"# Loading the test data\ntest_data= pd.read_csv(\"../input/spaceship-titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.068839Z","iopub.execute_input":"2022-08-05T15:12:54.069349Z","iopub.status.idle":"2022-08-05T15:12:54.104214Z","shell.execute_reply.started":"2022-08-05T15:12:54.069294Z","shell.execute_reply":"2022-08-05T15:12:54.102890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.105574Z","iopub.execute_input":"2022-08-05T15:12:54.105928Z","iopub.status.idle":"2022-08-05T15:12:54.127765Z","shell.execute_reply.started":"2022-08-05T15:12:54.105897Z","shell.execute_reply":"2022-08-05T15:12:54.126499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.129857Z","iopub.execute_input":"2022-08-05T15:12:54.130773Z","iopub.status.idle":"2022-08-05T15:12:54.141483Z","shell.execute_reply.started":"2022-08-05T15:12:54.130720Z","shell.execute_reply":"2022-08-05T15:12:54.140450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data-preprocessing of the test data","metadata":{}},{"cell_type":"code","source":"indexcol = test_data.PassengerId.to_numpy()\ntest_data.set_index('PassengerId',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.142970Z","iopub.execute_input":"2022-08-05T15:12:54.143894Z","iopub.status.idle":"2022-08-05T15:12:54.155270Z","shell.execute_reply.started":"2022-08-05T15:12:54.143858Z","shell.execute_reply":"2022-08-05T15:12:54.153947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.drop([\"Name\"], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.158763Z","iopub.execute_input":"2022-08-05T15:12:54.160281Z","iopub.status.idle":"2022-08-05T15:12:54.171612Z","shell.execute_reply.started":"2022-08-05T15:12:54.160229Z","shell.execute_reply":"2022-08-05T15:12:54.170142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.173591Z","iopub.execute_input":"2022-08-05T15:12:54.174544Z","iopub.status.idle":"2022-08-05T15:12:54.200183Z","shell.execute_reply.started":"2022-08-05T15:12:54.174491Z","shell.execute_reply":"2022-08-05T15:12:54.198951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Handling the missing data","metadata":{}},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.202243Z","iopub.execute_input":"2022-08-05T15:12:54.202751Z","iopub.status.idle":"2022-08-05T15:12:54.214233Z","shell.execute_reply.started":"2022-08-05T15:12:54.202703Z","shell.execute_reply":"2022-08-05T15:12:54.213057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"HomePlanet\"].fillna(\"Earth\",inplace=True)\ntest_data[\"Destination\"].fillna(\"TRAPPIST-1e\",inplace=True)\ntest_data[\"CryoSleep\"].fillna(test_data[\"CryoSleep\"].mode()[0], inplace=True)\ntest_data[\"VIP\"].fillna(test_data[\"VIP\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.215948Z","iopub.execute_input":"2022-08-05T15:12:54.216743Z","iopub.status.idle":"2022-08-05T15:12:54.229220Z","shell.execute_reply.started":"2022-08-05T15:12:54.216704Z","shell.execute_reply":"2022-08-05T15:12:54.228152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"RoomService\"].fillna(test_data[\"RoomService\"].median(), inplace=True)\ntest_data[\"FoodCourt\"].fillna(test_data[\"FoodCourt\"].median(), inplace=True)\ntest_data[\"ShoppingMall\"].fillna(test_data[\"ShoppingMall\"].median(), inplace=True)\ntest_data[\"Spa\"].fillna(test_data[\"Spa\"].median(), inplace=True)\ntest_data[\"VRDeck\"].fillna(test_data[\"VRDeck\"].median(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.231134Z","iopub.execute_input":"2022-08-05T15:12:54.231973Z","iopub.status.idle":"2022-08-05T15:12:54.243230Z","shell.execute_reply.started":"2022-08-05T15:12:54.231935Z","shell.execute_reply":"2022-08-05T15:12:54.241881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"Age\"].fillna(test_data[\"Age\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.244439Z","iopub.execute_input":"2022-08-05T15:12:54.245645Z","iopub.status.idle":"2022-08-05T15:12:54.252470Z","shell.execute_reply.started":"2022-08-05T15:12:54.245600Z","shell.execute_reply":"2022-08-05T15:12:54.251239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Separating Deck,Cabin,and Port side values and storing them in new columns","metadata":{}},{"cell_type":"code","source":"test_cabin_data = test_data[\"Cabin\"].str.split(\"/\", n=2, expand=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.254214Z","iopub.execute_input":"2022-08-05T15:12:54.254827Z","iopub.status.idle":"2022-08-05T15:12:54.275659Z","shell.execute_reply.started":"2022-08-05T15:12:54.254789Z","shell.execute_reply":"2022-08-05T15:12:54.274597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_cabin_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.276852Z","iopub.execute_input":"2022-08-05T15:12:54.277911Z","iopub.status.idle":"2022-08-05T15:12:54.295978Z","shell.execute_reply.started":"2022-08-05T15:12:54.277854Z","shell.execute_reply":"2022-08-05T15:12:54.295049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"Deck\"]=test_cabin_data[0]\ntest_data[\"Number\"]=test_cabin_data[1]\ntest_data[\"Side\"]=test_cabin_data[2]","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.297271Z","iopub.execute_input":"2022-08-05T15:12:54.297845Z","iopub.status.idle":"2022-08-05T15:12:54.310789Z","shell.execute_reply.started":"2022-08-05T15:12:54.297796Z","shell.execute_reply":"2022-08-05T15:12:54.309791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.311995Z","iopub.execute_input":"2022-08-05T15:12:54.313197Z","iopub.status.idle":"2022-08-05T15:12:54.340304Z","shell.execute_reply.started":"2022-08-05T15:12:54.313148Z","shell.execute_reply":"2022-08-05T15:12:54.339323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.drop(\"Cabin\", axis=1,inplace=True)   # Dropping columns \"cabin\"","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.341472Z","iopub.execute_input":"2022-08-05T15:12:54.342270Z","iopub.status.idle":"2022-08-05T15:12:54.349579Z","shell.execute_reply.started":"2022-08-05T15:12:54.342233Z","shell.execute_reply":"2022-08-05T15:12:54.348647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Filling the missing values with mode\ntest_data[\"Deck\"].fillna(test_data[\"Deck\"].mode()[0], inplace=True)\ntest_data[\"Side\"].fillna(test_data[\"Side\"].mode()[0], inplace=True)\ntest_data[\"Number\"].fillna(test_data[\"Number\"].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.351214Z","iopub.execute_input":"2022-08-05T15:12:54.351791Z","iopub.status.idle":"2022-08-05T15:12:54.366551Z","shell.execute_reply.started":"2022-08-05T15:12:54.351755Z","shell.execute_reply":"2022-08-05T15:12:54.365251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.367924Z","iopub.execute_input":"2022-08-05T15:12:54.369098Z","iopub.status.idle":"2022-08-05T15:12:54.383702Z","shell.execute_reply.started":"2022-08-05T15:12:54.369046Z","shell.execute_reply":"2022-08-05T15:12:54.382412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Label-encoding","metadata":{}},{"cell_type":"code","source":"# dividing Age values into groups\ntest_data_lst=[test_data]\nfor column in test_data_lst:\n    column.loc[(column['Age']>=0) & (column['Age']<=1), \"Age_category\"]=\"Infant\"\n    column.loc[(column['Age']>=2) & (column['Age']<=4), \"Age_category\"]=\"Toddler\"\n    column.loc[(column['Age']>=5) & (column['Age']<=12), \"Age_category\"]=\"Child\"\n    column.loc[(column['Age']>=13) & (column['Age']<=19), \"Age_category\"]=\"Teen\"\n    column.loc[(column['Age']>=20) & (column['Age']<=39), \"Age_category\"]=\"Adult\"\n    column.loc[(column['Age']>=40) & (column['Age']<=59), \"Age_category\"]=\"Middle Age Adult\"\n    column.loc[(column['Age']>=60) ,\"Age_category\"]=\"Senior Adult\"\n\ntest_data['Age_category'] = test_data['Age_category'].astype(\"category\")","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.385551Z","iopub.execute_input":"2022-08-05T15:12:54.386157Z","iopub.status.idle":"2022-08-05T15:12:54.408137Z","shell.execute_reply.started":"2022-08-05T15:12:54.386119Z","shell.execute_reply":"2022-08-05T15:12:54.406511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.drop(\"Age\", axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.409894Z","iopub.execute_input":"2022-08-05T15:12:54.410290Z","iopub.status.idle":"2022-08-05T15:12:54.418588Z","shell.execute_reply.started":"2022-08-05T15:12:54.410256Z","shell.execute_reply":"2022-08-05T15:12:54.417591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_data= test_data.copy()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.419716Z","iopub.execute_input":"2022-08-05T15:12:54.420689Z","iopub.status.idle":"2022-08-05T15:12:54.433589Z","shell.execute_reply.started":"2022-08-05T15:12:54.420614Z","shell.execute_reply":"2022-08-05T15:12:54.432293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.435153Z","iopub.execute_input":"2022-08-05T15:12:54.435871Z","iopub.status.idle":"2022-08-05T15:12:54.460383Z","shell.execute_reply.started":"2022-08-05T15:12:54.435828Z","shell.execute_reply":"2022-08-05T15:12:54.459383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.461722Z","iopub.execute_input":"2022-08-05T15:12:54.462089Z","iopub.status.idle":"2022-08-05T15:12:54.479409Z","shell.execute_reply.started":"2022-08-05T15:12:54.462056Z","shell.execute_reply":"2022-08-05T15:12:54.478081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lst_of_test_col=['HomePlanet', 'CryoSleep', 'Destination', 'VIP','Deck', 'Side', 'Age_category']\nfor i in lst_of_test_col:\n    new_test_data[i]=new_test_data[i].astype(\"category\")\n    new_test_data[i]=new_test_data[i].cat.codes ","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.481062Z","iopub.execute_input":"2022-08-05T15:12:54.481630Z","iopub.status.idle":"2022-08-05T15:12:54.499291Z","shell.execute_reply.started":"2022-08-05T15:12:54.481593Z","shell.execute_reply":"2022-08-05T15:12:54.498013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# one hot encoding\nlst_of_test_col_two=['HomePlanet','Destination','Deck','Age_category']\nfor i in lst_of_test_col_two:\n    new_test_data=pd.get_dummies(new_test_data, columns=[i],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.501077Z","iopub.execute_input":"2022-08-05T15:12:54.501445Z","iopub.status.idle":"2022-08-05T15:12:54.528635Z","shell.execute_reply.started":"2022-08-05T15:12:54.501412Z","shell.execute_reply":"2022-08-05T15:12:54.527383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.530563Z","iopub.execute_input":"2022-08-05T15:12:54.531239Z","iopub.status.idle":"2022-08-05T15:12:54.559946Z","shell.execute_reply.started":"2022-08-05T15:12:54.531198Z","shell.execute_reply":"2022-08-05T15:12:54.558659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# standardization\nfrom sklearn.preprocessing import StandardScaler\nsc = StandardScaler()\nnew_test_scaled = sc.fit_transform(new_test_data)\nnew_test_scaled","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.561497Z","iopub.execute_input":"2022-08-05T15:12:54.561971Z","iopub.status.idle":"2022-08-05T15:12:54.600963Z","shell.execute_reply.started":"2022-08-05T15:12:54.561935Z","shell.execute_reply":"2022-08-05T15:12:54.599405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_scaled = pd.DataFrame(new_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.604795Z","iopub.execute_input":"2022-08-05T15:12:54.605193Z","iopub.status.idle":"2022-08-05T15:12:54.611271Z","shell.execute_reply.started":"2022-08-05T15:12:54.605159Z","shell.execute_reply":"2022-08-05T15:12:54.610088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test_scaled","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.612636Z","iopub.execute_input":"2022-08-05T15:12:54.613030Z","iopub.status.idle":"2022-08-05T15:12:54.656037Z","shell.execute_reply.started":"2022-08-05T15:12:54.612995Z","shell.execute_reply":"2022-08-05T15:12:54.654638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predicting the values using the model\ny_pred_new_test_xgb = xgb.predict(new_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.657905Z","iopub.execute_input":"2022-08-05T15:12:54.658491Z","iopub.status.idle":"2022-08-05T15:12:54.675146Z","shell.execute_reply.started":"2022-08-05T15:12:54.658451Z","shell.execute_reply":"2022-08-05T15:12:54.674005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_new_test_xgb","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.688000Z","iopub.execute_input":"2022-08-05T15:12:54.689087Z","iopub.status.idle":"2022-08-05T15:12:54.698653Z","shell.execute_reply.started":"2022-08-05T15:12:54.689038Z","shell.execute_reply":"2022-08-05T15:12:54.697090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Predicted_data = pd.DataFrame(columns=[\"PassengerId\",\"Transported\"])\nPredicted_data[\"PassengerId\"] = indexcol\nPredicted_data.set_index('PassengerId')\nPredicted_data[\"Transported\"] = xgb.predict(new_test_scaled).astype(bool)\nPredicted_data","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.700350Z","iopub.execute_input":"2022-08-05T15:12:54.700772Z","iopub.status.idle":"2022-08-05T15:12:54.739561Z","shell.execute_reply.started":"2022-08-05T15:12:54.700733Z","shell.execute_reply":"2022-08-05T15:12:54.738640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Predicted_data.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T15:12:54.742223Z","iopub.execute_input":"2022-08-05T15:12:54.742617Z","iopub.status.idle":"2022-08-05T15:12:54.755151Z","shell.execute_reply.started":"2022-08-05T15:12:54.742583Z","shell.execute_reply":"2022-08-05T15:12:54.753788Z"},"trusted":true},"execution_count":null,"outputs":[]}]}