{"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":"import pandas as pd\nimport numpy as np\nfrom sklearn.preprocessing import LabelEncoder\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split,GridSearchCV\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import accuracy_score\nfrom sklearn import svm\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.neighbors  import KNeighborsClassifier\nfrom catboost import CatBoostClassifier\nfrom sklearn.linear_model import RidgeClassifier, LogisticRegression\nfrom sklearn.ensemble import VotingClassifier\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom xgboost import XGBClassifier\nfrom lightgbm import LGBMClassifier\nfrom sklearn.ensemble import ExtraTreesClassifier","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-25T16:42:31.705778Z","iopub.execute_input":"2022-07-25T16:42:31.706387Z","iopub.status.idle":"2022-07-25T16:42:34.121629Z","shell.execute_reply.started":"2022-07-25T16:42:31.706267Z","shell.execute_reply":"2022-07-25T16:42:34.120422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Reading the training and the testing data**","metadata":{}},{"cell_type":"code","source":"train=pd.read_csv(\"../input/spaceship-titanic/train.csv\")\npred=pd.read_csv(\"../input/spaceship-titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.125043Z","iopub.execute_input":"2022-07-25T16:42:34.125498Z","iopub.status.idle":"2022-07-25T16:42:34.211015Z","shell.execute_reply.started":"2022-07-25T16:42:34.125454Z","shell.execute_reply":"2022-07-25T16:42:34.210005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Displaying the top 10 data in training and testing data**","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.212183Z","iopub.execute_input":"2022-07-25T16:42:34.212600Z","iopub.status.idle":"2022-07-25T16:42:34.244999Z","shell.execute_reply.started":"2022-07-25T16:42:34.212558Z","shell.execute_reply":"2022-07-25T16:42:34.243730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.247730Z","iopub.execute_input":"2022-07-25T16:42:34.248100Z","iopub.status.idle":"2022-07-25T16:42:34.269253Z","shell.execute_reply.started":"2022-07-25T16:42:34.248067Z","shell.execute_reply":"2022-07-25T16:42:34.268172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#number of rows in test and train\nprint(\"Number of rows in Train dataset: \",train.shape[0], \" Number of rows in Test dataset: \", pred.shape[0])","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.270701Z","iopub.execute_input":"2022-07-25T16:42:34.271328Z","iopub.status.idle":"2022-07-25T16:42:34.280704Z","shell.execute_reply.started":"2022-07-25T16:42:34.271295Z","shell.execute_reply":"2022-07-25T16:42:34.279425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#number of columns in test and train\nprint(\"Number of columns in Train dataset: \",pred.shape[1], \" Number of columns in Test dataset: \", pred.shape[1])","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.282315Z","iopub.execute_input":"2022-07-25T16:42:34.282957Z","iopub.status.idle":"2022-07-25T16:42:34.291697Z","shell.execute_reply.started":"2022-07-25T16:42:34.282923Z","shell.execute_reply":"2022-07-25T16:42:34.290841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Information about the training dataset\ntrain.describe(include=\"all\")","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.293114Z","iopub.execute_input":"2022-07-25T16:42:34.293697Z","iopub.status.idle":"2022-07-25T16:42:34.385339Z","shell.execute_reply.started":"2022-07-25T16:42:34.293663Z","shell.execute_reply":"2022-07-25T16:42:34.384182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Cleaning the dataset:**\n1.     Removing the Null values\n2.     Dropping the unwanted columns\n3.     Adding New columns if needed\n4.     Formatting the columns","metadata":{}},{"cell_type":"code","source":"#to find the percentage of null:\ndef percentagenull(df):\n    percentage= ((df.isna().sum()/df.isna().count())*100).sort_values(ascending=False)\n    count= df.isna().sum().sort_values(ascending=False)\n    dfff= pd.concat([count, percentage], axis=1,keys=['the Count', 'Percentage of null'])\n    return dfff\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.387040Z","iopub.execute_input":"2022-07-25T16:42:34.387731Z","iopub.status.idle":"2022-07-25T16:42:34.395463Z","shell.execute_reply.started":"2022-07-25T16:42:34.387685Z","shell.execute_reply":"2022-07-25T16:42:34.394645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percentagenull(train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.397199Z","iopub.execute_input":"2022-07-25T16:42:34.398035Z","iopub.status.idle":"2022-07-25T16:42:34.444031Z","shell.execute_reply.started":"2022-07-25T16:42:34.397988Z","shell.execute_reply":"2022-07-25T16:42:34.442823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percentagenull(pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.448637Z","iopub.execute_input":"2022-07-25T16:42:34.449182Z","iopub.status.idle":"2022-07-25T16:42:34.475525Z","shell.execute_reply.started":"2022-07-25T16:42:34.449133Z","shell.execute_reply":"2022-07-25T16:42:34.474720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**We can see that every columns has equal percentage of null**","metadata":{}},{"cell_type":"code","source":"#Replacing the null data in dataset with the null string before spliting them into new columns\ntrain.replace(np.nan, \"null\", inplace=True)\npred.replace(np.nan, \"null\", inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.476764Z","iopub.execute_input":"2022-07-25T16:42:34.477946Z","iopub.status.idle":"2022-07-25T16:42:34.508498Z","shell.execute_reply.started":"2022-07-25T16:42:34.477897Z","shell.execute_reply":"2022-07-25T16:42:34.507356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**We can see that the cabin is of format Deck/num/side. So going to split separately and make them into columns**","metadata":{}},{"cell_type":"code","source":"# Creating a function to create new columns (can use split function - but this for deeper understanding)\ndef addcolumns(df):\n    li=\"\"\n    f=[]\n    mm=\"\"\n    m=[]\n    l=[]\n    for value in df[\"Cabin\"].tolist():\n        if value == \"null\":\n            f.append('null')\n            m.append('null')\n            l.append('null')\n        else:    \n            li=li+value\n    \n            f.append(li[0])\n            for j in range(2,len(li)):\n                if li[j] == '/':\n                    break\n                else:\n                    mm=mm+li[j]\n            m.append(mm)\n            l.append(li[j+1])\n            li=\"\"\n            mm=\"\"\n    deck=pd.DataFrame(f, columns=[\"Deck\"])\n    num=pd.DataFrame(m,columns=[\"Num\"])\n    side=pd.DataFrame(l,columns=[\"Side\"])\n    df1=pd.concat([deck,num,side],axis=1)\n    df=pd.concat([df, df1], axis=1)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.509834Z","iopub.execute_input":"2022-07-25T16:42:34.510170Z","iopub.status.idle":"2022-07-25T16:42:34.520960Z","shell.execute_reply.started":"2022-07-25T16:42:34.510140Z","shell.execute_reply":"2022-07-25T16:42:34.519917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=addcolumns(train)\npred=addcolumns(pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.522691Z","iopub.execute_input":"2022-07-25T16:42:34.523379Z","iopub.status.idle":"2022-07-25T16:42:34.573066Z","shell.execute_reply.started":"2022-07-25T16:42:34.523333Z","shell.execute_reply":"2022-07-25T16:42:34.572125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Seeing the new columns added\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.576175Z","iopub.execute_input":"2022-07-25T16:42:34.576646Z","iopub.status.idle":"2022-07-25T16:42:34.600623Z","shell.execute_reply.started":"2022-07-25T16:42:34.576599Z","shell.execute_reply":"2022-07-25T16:42:34.599463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Dropping cabin as they are not required from here onwards\ntrain.drop('Cabin', axis=1, inplace=True)\npred.drop('Cabin', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.602158Z","iopub.execute_input":"2022-07-25T16:42:34.603239Z","iopub.status.idle":"2022-07-25T16:42:34.620188Z","shell.execute_reply.started":"2022-07-25T16:42:34.603193Z","shell.execute_reply":"2022-07-25T16:42:34.619189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Dropping PassengerId and Name as they dont have any pattern and they are unique\ntrain.drop('PassengerId', axis=1, inplace=True)\npred.drop('PassengerId', axis=1, inplace=True)\ntrain.drop('Name', axis=1, inplace=True)\npred.drop('Name', axis=1, inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.623069Z","iopub.execute_input":"2022-07-25T16:42:34.623527Z","iopub.status.idle":"2022-07-25T16:42:34.640391Z","shell.execute_reply.started":"2022-07-25T16:42:34.623481Z","shell.execute_reply":"2022-07-25T16:42:34.639253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.641687Z","iopub.execute_input":"2022-07-25T16:42:34.642483Z","iopub.status.idle":"2022-07-25T16:42:34.652812Z","shell.execute_reply.started":"2022-07-25T16:42:34.642437Z","shell.execute_reply":"2022-07-25T16:42:34.651643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Converting the object to numeric for fitting","metadata":{}},{"cell_type":"code","source":"#Deck distribution with respect to transportation\nsns.countplot(x='Deck', data=train, hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.654409Z","iopub.execute_input":"2022-07-25T16:42:34.655931Z","iopub.status.idle":"2022-07-25T16:42:34.980811Z","shell.execute_reply.started":"2022-07-25T16:42:34.655879Z","shell.execute_reply":"2022-07-25T16:42:34.979437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using label encoder to convert category to numeric (Other methods: get_dummies, map)\nle=LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.982509Z","iopub.execute_input":"2022-07-25T16:42:34.983629Z","iopub.status.idle":"2022-07-25T16:42:34.989428Z","shell.execute_reply.started":"2022-07-25T16:42:34.983569Z","shell.execute_reply":"2022-07-25T16:42:34.988214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"HomePlanet\"]=le.fit_transform(train[\"HomePlanet\"])\n\ntrain[\"Destination\"]=le.fit_transform(train[\"Destination\"])\n\ntrain[\"VIP\"].replace('null', train.VIP.mode()[0], inplace=True)\n\ntrain[\"VIP\"]=le.fit_transform(train[\"VIP\"])\n\ntrain[\"CryoSleep\"].replace('null', train.CryoSleep.mode()[0], inplace=True)\n\ntrain[\"CryoSleep\"]=le.fit_transform(train[\"CryoSleep\"])\n\ntrain[\"Transported\"].replace('null', train.Transported.mode()[0], inplace=True)\n\ntrain[\"Transported\"]=le.fit_transform(train[\"Transported\"])\n\ntrain[\"Age\"].replace('null', '0.0', inplace=True)\n\ntrain[\"Age\"]=train[\"Age\"].astype(\"float\")\n","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:34.992113Z","iopub.execute_input":"2022-07-25T16:42:34.993183Z","iopub.status.idle":"2022-07-25T16:42:35.026478Z","shell.execute_reply.started":"2022-07-25T16:42:34.993140Z","shell.execute_reply":"2022-07-25T16:42:35.025145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Replacing the NUll with their respective mean values\ntrain[\"Age\"].replace('0.0', train.Age.mean(), inplace=True)\n\ntrain[\"RoomService\"].replace('null', '0.0', inplace=True)\n\ntrain[\"FoodCourt\"].replace('null', '0.0', inplace=True)\ntrain[\"ShoppingMall\"].replace('null', '0.0', inplace=True)\ntrain[\"Spa\"].replace('null', '0.0', inplace=True)\ntrain[\"VRDeck\"].replace('null', '0.0', inplace=True)\n\ntrain[\"FoodCourt\"]=train[\"FoodCourt\"].astype(\"float\")\ntrain[\"ShoppingMall\"]=train[\"ShoppingMall\"].astype(\"float\")\ntrain[\"Spa\"]=train[\"Spa\"].astype(\"float\")\ntrain[\"VRDeck\"]=train[\"VRDeck\"].astype(\"float\")\ntrain[\"RoomService\"]=train[\"RoomService\"].astype(\"float\")","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.027918Z","iopub.execute_input":"2022-07-25T16:42:35.028591Z","iopub.status.idle":"2022-07-25T16:42:35.053724Z","shell.execute_reply.started":"2022-07-25T16:42:35.028555Z","shell.execute_reply":"2022-07-25T16:42:35.052457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Replacing null with their mode and converting to numeric using LabelEncoder\ntrain[\"Deck\"].replace('null',train[\"Deck\"].mode()[0] , inplace=True)\ntrain[\"Num\"].replace('null', train[\"Num\"].mode()[0], inplace=True)\ntrain[\"Side\"].replace('null', train[\"Side\"].mode()[0], inplace=True)\n\ntrain[\"Deck\"]=le.fit_transform(train[\"Deck\"])\ntrain[\"Num\"]=le.fit_transform(train[\"Num\"])\ntrain[\"Side\"]=le.fit_transform(train[\"Side\"])","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.055170Z","iopub.execute_input":"2022-07-25T16:42:35.055658Z","iopub.status.idle":"2022-07-25T16:42:35.086650Z","shell.execute_reply.started":"2022-07-25T16:42:35.055624Z","shell.execute_reply":"2022-07-25T16:42:35.085758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Following the above process for the prediction dataset\n\npred[\"HomePlanet\"]=le.fit_transform(pred[\"HomePlanet\"])\n\npred[\"Destination\"]=le.fit_transform(pred[\"Destination\"])\n\npred[\"VIP\"].replace('null', pred.VIP.mode()[0], inplace=True)\n\npred[\"VIP\"]=le.fit_transform(pred[\"VIP\"])\n\npred[\"CryoSleep\"].replace('null', pred.CryoSleep.mode()[0], inplace=True)\n\npred[\"CryoSleep\"]=le.fit_transform(pred[\"CryoSleep\"])\n\n\n\npred[\"Age\"].replace('null', '0.0', inplace=True)\n\npred[\"Age\"]=pred[\"Age\"].astype(\"float\")\npred[\"Age\"].replace('0.0', pred.Age.mean(), inplace=True)\n\npred[\"RoomService\"].replace('null', '0.0', inplace=True)\n\npred[\"FoodCourt\"].replace('null', '0.0', inplace=True)\npred[\"ShoppingMall\"].replace('null', '0.0', inplace=True)\npred[\"Spa\"].replace('null', '0.0', inplace=True)\npred[\"VRDeck\"].replace('null', '0.0', inplace=True)\n\npred[\"FoodCourt\"]=pred[\"FoodCourt\"].astype(\"float\")\npred[\"ShoppingMall\"]=pred[\"ShoppingMall\"].astype(\"float\")\npred[\"Spa\"]=pred[\"Spa\"].astype(\"float\")\npred[\"VRDeck\"]=pred[\"VRDeck\"].astype(\"float\")\npred[\"RoomService\"]=pred[\"RoomService\"].astype(\"float\")\n\n\npred[\"Deck\"].replace('null',pred[\"Deck\"].mode()[0] , inplace=True)\npred[\"Num\"].replace('null', pred[\"Num\"].mode()[0], inplace=True)\npred[\"Side\"].replace('null', pred[\"Side\"].mode()[0], inplace=True)\n\npred[\"Deck\"]=le.fit_transform(pred[\"Deck\"])\npred[\"Num\"]=le.fit_transform(pred[\"Num\"])\npred[\"Side\"]=le.fit_transform(pred[\"Side\"])","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.088049Z","iopub.execute_input":"2022-07-25T16:42:35.088408Z","iopub.status.idle":"2022-07-25T16:42:35.140539Z","shell.execute_reply.started":"2022-07-25T16:42:35.088379Z","shell.execute_reply":"2022-07-25T16:42:35.139211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Viewing information about the training dataset after the cleaning\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.144619Z","iopub.execute_input":"2022-07-25T16:42:35.145129Z","iopub.status.idle":"2022-07-25T16:42:35.168187Z","shell.execute_reply.started":"2022-07-25T16:42:35.145090Z","shell.execute_reply":"2022-07-25T16:42:35.166936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Viewing information about the prediction dataset after the cleaning\npred.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.298548Z","iopub.execute_input":"2022-07-25T16:42:35.298971Z","iopub.status.idle":"2022-07-25T16:42:35.319045Z","shell.execute_reply.started":"2022-07-25T16:42:35.298935Z","shell.execute_reply":"2022-07-25T16:42:35.318140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Feature Importance:**\n1.     Using heatmap to detect the correlaion between features","metadata":{}},{"cell_type":"code","source":"x=train[['HomePlanet',\n 'CryoSleep',\n 'Destination',\n 'Age',\n 'VIP',\n 'RoomService',\n 'FoodCourt',\n 'ShoppingMall',\n 'Spa',\n 'VRDeck',\n 'Deck',\n 'Num',\n 'Side']]\ny=train['Transported']","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.381890Z","iopub.execute_input":"2022-07-25T16:42:35.382796Z","iopub.status.idle":"2022-07-25T16:42:35.392346Z","shell.execute_reply.started":"2022-07-25T16:42:35.382759Z","shell.execute_reply":"2022-07-25T16:42:35.391203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(40, 25))\nsns.heatmap(train.corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:35.439488Z","iopub.execute_input":"2022-07-25T16:42:35.440099Z","iopub.status.idle":"2022-07-25T16:42:36.839780Z","shell.execute_reply.started":"2022-07-25T16:42:35.440066Z","shell.execute_reply":"2022-07-25T16:42:36.838792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Distribution of Age\nplt.figure(figsize=(20,8))\nsns.histplot(train.Age)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:36.841428Z","iopub.execute_input":"2022-07-25T16:42:36.842256Z","iopub.status.idle":"2022-07-25T16:42:37.176154Z","shell.execute_reply.started":"2022-07-25T16:42:36.842220Z","shell.execute_reply":"2022-07-25T16:42:37.174937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.regplot(train['CryoSleep'], train['Transported'], data=train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:37.177752Z","iopub.execute_input":"2022-07-25T16:42:37.178206Z","iopub.status.idle":"2022-07-25T16:42:38.002091Z","shell.execute_reply.started":"2022-07-25T16:42:37.178167Z","shell.execute_reply":"2022-07-25T16:42:38.000930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From above plot we can see that CryoSleep is positvely correlated to Transportation**","metadata":{}},{"cell_type":"code","source":"#Try this merge function for your chances of increasing the score. If you get it please comment me ;)\ndef merges(df):\n    relatives=[]\n    for i in df[\"FoodCourt\"].values.tolist():\n        relatives.append(i)\n    relatives1=[]\n    for i in df[\"ShoppingMall\"].values.tolist():\n        relatives1.append(i) \n    relatives2=[]\n    for i in df[\"Spa\"].values.tolist():\n        relatives2.append(i)\n    relatives3=[]\n    for i in df[\"VRDeck\"].values.tolist():\n        relatives3.append(i) \n    relatives4=[]\n    for i in df[\"RoomService\"].values.tolist():\n        relatives4.append(i)     \n    re=[]\n\n    for i in range(0, len(relatives)):\n        re.append(relatives[i]+relatives1[i]+relatives2[i]+relatives3[i]+relatives4[i])  \n    df1=pd.DataFrame(re, columns=['Price Spent'])   \n    df= pd.concat([df, df1], axis=1)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:38.005363Z","iopub.execute_input":"2022-07-25T16:42:38.006145Z","iopub.status.idle":"2022-07-25T16:42:38.019283Z","shell.execute_reply.started":"2022-07-25T16:42:38.006105Z","shell.execute_reply":"2022-07-25T16:42:38.017925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pred=merges(pred)\n#train=merges(train)\n\n#train.drop(['RoomService', 'FoodCourt','ShoppingMall','Spa','VRDeck'], axis=1, inplace=True)\n#pred.drop(['RoomService', 'FoodCourt','ShoppingMall','Spa','VRDeck'], axis=1, inplace=True)\n\n#train.drop(['VIP', 'ShoppingMall'], axis=1, inplace=True)\n#pred.drop(['VIP', 'ShoppingMall'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:38.021948Z","iopub.execute_input":"2022-07-25T16:42:38.023299Z","iopub.status.idle":"2022-07-25T16:42:38.034459Z","shell.execute_reply.started":"2022-07-25T16:42:38.023252Z","shell.execute_reply":"2022-07-25T16:42:38.033214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Preprocessing the data**","metadata":{}},{"cell_type":"code","source":"X_train, X_test, y_train, y_test= train_test_split(x, y, test_size=0.2, random_state=1)\nX_train=StandardScaler().fit_transform(X_train)\nX_test=StandardScaler().fit_transform(X_test)\npred=StandardScaler().fit_transform(pred)\ntrain.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:38.037698Z","iopub.execute_input":"2022-07-25T16:42:38.038589Z","iopub.status.idle":"2022-07-25T16:42:38.069516Z","shell.execute_reply.started":"2022-07-25T16:42:38.038540Z","shell.execute_reply":"2022-07-25T16:42:38.068208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **DIFFERENT ML MODELS AND THEIR ACCURACY SCORE**","metadata":{}},{"cell_type":"markdown","source":"# **Logistic Regression:**","metadata":{}},{"cell_type":"code","source":"lr = LogisticRegression()\nparams = { \"penalty\": (\"l1\", \"l2\", \"elasticnet\"), \"tol\": (0.1, 0.01, 0.001, 0.0001), \"C\": (10.0, 1.0, 0.1, 0.01)}\nmodelLR = GridSearchCV(lr, params, cv=10)\nmodelLR.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:38.071199Z","iopub.execute_input":"2022-07-25T16:42:38.071514Z","iopub.status.idle":"2022-07-25T16:42:43.171364Z","shell.execute_reply.started":"2022-07-25T16:42:38.071485Z","shell.execute_reply":"2022-07-25T16:42:43.170074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelLR.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:43.173377Z","iopub.execute_input":"2022-07-25T16:42:43.174173Z","iopub.status.idle":"2022-07-25T16:42:43.188159Z","shell.execute_reply.started":"2022-07-25T16:42:43.174108Z","shell.execute_reply":"2022-07-25T16:42:43.186871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Cat Boost:**","metadata":{}},{"cell_type":"code","source":"modelCT=CatBoostClassifier(verbose = 0)\nmodelCT.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:43.190397Z","iopub.execute_input":"2022-07-25T16:42:43.191393Z","iopub.status.idle":"2022-07-25T16:42:46.807177Z","shell.execute_reply.started":"2022-07-25T16:42:43.191339Z","shell.execute_reply":"2022-07-25T16:42:46.805980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelCT.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:46.812351Z","iopub.execute_input":"2022-07-25T16:42:46.812712Z","iopub.status.idle":"2022-07-25T16:42:46.827340Z","shell.execute_reply.started":"2022-07-25T16:42:46.812679Z","shell.execute_reply":"2022-07-25T16:42:46.825836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Voting Classifier:**","metadata":{}},{"cell_type":"code","source":"models = {'catboost':CatBoostClassifier(verbose = 0),\n           'gbc':GradientBoostingClassifier(),\n           'ridge':RidgeClassifier(),\n           'lr':LogisticRegression()}\n\nestimators = [('catboost', CatBoostClassifier(verbose = 0)), ('gbc', GradientBoostingClassifier()),  ('lr', LogisticRegression())]\nmodelVC = VotingClassifier(estimators=estimators, voting='soft', weights=[1, 1, 1])\nmodelVC.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:46.829236Z","iopub.execute_input":"2022-07-25T16:42:46.829729Z","iopub.status.idle":"2022-07-25T16:42:51.311010Z","shell.execute_reply.started":"2022-07-25T16:42:46.829691Z","shell.execute_reply":"2022-07-25T16:42:51.309547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelVC.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:51.312548Z","iopub.execute_input":"2022-07-25T16:42:51.313004Z","iopub.status.idle":"2022-07-25T16:42:51.345325Z","shell.execute_reply.started":"2022-07-25T16:42:51.312959Z","shell.execute_reply":"2022-07-25T16:42:51.341291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **LGBM Classifier:**","metadata":{}},{"cell_type":"code","source":"modelLGBM=LGBMClassifier(max_depth=6, random_state=314, silent=True, metric='None', n_jobs=6)\n\n\nmodelLGBM.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:51.347130Z","iopub.execute_input":"2022-07-25T16:42:51.347898Z","iopub.status.idle":"2022-07-25T16:42:52.086135Z","shell.execute_reply.started":"2022-07-25T16:42:51.347829Z","shell.execute_reply":"2022-07-25T16:42:52.084946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelLGBM.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:52.087637Z","iopub.execute_input":"2022-07-25T16:42:52.088261Z","iopub.status.idle":"2022-07-25T16:42:52.103182Z","shell.execute_reply.started":"2022-07-25T16:42:52.088215Z","shell.execute_reply":"2022-07-25T16:42:52.101703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **SVM:**","metadata":{}},{"cell_type":"code","source":"modelSVM=svm.SVC(kernel='rbf')\nmodelSVM.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:52.106882Z","iopub.execute_input":"2022-07-25T16:42:52.107563Z","iopub.status.idle":"2022-07-25T16:42:53.921543Z","shell.execute_reply.started":"2022-07-25T16:42:52.107525Z","shell.execute_reply":"2022-07-25T16:42:53.920238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelSVM.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:53.922906Z","iopub.execute_input":"2022-07-25T16:42:53.923341Z","iopub.status.idle":"2022-07-25T16:42:54.343551Z","shell.execute_reply.started":"2022-07-25T16:42:53.923307Z","shell.execute_reply":"2022-07-25T16:42:54.342311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Decision Tree Classifier:**","metadata":{}},{"cell_type":"code","source":"modelDTC=DecisionTreeClassifier(criterion=\"entropy\")\nmodelDTC.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:54.345230Z","iopub.execute_input":"2022-07-25T16:42:54.345554Z","iopub.status.idle":"2022-07-25T16:42:54.397839Z","shell.execute_reply.started":"2022-07-25T16:42:54.345524Z","shell.execute_reply":"2022-07-25T16:42:54.396767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelDTC.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:54.399316Z","iopub.execute_input":"2022-07-25T16:42:54.399644Z","iopub.status.idle":"2022-07-25T16:42:54.406531Z","shell.execute_reply.started":"2022-07-25T16:42:54.399615Z","shell.execute_reply":"2022-07-25T16:42:54.405353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **KNeighbors Classifier:**","metadata":{}},{"cell_type":"code","source":"n=KNeighborsClassifier(n_neighbors=3)\nn.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:54.408947Z","iopub.execute_input":"2022-07-25T16:42:54.409321Z","iopub.status.idle":"2022-07-25T16:42:54.430274Z","shell.execute_reply.started":"2022-07-25T16:42:54.409290Z","shell.execute_reply":"2022-07-25T16:42:54.429055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(n.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:54.431984Z","iopub.execute_input":"2022-07-25T16:42:54.432813Z","iopub.status.idle":"2022-07-25T16:42:54.653448Z","shell.execute_reply.started":"2022-07-25T16:42:54.432764Z","shell.execute_reply":"2022-07-25T16:42:54.652574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"report = pd.DataFrame({\n    \"Model\" : [\"Logistic Regression\",\"Cat Boost\",\"Voting Classifier\", \"LGBM Classifier\", \"SVM\", \"Decision Tree Classifier\", \"KNeighborsClassifier\"],\n    \"Accuracy score\" : [accuracy_score(modelLR.predict(X_test),y_test),accuracy_score(modelCT.predict(X_test),y_test),accuracy_score(modelVC.predict(X_test),y_test),accuracy_score(modelLGBM.predict(X_test),y_test), accuracy_score(modelSVM.predict(X_test),y_test),accuracy_score(modelDTC.predict(X_test),y_test),accuracy_score(n.predict(X_test),y_test)]\n})\nreport.sort_values(by = \"Accuracy score\")","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:54.655008Z","iopub.execute_input":"2022-07-25T16:42:54.655710Z","iopub.status.idle":"2022-07-25T16:42:55.391900Z","shell.execute_reply.started":"2022-07-25T16:42:54.655654Z","shell.execute_reply":"2022-07-25T16:42:55.390812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transportedpred=modelSVM.predict(pred)\n\ntransportedpredframe=pd.DataFrame(transportedpred, columns=['Transported'])\n\ntransportedpredframe['Transported']=transportedpredframe['Transported'].replace(1, \"True\")\n\ntransportedpredframe['Transported']=transportedpredframe['Transported'].replace(0, \"False\")","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:55.393261Z","iopub.execute_input":"2022-07-25T16:42:55.393578Z","iopub.status.idle":"2022-07-25T16:42:56.366038Z","shell.execute_reply.started":"2022-07-25T16:42:55.393549Z","shell.execute_reply":"2022-07-25T16:42:56.364947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transportedpredframe","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:56.367342Z","iopub.execute_input":"2022-07-25T16:42:56.368346Z","iopub.status.idle":"2022-07-25T16:42:56.381312Z","shell.execute_reply.started":"2022-07-25T16:42:56.368311Z","shell.execute_reply":"2022-07-25T16:42:56.379902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred1=pd.read_csv(\"../input/spaceship-titanic/test.csv\")\n\npasse=pred1[\"PassengerId\"]\n\npassee=pd.DataFrame(passe, columns=['PassengerId'])","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:56.382883Z","iopub.execute_input":"2022-07-25T16:42:56.383248Z","iopub.status.idle":"2022-07-25T16:42:56.408159Z","shell.execute_reply.started":"2022-07-25T16:42:56.383216Z","shell.execute_reply":"2022-07-25T16:42:56.407010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=pd.concat([passee,transportedpredframe], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:56.409557Z","iopub.execute_input":"2022-07-25T16:42:56.410087Z","iopub.status.idle":"2022-07-25T16:42:56.416559Z","shell.execute_reply.started":"2022-07-25T16:42:56.410043Z","shell.execute_reply":"2022-07-25T16:42:56.415235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T16:42:56.418593Z","iopub.execute_input":"2022-07-25T16:42:56.419078Z","iopub.status.idle":"2022-07-25T16:42:56.440386Z","shell.execute_reply.started":"2022-07-25T16:42:56.419034Z","shell.execute_reply":"2022-07-25T16:42:56.439314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **THANK YOU SO MUCH FOR VIEWING MY NOTEBOOK. YOUR FEEDBACK IS MORE IMPORTANT FOR MY IMPROVEMENT!**","metadata":{}}]}