{"metadata":{"colab":{"collapsed_sections":["oiqAwJHsYVT1","aTZtGxEWYZeq","KXbnmOBWwC9S","Sm3f7tPCIV9G","l97m9Zs3ZnPA","ykrb8lgPazJM","txLgUNWYRVvW","cTfngtPzXSVl","yjZKq-PK5yLD","dMYt30YvUc3w","D8DyX9d9zRBR","vA6ZFQlTPomY"],"provenance":[],"name":"EDA + PREPROCESSING + MODEL IMPLEMENTATION"},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":38892,"databundleVersionId":4256898,"sourceType":"competition"}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#**IMPORTING LIBRARIES**","metadata":{"id":"oiqAwJHsYVT1"}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom scipy import stats\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"id":"WbSHPDU4OWTy","execution":{"iopub.status.busy":"2024-02-25T15:14:18.580641Z","iopub.execute_input":"2024-02-25T15:14:18.581034Z","iopub.status.idle":"2024-02-25T15:14:21.220894Z","shell.execute_reply.started":"2024-02-25T15:14:18.581003Z","shell.execute_reply":"2024-02-25T15:14:21.219728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**IMPORTING DATA SET**","metadata":{"id":"aTZtGxEWYZeq"}},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/ai511-homeloan-2022/train_data.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/ai511-homeloan-2022/test_data.csv\")\ntest_train_merged=pd.concat([train_data,test_data])","metadata":{"id":"Ov-5k6JKQRtm","execution":{"iopub.status.busy":"2024-02-25T15:14:21.222893Z","iopub.execute_input":"2024-02-25T15:14:21.223435Z","iopub.status.idle":"2024-02-25T15:14:28.076912Z","shell.execute_reply.started":"2024-02-25T15:14:21.223402Z","shell.execute_reply":"2024-02-25T15:14:28.075510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**OVERVIEW OF TRAIN DATASET**","metadata":{"id":"KXbnmOBWwC9S"}},{"cell_type":"markdown","source":"SIZE OF DATASET","metadata":{"id":"84OgVdMiYfyq"}},{"cell_type":"code","source":"format(train_data.shape)","metadata":{"id":"fBXQKXjBQd9c","outputId":"5eda6c6c-8dbe-4667-d21e-9e7244bb8678","execution":{"iopub.status.busy":"2024-02-25T15:14:28.078428Z","iopub.execute_input":"2024-02-25T15:14:28.078883Z","iopub.status.idle":"2024-02-25T15:14:28.089428Z","shell.execute_reply.started":"2024-02-25T15:14:28.078842Z","shell.execute_reply":"2024-02-25T15:14:28.088035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"DESCRIPTION OF DATA","metadata":{"id":"0fOTH4_YYlAp"}},{"cell_type":"code","source":"train_data.describe()","metadata":{"id":"6ueCPKExQlmt","outputId":"0d5fb8f2-9ac5-4c01-d95f-ee9e5e5cdbd0","execution":{"iopub.status.busy":"2024-02-25T15:14:28.092228Z","iopub.execute_input":"2024-02-25T15:14:28.092549Z","iopub.status.idle":"2024-02-25T15:14:29.296223Z","shell.execute_reply.started":"2024-02-25T15:14:28.092522Z","shell.execute_reply":"2024-02-25T15:14:29.295057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ROWS OF DATA","metadata":{"id":"8csjwXd2vsEA"}},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"d3H8I7e_Qul4","outputId":"3827401d-4290-4c84-bfc7-60a5f951612d","execution":{"iopub.status.busy":"2024-02-25T15:14:29.298521Z","iopub.execute_input":"2024-02-25T15:14:29.299362Z","iopub.status.idle":"2024-02-25T15:14:29.330205Z","shell.execute_reply.started":"2024-02-25T15:14:29.299322Z","shell.execute_reply":"2024-02-25T15:14:29.328826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"COLUMNS OF DATA","metadata":{"id":"89Pbq8n-Y5e3"}},{"cell_type":"code","source":"train_data.columns","metadata":{"id":"CvR6ketfQ03k","outputId":"99718069-8fda-4809-db4f-c4dc4e3ec276","execution":{"iopub.status.busy":"2024-02-25T15:14:29.332015Z","iopub.execute_input":"2024-02-25T15:14:29.332587Z","iopub.status.idle":"2024-02-25T15:14:29.348012Z","shell.execute_reply.started":"2024-02-25T15:14:29.332528Z","shell.execute_reply":"2024-02-25T15:14:29.346528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"FIRST FIVE ROWS OF DATA","metadata":{"id":"j2faCw1KZBtR"}},{"cell_type":"code","source":"train_data.head()\n","metadata":{"id":"34YzM_D8Q-3b","outputId":"2b87cb40-a28d-4ef4-dc76-2d64ddc58af7","execution":{"iopub.status.busy":"2024-02-25T15:14:29.349659Z","iopub.execute_input":"2024-02-25T15:14:29.350076Z","iopub.status.idle":"2024-02-25T15:14:29.384604Z","shell.execute_reply.started":"2024-02-25T15:14:29.350037Z","shell.execute_reply":"2024-02-25T15:14:29.383504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train_data.drop(columns=['SK_ID_CURR'])","metadata":{"id":"M6IYX2QqjpiX","execution":{"iopub.status.busy":"2024-02-25T15:14:29.386140Z","iopub.execute_input":"2024-02-25T15:14:29.386847Z","iopub.status.idle":"2024-02-25T15:14:29.489080Z","shell.execute_reply.started":"2024-02-25T15:14:29.386814Z","shell.execute_reply":"2024-02-25T15:14:29.487811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Column which shows ID is not at all relevant in our model. So dropping that column.","metadata":{"id":"ftBHt5MOjz1G"}},{"cell_type":"code","source":"train.head()","metadata":{"id":"BSsDPPRN4RkE","outputId":"0161c733-c0ae-4b9b-ea1e-84e9d789217c","execution":{"iopub.status.busy":"2024-02-25T15:14:29.490635Z","iopub.execute_input":"2024-02-25T15:14:29.490951Z","iopub.status.idle":"2024-02-25T15:14:29.526844Z","shell.execute_reply.started":"2024-02-25T15:14:29.490925Z","shell.execute_reply":"2024-02-25T15:14:29.525408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_rows',None)    #pd by default shows only 10 rows, this will change it to maximum possible rows","metadata":{"id":"cfzDN0p7Chdt","execution":{"iopub.status.busy":"2024-02-25T15:14:29.532141Z","iopub.execute_input":"2024-02-25T15:14:29.533283Z","iopub.status.idle":"2024-02-25T15:14:29.538406Z","shell.execute_reply.started":"2024-02-25T15:14:29.533237Z","shell.execute_reply":"2024-02-25T15:14:29.537511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"UNIQUE VALUES","metadata":{"id":"Qaq24lWODlxU"}},{"cell_type":"code","source":"train.nunique().sort_values()","metadata":{"id":"j2nOGw_eSPm7","outputId":"2ff7c5b9-8f31-4af0-fb2c-5f748b96d592","execution":{"iopub.status.busy":"2024-02-25T15:14:29.540474Z","iopub.execute_input":"2024-02-25T15:14:29.541496Z","iopub.status.idle":"2024-02-25T15:14:30.096213Z","shell.execute_reply.started":"2024-02-25T15:14:29.541451Z","shell.execute_reply":"2024-02-25T15:14:30.095061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**OVERVIEW OF TEST DATASET**","metadata":{"id":"Sm3f7tPCIV9G"}},{"cell_type":"markdown","source":"SIZE OF DATASET","metadata":{"id":"trhycT-PIV9H"}},{"cell_type":"code","source":"format(test_data.shape)","metadata":{"id":"JpdyLXyNIV9H","outputId":"f321ed5a-95bd-4680-e432-c640f379032e","execution":{"iopub.status.busy":"2024-02-25T15:14:30.097744Z","iopub.execute_input":"2024-02-25T15:14:30.098731Z","iopub.status.idle":"2024-02-25T15:14:30.105500Z","shell.execute_reply.started":"2024-02-25T15:14:30.098689Z","shell.execute_reply":"2024-02-25T15:14:30.104490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"DESCRIPTION OF DATA","metadata":{"id":"BMf9k1l-IV9H"}},{"cell_type":"code","source":"test_data.describe()","metadata":{"id":"HvDmrq1PIV9H","outputId":"5660659e-dd2c-4d51-fa1e-2e1e72c0ce6c","execution":{"iopub.status.busy":"2024-02-25T15:14:30.107073Z","iopub.execute_input":"2024-02-25T15:14:30.107759Z","iopub.status.idle":"2024-02-25T15:14:30.993621Z","shell.execute_reply.started":"2024-02-25T15:14:30.107722Z","shell.execute_reply":"2024-02-25T15:14:30.992249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ROWS OF DATA","metadata":{"id":"4thfZGYzIV9H"}},{"cell_type":"code","source":"test_data.info()","metadata":{"id":"VN-F6DjgIV9H","outputId":"78161c2c-53c4-41ef-a475-f797a83de0d9","execution":{"iopub.status.busy":"2024-02-25T15:14:30.995056Z","iopub.execute_input":"2024-02-25T15:14:30.995445Z","iopub.status.idle":"2024-02-25T15:14:31.015630Z","shell.execute_reply.started":"2024-02-25T15:14:30.995416Z","shell.execute_reply":"2024-02-25T15:14:31.014284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"COLUMNS OF DATA","metadata":{"id":"A4TF2UvxIV9I"}},{"cell_type":"code","source":"test_data.columns","metadata":{"id":"MBcAhQr0IV9I","outputId":"a3f1d154-cb8b-4a02-dcb6-5f95921103cf","execution":{"iopub.status.busy":"2024-02-25T15:14:31.017186Z","iopub.execute_input":"2024-02-25T15:14:31.017580Z","iopub.status.idle":"2024-02-25T15:14:31.026373Z","shell.execute_reply.started":"2024-02-25T15:14:31.017528Z","shell.execute_reply":"2024-02-25T15:14:31.024888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"FIRST FIVE ROWS OF DATA","metadata":{"id":"HyNIOWSWIV9I"}},{"cell_type":"code","source":"test_data.head()\n","metadata":{"id":"W2q-DWSHIV9I","outputId":"b0a2237f-2701-404b-b78f-43fc564a5d62","execution":{"iopub.status.busy":"2024-02-25T15:14:31.030489Z","iopub.execute_input":"2024-02-25T15:14:31.030935Z","iopub.status.idle":"2024-02-25T15:14:31.068090Z","shell.execute_reply.started":"2024-02-25T15:14:31.030895Z","shell.execute_reply":"2024-02-25T15:14:31.066976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=test_data.drop(columns=['SK_ID_CURR'])","metadata":{"id":"FOmo5r8sIV9I","execution":{"iopub.status.busy":"2024-02-25T15:14:31.070122Z","iopub.execute_input":"2024-02-25T15:14:31.070530Z","iopub.status.idle":"2024-02-25T15:14:31.128205Z","shell.execute_reply.started":"2024-02-25T15:14:31.070492Z","shell.execute_reply":"2024-02-25T15:14:31.126767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Column which shows ID is not at all relevant in our model. So dropping that column.","metadata":{"id":"qR_BpSTfIV9I"}},{"cell_type":"code","source":"test.head()","metadata":{"id":"Q7tSEeNzIV9I","outputId":"b1e0f470-fd40-4a04-d951-c8f861e39be2","execution":{"iopub.status.busy":"2024-02-25T15:14:31.129877Z","iopub.execute_input":"2024-02-25T15:14:31.130227Z","iopub.status.idle":"2024-02-25T15:14:31.160669Z","shell.execute_reply.started":"2024-02-25T15:14:31.130196Z","shell.execute_reply":"2024-02-25T15:14:31.159537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.nunique().sort_values()","metadata":{"id":"ZILodPTNZIIH","outputId":"4cbe48e2-a299-4653-ed11-992ddb8b65f4","execution":{"iopub.status.busy":"2024-02-25T15:14:31.162129Z","iopub.execute_input":"2024-02-25T15:14:31.162859Z","iopub.status.idle":"2024-02-25T15:14:31.494909Z","shell.execute_reply.started":"2024-02-25T15:14:31.162810Z","shell.execute_reply":"2024-02-25T15:14:31.493907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**TRAIN DATA ANALYSIS**","metadata":{"id":"l97m9Zs3ZnPA"}},{"cell_type":"markdown","source":"PLOTTING TARGET LABEL\n(Did people return loan amount on time?)","metadata":{"id":"tImZthQ9bnZd"}},{"cell_type":"code","source":"plt.figure(figsize=(10,7))\nax=sns.countplot(x='TARGET',data=train)\nfor p in ax.patches:\n        ax.annotate(p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')\nplt.show()","metadata":{"id":"PbTv1cnJUwWX","outputId":"6397106b-7e67-42bc-a776-5c191795f73d","execution":{"iopub.status.busy":"2024-02-25T15:14:31.496198Z","iopub.execute_input":"2024-02-25T15:14:31.496525Z","iopub.status.idle":"2024-02-25T15:14:31.736614Z","shell.execute_reply.started":"2024-02-25T15:14:31.496498Z","shell.execute_reply":"2024-02-25T15:14:31.735807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"0 indicates people who repayed all the installments on time and 1 indicates people who repayed the installment late at least once","metadata":{"id":"bBibA8FgDozH"}},{"cell_type":"markdown","source":"From the above graph, we can infer that a high percentage of people (91.93%) repayed the installments on time, so the target label is highly imbalanced.","metadata":{"id":"piRPG34TiKGn"}},{"cell_type":"markdown","source":"PLOTTING COUNTS OF ALL THE COLUMNS","metadata":{"id":"uJI7KWNo3lUQ"}},{"cell_type":"code","source":"for i in train:\n    if (train[i].dtype=='object'):\n        plt.figure(figsize=(12,7))\n        ax=sns.countplot(data=train,x='TARGET',hue=i)\n        for p in ax.patches:\n              ax.annotate(p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')\n        plt.show()\n","metadata":{"id":"38UARcYhX5Gz","outputId":"9b9dcdb7-e16f-4ec5-de05-2f1ac2328147","execution":{"iopub.status.busy":"2024-02-25T15:14:31.737823Z","iopub.execute_input":"2024-02-25T15:14:31.738384Z","iopub.status.idle":"2024-02-25T15:14:44.064210Z","shell.execute_reply.started":"2024-02-25T15:14:31.738352Z","shell.execute_reply":"2024-02-25T15:14:44.062880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in train:\n    if (len(train[i].unique())>3 and train[i].dtype != 'object'):\n        plt.figure(figsize=(10,7))\n        sns.kdeplot(train.loc[train['TARGET'] == 0, i], label = 'target = 0')\n        sns.kdeplot(train.loc[train['TARGET'] == 1, i], label = 'target = 1')\n        plt.legend()\n        plt.show()","metadata":{"id":"kY1LaCDXPr9o","outputId":"938aa3e6-37a8-44ef-f256-6db28317f627","execution":{"iopub.status.busy":"2024-02-25T15:14:44.066467Z","iopub.execute_input":"2024-02-25T15:14:44.067398Z","iopub.status.idle":"2024-02-25T15:15:57.451423Z","shell.execute_reply.started":"2024-02-25T15:14:44.067356Z","shell.execute_reply":"2024-02-25T15:15:57.450323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in train:\n    if (len(train[i].unique())<=3 and not train[i].dtype=='object'):\n        plt.figure(figsize=(10,7))\n        ax=sns.countplot(data=train,x='TARGET',hue=i)\n        for p in ax.patches:\n              ax.annotate(p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')\n        plt.show()","metadata":{"id":"xGhwh96_8Ut3","outputId":"f57f4925-70bd-412f-a9d8-e1ecd5f6fd2b","execution":{"iopub.status.busy":"2024-02-25T15:15:57.452813Z","iopub.execute_input":"2024-02-25T15:15:57.453127Z","iopub.status.idle":"2024-02-25T15:16:06.750858Z","shell.execute_reply.started":"2024-02-25T15:15:57.453100Z","shell.execute_reply":"2024-02-25T15:16:06.749501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From the graphs, we observed, Rows with CODE_GENDER = XNA has only 2 Rows, and few XNA in ORGANIZATION_TYPE (This can be treated like an unknown value). So we are manipulating those values to NULL and later dealt, while dealing with null values","metadata":{"id":"6dP8HGVhOOnX"}},{"cell_type":"code","source":"train = train.replace('XNA', np.nan)","metadata":{"id":"_jVtpvslOOAL","execution":{"iopub.status.busy":"2024-02-25T15:16:06.752678Z","iopub.execute_input":"2024-02-25T15:16:06.753060Z","iopub.status.idle":"2024-02-25T15:16:07.347661Z","shell.execute_reply.started":"2024-02-25T15:16:06.753020Z","shell.execute_reply":"2024-02-25T15:16:07.346448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Also we found that FLAG_MOBIL has just 1 row with a zero, hence its pointless to have that column for training. So removing that column","metadata":{"id":"FyTL8QUETAKn"}},{"cell_type":"code","source":"train = train.drop('FLAG_MOBIL', axis=1)","metadata":{"id":"0-FARDsgTXrD","execution":{"iopub.status.busy":"2024-02-25T15:16:07.349370Z","iopub.execute_input":"2024-02-25T15:16:07.349734Z","iopub.status.idle":"2024-02-25T15:16:07.502812Z","shell.execute_reply.started":"2024-02-25T15:16:07.349704Z","shell.execute_reply":"2024-02-25T15:16:07.501676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We do the same with test data","metadata":{"id":"9TFGxl1OR-gL"}},{"cell_type":"code","source":"test = test.replace('XNA', np.nan)","metadata":{"id":"gnWM9BKvQp0p","execution":{"iopub.status.busy":"2024-02-25T15:16:07.504326Z","iopub.execute_input":"2024-02-25T15:16:07.504683Z","iopub.status.idle":"2024-02-25T15:16:07.866050Z","shell.execute_reply.started":"2024-02-25T15:16:07.504654Z","shell.execute_reply":"2024-02-25T15:16:07.865058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.drop('FLAG_MOBIL', axis=1)","metadata":{"id":"voqKCeXrTr10","execution":{"iopub.status.busy":"2024-02-25T15:16:07.867478Z","iopub.execute_input":"2024-02-25T15:16:07.867811Z","iopub.status.idle":"2024-02-25T15:16:07.955672Z","shell.execute_reply.started":"2024-02-25T15:16:07.867783Z","shell.execute_reply":"2024-02-25T15:16:07.954500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**BASIC PREPROCESSING**","metadata":{"id":"ykrb8lgPazJM"}},{"cell_type":"markdown","source":"FINDING NULL VALUES (NaN)","metadata":{"id":"mbng2RoVZIO4"}},{"cell_type":"code","source":"train.isna().sum()","metadata":{"id":"Rg6CB7_OPB-b","outputId":"63c83389-c00f-4a51-a10a-caa5e09aef8c","execution":{"iopub.status.busy":"2024-02-25T15:16:07.966555Z","iopub.execute_input":"2024-02-25T15:16:07.966945Z","iopub.status.idle":"2024-02-25T15:16:08.453544Z","shell.execute_reply.started":"2024-02-25T15:16:07.966916Z","shell.execute_reply":"2024-02-25T15:16:08.452436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isna().sum().sort_values()","metadata":{"id":"EiHTQs2jR2L1","outputId":"d9b0c30f-19e8-4593-fae0-fd3eb9a15393","execution":{"iopub.status.busy":"2024-02-25T15:16:08.455203Z","iopub.execute_input":"2024-02-25T15:16:08.455514Z","iopub.status.idle":"2024-02-25T15:16:08.776268Z","shell.execute_reply.started":"2024-02-25T15:16:08.455488Z","shell.execute_reply":"2024-02-25T15:16:08.775153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_perc_col=train.isna().sum().sort_values()/len(train)*100\nnull_perc_col","metadata":{"id":"EE8C31NKCaNf","outputId":"c3dc7285-119e-46d7-edd5-8b0b32cf0315","execution":{"iopub.status.busy":"2024-02-25T15:16:08.777718Z","iopub.execute_input":"2024-02-25T15:16:08.778139Z","iopub.status.idle":"2024-02-25T15:16:09.102385Z","shell.execute_reply.started":"2024-02-25T15:16:08.778108Z","shell.execute_reply":"2024-02-25T15:16:09.101125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**DROPPING COLUMNS WITH HIGH % OF NULL VALUES**","metadata":{"id":"ViuQY66MieUM"}},{"cell_type":"code","source":"train_drop_null_col=[]\nfor i in train:\n    if(null_perc_col[i]>65):\n        train_drop_null_col.append(i)\ntrain_drop_null_col","metadata":{"id":"DswjSMMJWfWk","outputId":"3a46631d-ecdc-43eb-b497-412f1c40e56a","execution":{"iopub.status.busy":"2024-02-25T15:16:09.103677Z","iopub.execute_input":"2024-02-25T15:16:09.104000Z","iopub.status.idle":"2024-02-25T15:16:09.113188Z","shell.execute_reply.started":"2024-02-25T15:16:09.103972Z","shell.execute_reply":"2024-02-25T15:16:09.111887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(columns =train_drop_null_col,axis=1,inplace = True)\nformat(train.shape)","metadata":{"id":"Xfe4CgoDrViL","outputId":"09bf4084-ab37-42d5-ad58-665686d46153","execution":{"iopub.status.busy":"2024-02-25T15:16:09.114939Z","iopub.execute_input":"2024-02-25T15:16:09.115445Z","iopub.status.idle":"2024-02-25T15:16:09.230388Z","shell.execute_reply.started":"2024-02-25T15:16:09.115408Z","shell.execute_reply":"2024-02-25T15:16:09.229093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**DROPPING COLUMNS WITH HIGH NULL VALUE % IN TRAIN**","metadata":{"id":"hQGAkQFLjCmB"}},{"cell_type":"code","source":"test.drop(columns =train_drop_null_col,axis=1,inplace = True)\nformat(test.shape)","metadata":{"id":"-pvfccndjOhW","outputId":"3e997963-fdba-46cd-daa0-d3e5f0bc7c32","execution":{"iopub.status.busy":"2024-02-25T15:16:09.231780Z","iopub.execute_input":"2024-02-25T15:16:09.232140Z","iopub.status.idle":"2024-02-25T15:16:09.306673Z","shell.execute_reply.started":"2024-02-25T15:16:09.232112Z","shell.execute_reply":"2024-02-25T15:16:09.305526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"FINDING (?) IN DATASET","metadata":{"id":"qFBEuq4mGGQ2"}},{"cell_type":"code","source":"(train == \"?\").sum()","metadata":{"id":"0xPcogkMR2oF","outputId":"faa64329-f295-4c51-8a82-3307ba0ff325","execution":{"iopub.status.busy":"2024-02-25T15:16:09.308192Z","iopub.execute_input":"2024-02-25T15:16:09.308521Z","iopub.status.idle":"2024-02-25T15:16:09.784529Z","shell.execute_reply.started":"2024-02-25T15:16:09.308493Z","shell.execute_reply":"2024-02-25T15:16:09.783626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(test == \"?\").sum()","metadata":{"id":"QxyeiMAuQzwp","outputId":"7a1141ed-9387-48ab-f02e-90846fa5f70b","execution":{"iopub.status.busy":"2024-02-25T15:16:09.785688Z","iopub.execute_input":"2024-02-25T15:16:09.785998Z","iopub.status.idle":"2024-02-25T15:16:10.107641Z","shell.execute_reply.started":"2024-02-25T15:16:09.785970Z","shell.execute_reply":"2024-02-25T15:16:10.106533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are no (?) in the given dataset","metadata":{"id":"9Ojb1vR37EZl"}},{"cell_type":"markdown","source":"FINDING DUPLICATE ROWS","metadata":{"id":"QJLFxZSiJXlV"}},{"cell_type":"code","source":"train.duplicated().sum()","metadata":{"id":"SbzIfSyQJS2z","outputId":"d85be52c-36e5-45d0-cd96-626816e0a142","execution":{"iopub.status.busy":"2024-02-25T15:16:10.109035Z","iopub.execute_input":"2024-02-25T15:16:10.109484Z","iopub.status.idle":"2024-02-25T15:16:10.915114Z","shell.execute_reply.started":"2024-02-25T15:16:10.109417Z","shell.execute_reply":"2024-02-25T15:16:10.914086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are no duplicate rows which can be removed","metadata":{"id":"3lunQZDX7OAB"}},{"cell_type":"markdown","source":"#**FILLING IN MISSING/NULL VALUES**","metadata":{"id":"cTfngtPzXSVl"}},{"cell_type":"code","source":"def RemoveNaN(df,df_merged,nan_data):\n  cols = list(df.columns[df.isnull().sum() != 0])\n\n  for col in cols:\n      t=0\n\n      if(type(nan_data[col]) is list):\n          t=nan_data[col][1]\n      else:\n          t = nan_data[col]\n\n      replace_type = t\n\n      if(replace_type == \"median\"):\n            df[col].fillna(df_merged[col].median(),inplace=True)\n      # elif(replace_type == \"mean\"):\n      #     df[col].fillna(df_merged[col].mean(),inplace=True)\n      elif(replace_type == \"mode\"):\n            df[col].fillna(df_merged[col].value_counts().idxmax(),inplace=True)\n      else:\n            df[col].fillna(replace_type,inplace=True)","metadata":{"id":"byyZW6kjVZ53","execution":{"iopub.status.busy":"2024-02-25T15:16:10.916283Z","iopub.execute_input":"2024-02-25T15:16:10.916592Z","iopub.status.idle":"2024-02-25T15:16:10.924311Z","shell.execute_reply.started":"2024-02-25T15:16:10.916551Z","shell.execute_reply":"2024-02-25T15:16:10.923464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nan_data = {\n 'CODE_GENDER':'mode',\n 'ORGANIZATION_TYPE':'Not Specified',\n 'AMT_ANNUITY': 0,\n 'AMT_GOODS_PRICE': 0,\n 'NAME_TYPE_SUITE': 'Not Specified',\n 'OWN_CAR_AGE': -1,\n 'OCCUPATION_TYPE': 'Not Specified',\n 'CNT_FAM_MEMBERS': 'median',\n 'EXT_SOURCE_1': 'median',\n 'EXT_SOURCE_2': 'median',\n 'EXT_SOURCE_3': 'median',\n 'APARTMENTS_AVG': 'median',\n 'BASEMENTAREA_AVG': 'median',\n 'YEARS_BEGINEXPLUATATION_AVG': 'median',\n 'YEARS_BUILD_AVG': 'median',\n 'COMMONAREA_AVG': 'median',\n 'ELEVATORS_AVG': 'median',\n 'ENTRANCES_AVG': 'median',\n 'FLOORSMAX_AVG': 'median',\n 'FLOORSMIN_AVG': 'median',\n 'LANDAREA_AVG': 'median',\n 'LIVINGAPARTMENTS_AVG': 'median',\n 'LIVINGAREA_AVG': 'median',\n 'NONLIVINGAPARTMENTS_AVG': 'median',\n 'NONLIVINGAREA_AVG': 'median',\n 'APARTMENTS_MODE': 'median',\n 'BASEMENTAREA_MODE': 'median',\n 'YEARS_BEGINEXPLUATATION_MODE': 'median',\n 'YEARS_BUILD_MODE': 'median',\n 'COMMONAREA_MODE': 'median',\n 'ELEVATORS_MODE': 'median',\n 'ENTRANCES_MODE': 'median',\n 'FLOORSMAX_MODE': 'median',\n 'FLOORSMIN_MODE': 'median',\n 'LANDAREA_MODE': 'median',\n 'LIVINGAPARTMENTS_MODE': 'median',\n 'LIVINGAREA_MODE': 'median',\n 'NONLIVINGAPARTMENTS_MODE': 'median',\n 'NONLIVINGAREA_MODE': 'median',\n 'APARTMENTS_MEDI': 'median',\n 'BASEMENTAREA_MEDI': 'median',\n 'YEARS_BEGINEXPLUATATION_MEDI': 'median',\n 'YEARS_BUILD_MEDI': 'median',\n 'COMMONAREA_MEDI': 'median',\n 'ELEVATORS_MEDI': 'median',\n 'ENTRANCES_MEDI': 'median',\n 'FLOORSMAX_MEDI': 'median',\n 'FLOORSMIN_MEDI': 'median',\n 'LANDAREA_MEDI': 'median',\n 'LIVINGAPARTMENTS_MEDI': 'median',\n 'LIVINGAREA_MEDI': 'median',\n 'NONLIVINGAPARTMENTS_MEDI': 'median',\n 'NONLIVINGAREA_MEDI': 'median',\n 'FONDKAPREMONT_MODE': 'Not Specified',\n 'HOUSETYPE_MODE': 'Not Specified',\n 'TOTALAREA_MODE': 'median',\n 'WALLSMATERIAL_MODE': 'Not Specified',\n 'EMERGENCYSTATE_MODE': 'Not Specified',\n 'OBS_30_CNT_SOCIAL_CIRCLE': 0,\n 'DEF_30_CNT_SOCIAL_CIRCLE': 0,\n 'OBS_60_CNT_SOCIAL_CIRCLE': 0,\n 'DEF_60_CNT_SOCIAL_CIRCLE':0,\n 'DAYS_LAST_PHONE_CHANGE':'median',\n 'AMT_REQ_CREDIT_BUREAU_HOUR': 0,\n 'AMT_REQ_CREDIT_BUREAU_DAY': 0,\n 'AMT_REQ_CREDIT_BUREAU_WEEK': 0,\n 'AMT_REQ_CREDIT_BUREAU_MON': 0,\n 'AMT_REQ_CREDIT_BUREAU_QRT': 0,\n 'AMT_REQ_CREDIT_BUREAU_YEAR': 0\n}","metadata":{"id":"sULvWv7RPjps","execution":{"iopub.status.busy":"2024-02-25T15:16:10.925504Z","iopub.execute_input":"2024-02-25T15:16:10.925891Z","iopub.status.idle":"2024-02-25T15:16:10.938294Z","shell.execute_reply.started":"2024-02-25T15:16:10.925842Z","shell.execute_reply":"2024-02-25T15:16:10.936969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RemoveNaN(train,test_train_merged,nan_data)","metadata":{"id":"qPd4JSNgo5qM","outputId":"3c29d18e-cc0c-437a-a9cd-55cf0760227b","execution":{"iopub.status.busy":"2024-02-25T15:16:10.939971Z","iopub.execute_input":"2024-02-25T15:16:10.940404Z","iopub.status.idle":"2024-02-25T15:16:11.747191Z","shell.execute_reply.started":"2024-02-25T15:16:10.940365Z","shell.execute_reply":"2024-02-25T15:16:11.745908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RemoveNaN(test,test_train_merged,nan_data)","metadata":{"id":"RgKiRIwkdy3k","outputId":"c84e615a-98a1-40db-9be2-f1c59c83a04d","execution":{"iopub.status.busy":"2024-02-25T15:16:11.748617Z","iopub.execute_input":"2024-02-25T15:16:11.748981Z","iopub.status.idle":"2024-02-25T15:16:12.379759Z","shell.execute_reply.started":"2024-02-25T15:16:11.748950Z","shell.execute_reply":"2024-02-25T15:16:12.378470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isna().sum().sort_values()","metadata":{"id":"zUAneJ4yusvU","outputId":"aaecea1e-20a0-4689-9e7e-6125d6fd0243","execution":{"iopub.status.busy":"2024-02-25T15:16:12.381357Z","iopub.execute_input":"2024-02-25T15:16:12.381794Z","iopub.status.idle":"2024-02-25T15:16:12.708439Z","shell.execute_reply.started":"2024-02-25T15:16:12.381756Z","shell.execute_reply":"2024-02-25T15:16:12.707236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isna().sum().sort_values()","metadata":{"id":"5JrD8rSAd1vN","outputId":"ea7b5fe4-6bd4-44a2-e357-eff2577ff2d2","execution":{"iopub.status.busy":"2024-02-25T15:16:12.709946Z","iopub.execute_input":"2024-02-25T15:16:12.710368Z","iopub.status.idle":"2024-02-25T15:16:12.930584Z","shell.execute_reply.started":"2024-02-25T15:16:12.710331Z","shell.execute_reply":"2024-02-25T15:16:12.929777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**ENCODING**","metadata":{"id":"RAYGUY8PjOmW"}},{"cell_type":"markdown","source":"**TRAIN DATA**","metadata":{"id":"Q5j7A1HFdOw7"}},{"cell_type":"code","source":"obj_train = [i for i in train.columns if train[i].dtypes == 'object']\nobj_train","metadata":{"id":"3PhNUFHBU6H9","execution":{"iopub.status.busy":"2024-02-25T15:16:12.931429Z","iopub.execute_input":"2024-02-25T15:16:12.931747Z","iopub.status.idle":"2024-02-25T15:16:12.942000Z","shell.execute_reply.started":"2024-02-25T15:16:12.931714Z","shell.execute_reply":"2024-02-25T15:16:12.940835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_train=obj_train","metadata":{"id":"FXOathoXnIkr","execution":{"iopub.status.busy":"2024-02-25T15:16:12.943321Z","iopub.execute_input":"2024-02-25T15:16:12.943651Z","iopub.status.idle":"2024-02-25T15:16:12.948264Z","shell.execute_reply.started":"2024-02-25T15:16:12.943625Z","shell.execute_reply":"2024-02-25T15:16:12.947036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['NAME_CONTRACT_TYPE'].value_counts()","metadata":{"id":"0_sQKCv1B527","execution":{"iopub.status.busy":"2024-02-25T15:16:12.949695Z","iopub.execute_input":"2024-02-25T15:16:12.950073Z","iopub.status.idle":"2024-02-25T15:16:12.997850Z","shell.execute_reply.started":"2024-02-25T15:16:12.950022Z","shell.execute_reply":"2024-02-25T15:16:12.996878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['FLAG_OWN_CAR'].value_counts()","metadata":{"id":"rBwkDv8L1HSz","execution":{"iopub.status.busy":"2024-02-25T15:16:12.999549Z","iopub.execute_input":"2024-02-25T15:16:13.000424Z","iopub.status.idle":"2024-02-25T15:16:13.036641Z","shell.execute_reply.started":"2024-02-25T15:16:13.000382Z","shell.execute_reply":"2024-02-25T15:16:13.035649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['FLAG_OWN_REALTY'].value_counts()","metadata":{"id":"3RiJenKj1KiC","execution":{"iopub.status.busy":"2024-02-25T15:16:13.037689Z","iopub.execute_input":"2024-02-25T15:16:13.038030Z","iopub.status.idle":"2024-02-25T15:16:13.075037Z","shell.execute_reply.started":"2024-02-25T15:16:13.038001Z","shell.execute_reply":"2024-02-25T15:16:13.074035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labelencoder = LabelEncoder()\nfor i in label_train:\n    train[i] = labelencoder.fit_transform(train[i])","metadata":{"id":"3yrhP8NSVOSE","execution":{"iopub.status.busy":"2024-02-25T15:16:13.076250Z","iopub.execute_input":"2024-02-25T15:16:13.076595Z","iopub.status.idle":"2024-02-25T15:16:13.969735Z","shell.execute_reply.started":"2024-02-25T15:16:13.076541Z","shell.execute_reply":"2024-02-25T15:16:13.968644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['NAME_CONTRACT_TYPE'].value_counts()","metadata":{"id":"VBTb_P1t-Gt0","execution":{"iopub.status.busy":"2024-02-25T15:16:13.971528Z","iopub.execute_input":"2024-02-25T15:16:13.972007Z","iopub.status.idle":"2024-02-25T15:16:13.984732Z","shell.execute_reply.started":"2024-02-25T15:16:13.971963Z","shell.execute_reply":"2024-02-25T15:16:13.983646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['FLAG_OWN_CAR'].value_counts()","metadata":{"id":"WYjGRjKe1Qpm","execution":{"iopub.status.busy":"2024-02-25T15:16:13.986070Z","iopub.execute_input":"2024-02-25T15:16:13.986388Z","iopub.status.idle":"2024-02-25T15:16:14.001037Z","shell.execute_reply.started":"2024-02-25T15:16:13.986361Z","shell.execute_reply":"2024-02-25T15:16:13.999769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['FLAG_OWN_REALTY'].value_counts()","metadata":{"id":"39AHtdtt1R_d","execution":{"iopub.status.busy":"2024-02-25T15:16:14.002648Z","iopub.execute_input":"2024-02-25T15:16:14.003078Z","iopub.status.idle":"2024-02-25T15:16:14.015110Z","shell.execute_reply.started":"2024-02-25T15:16:14.003042Z","shell.execute_reply":"2024-02-25T15:16:14.013912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**TEST DATA**","metadata":{"id":"v48t5utiY-Wo"}},{"cell_type":"code","source":"test['NAME_CONTRACT_TYPE'].value_counts()","metadata":{"id":"BJGaIMcIY-Wp","execution":{"iopub.status.busy":"2024-02-25T15:16:14.016585Z","iopub.execute_input":"2024-02-25T15:16:14.016994Z","iopub.status.idle":"2024-02-25T15:16:14.050279Z","shell.execute_reply.started":"2024-02-25T15:16:14.016964Z","shell.execute_reply":"2024-02-25T15:16:14.049054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in label_train:\n    test[i] = labelencoder.fit_transform(test[i])","metadata":{"id":"z-2VB3JIY-Wp","execution":{"iopub.status.busy":"2024-02-25T15:16:14.051849Z","iopub.execute_input":"2024-02-25T15:16:14.052275Z","iopub.status.idle":"2024-02-25T15:16:14.695670Z","shell.execute_reply.started":"2024-02-25T15:16:14.052237Z","shell.execute_reply":"2024-02-25T15:16:14.694372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['NAME_CONTRACT_TYPE'].value_counts()","metadata":{"id":"1eEQ0BO7Y-Wp","execution":{"iopub.status.busy":"2024-02-25T15:16:14.697226Z","iopub.execute_input":"2024-02-25T15:16:14.697779Z","iopub.status.idle":"2024-02-25T15:16:14.708650Z","shell.execute_reply.started":"2024-02-25T15:16:14.697735Z","shell.execute_reply":"2024-02-25T15:16:14.707265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**CORRELATION**","metadata":{"id":"txLgUNWYRVvW"}},{"cell_type":"code","source":"cor_matrix = train.corr().abs()\n#cor_matrix","metadata":{"id":"2S5dREJIuWDw","execution":{"iopub.status.busy":"2024-02-25T15:16:14.710082Z","iopub.execute_input":"2024-02-25T15:16:14.710473Z","iopub.status.idle":"2024-02-25T15:16:20.134403Z","shell.execute_reply.started":"2024-02-25T15:16:14.710435Z","shell.execute_reply":"2024-02-25T15:16:20.133440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Correlation matrix will be mirror image about the diagonal and all the diagonal elements will be 1 (So diagonal should not be included in any calculation).","metadata":{"id":"wyUh5ez_wakE"}},{"cell_type":"markdown","source":"Some of the features which are highly correlated that means which are some what linearly dependent with other features. These features contribute very less in predicting the output but increses the computational cost.","metadata":{"id":"0StPw3zfYx9R"}},{"cell_type":"code","source":"upper_t = cor_matrix.abs().where(np.triu(np.ones(cor_matrix.shape), k=1).astype(bool))\n#upper_t","metadata":{"id":"8DY-7NouUqKs","execution":{"iopub.status.busy":"2024-02-25T15:16:20.135974Z","iopub.execute_input":"2024-02-25T15:16:20.136792Z","iopub.status.idle":"2024-02-25T15:16:20.144707Z","shell.execute_reply.started":"2024-02-25T15:16:20.136754Z","shell.execute_reply":"2024-02-25T15:16:20.143556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_drop1 = [column for column in upper_t.columns if any(upper_t[column] >= 0.95)]\ntrain_drop1","metadata":{"id":"Am6nG_lLxble","execution":{"iopub.status.busy":"2024-02-25T15:16:20.146324Z","iopub.execute_input":"2024-02-25T15:16:20.147091Z","iopub.status.idle":"2024-02-25T15:16:20.174746Z","shell.execute_reply.started":"2024-02-25T15:16:20.147061Z","shell.execute_reply":"2024-02-25T15:16:20.173382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here, we are selecting upper triangular matrix and removing columns with high correlation.","metadata":{"id":"YY688QFnY61I"}},{"cell_type":"code","source":"train.drop(columns =train_drop1,axis=1,inplace = True)","metadata":{"id":"U-30CE8MUilV","execution":{"iopub.status.busy":"2024-02-25T15:16:20.175768Z","iopub.execute_input":"2024-02-25T15:16:20.176079Z","iopub.status.idle":"2024-02-25T15:16:20.241338Z","shell.execute_reply.started":"2024-02-25T15:16:20.176052Z","shell.execute_reply":"2024-02-25T15:16:20.240331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"format(train.shape)","metadata":{"id":"Ju4Bw_beyG5E","execution":{"iopub.status.busy":"2024-02-25T15:16:20.242412Z","iopub.execute_input":"2024-02-25T15:16:20.242751Z","iopub.status.idle":"2024-02-25T15:16:20.249187Z","shell.execute_reply.started":"2024-02-25T15:16:20.242723Z","shell.execute_reply":"2024-02-25T15:16:20.248018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c=train.corr().abs()['TARGET']","metadata":{"id":"TdzF_NBYIEji","execution":{"iopub.status.busy":"2024-02-25T15:16:20.251066Z","iopub.execute_input":"2024-02-25T15:16:20.251529Z","iopub.status.idle":"2024-02-25T15:16:23.681810Z","shell.execute_reply.started":"2024-02-25T15:16:20.251492Z","shell.execute_reply":"2024-02-25T15:16:23.680163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here, we are removing columns which has very less correlation with the TARGET.","metadata":{"id":"JPfMwneOY9t-"}},{"cell_type":"code","source":"train_drop2=[]\nfor i in train:\n    if(train[i].dtype!='object' and c[i]<0.005):\n        train_drop2.append(i)\ntrain_drop2","metadata":{"id":"-TtJrQklIgp6","execution":{"iopub.status.busy":"2024-02-25T15:16:23.683747Z","iopub.execute_input":"2024-02-25T15:16:23.684193Z","iopub.status.idle":"2024-02-25T15:16:23.698184Z","shell.execute_reply.started":"2024-02-25T15:16:23.684153Z","shell.execute_reply":"2024-02-25T15:16:23.697260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(columns =train_drop2,axis=1,inplace = True)","metadata":{"id":"1vRXW7jcNCiS","execution":{"iopub.status.busy":"2024-02-25T15:16:23.699294Z","iopub.execute_input":"2024-02-25T15:16:23.699666Z","iopub.status.idle":"2024-02-25T15:16:23.767926Z","shell.execute_reply.started":"2024-02-25T15:16:23.699639Z","shell.execute_reply":"2024-02-25T15:16:23.766676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"format(train.shape)","metadata":{"id":"3mPLQf_FNcAS","execution":{"iopub.status.busy":"2024-02-25T15:16:23.769639Z","iopub.execute_input":"2024-02-25T15:16:23.770054Z","iopub.status.idle":"2024-02-25T15:16:23.777724Z","shell.execute_reply.started":"2024-02-25T15:16:23.770013Z","shell.execute_reply":"2024-02-25T15:16:23.776356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**REMOVING COLUMNS IN TEST WHICH WE REMOVED FROM TRAIN BASED ON CORRELATION**","metadata":{"id":"5U0uE3FqSNZL"}},{"cell_type":"code","source":"test.drop(columns =train_drop1,axis=1,inplace = True)","metadata":{"id":"ySyl6eWXJp0h","execution":{"iopub.status.busy":"2024-02-25T15:16:23.779131Z","iopub.execute_input":"2024-02-25T15:16:23.779642Z","iopub.status.idle":"2024-02-25T15:16:23.820951Z","shell.execute_reply.started":"2024-02-25T15:16:23.779599Z","shell.execute_reply":"2024-02-25T15:16:23.819741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"format(test.shape)","metadata":{"id":"ohU2ReNu-6oL","execution":{"iopub.status.busy":"2024-02-25T15:16:23.822333Z","iopub.execute_input":"2024-02-25T15:16:23.822711Z","iopub.status.idle":"2024-02-25T15:16:23.829501Z","shell.execute_reply.started":"2024-02-25T15:16:23.822679Z","shell.execute_reply":"2024-02-25T15:16:23.828277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.drop(columns =train_drop2,axis=1,inplace = True)","metadata":{"id":"XzqthJQtOqN6","execution":{"iopub.status.busy":"2024-02-25T15:16:23.831020Z","iopub.execute_input":"2024-02-25T15:16:23.831512Z","iopub.status.idle":"2024-02-25T15:16:23.861090Z","shell.execute_reply.started":"2024-02-25T15:16:23.831481Z","shell.execute_reply":"2024-02-25T15:16:23.860139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"format(test.shape)","metadata":{"id":"zYL_6HYPOs97","execution":{"iopub.status.busy":"2024-02-25T15:16:23.862192Z","iopub.execute_input":"2024-02-25T15:16:23.862930Z","iopub.status.idle":"2024-02-25T15:16:23.869793Z","shell.execute_reply.started":"2024-02-25T15:16:23.862899Z","shell.execute_reply":"2024-02-25T15:16:23.868483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**OUTLIERS**","metadata":{"id":"yjZKq-PK5yLD"}},{"cell_type":"code","source":"for i in train:\n    if (train[i].nunique()>2 and train[i].dtypes != 'object'):\n      sns.boxplot(train[i])\n      plt.show()","metadata":{"id":"e_zPZaFE4yKO","execution":{"iopub.status.busy":"2024-02-25T15:16:23.871060Z","iopub.execute_input":"2024-02-25T15:16:23.871378Z","iopub.status.idle":"2024-02-25T15:16:31.466988Z","shell.execute_reply.started":"2024-02-25T15:16:23.871352Z","shell.execute_reply":"2024-02-25T15:16:31.466026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in train:\n    if (train[i].nunique()>2 and train[i].dtypes != 'object'):\n      sns.histplot(train[i],kde=True)\n      plt.show()","metadata":{"id":"yCQIv22xEANN","execution":{"iopub.status.busy":"2024-02-25T15:16:31.468493Z","iopub.execute_input":"2024-02-25T15:16:31.468929Z","iopub.status.idle":"2024-02-25T15:17:51.443217Z","shell.execute_reply.started":"2024-02-25T15:16:31.468891Z","shell.execute_reply":"2024-02-25T15:17:51.442069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calc_iqr(x,para):\n    q1 = x.quantile(q=0.25)\n    q3 = x.quantile(q=0.75)\n    iqr = q3 - q1\n    outlier_range = iqr*para\n    lower_bound = q1 - outlier_range\n    upper_bound = q3 + outlier_range\n    return lower_bound,upper_bound","metadata":{"id":"I3DLedsT53gQ","execution":{"iopub.status.busy":"2024-02-25T15:17:51.444670Z","iopub.execute_input":"2024-02-25T15:17:51.445024Z","iopub.status.idle":"2024-02-25T15:17:51.451616Z","shell.execute_reply.started":"2024-02-25T15:17:51.444991Z","shell.execute_reply":"2024-02-25T15:17:51.450075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# z = np.abs(stats.zscore(train))","metadata":{"id":"NM3qTeqUcdy5","execution":{"iopub.status.busy":"2024-02-25T15:17:51.453356Z","iopub.execute_input":"2024-02-25T15:17:51.453810Z","iopub.status.idle":"2024-02-25T15:17:51.462075Z","shell.execute_reply.started":"2024-02-25T15:17:51.453776Z","shell.execute_reply":"2024-02-25T15:17:51.461037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test['AMT_REQ_CREDIT_BUREAU_YEAR'].value_counts().sort_values()","metadata":{"id":"ohfhSPTPTsXi","execution":{"iopub.status.busy":"2024-02-25T15:17:51.463538Z","iopub.execute_input":"2024-02-25T15:17:51.464000Z","iopub.status.idle":"2024-02-25T15:17:51.477430Z","shell.execute_reply.started":"2024-02-25T15:17:51.463958Z","shell.execute_reply":"2024-02-25T15:17:51.476131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(np.where(train['AMT_REQ_CREDIT_BUREAU_YEAR']>12)[0])","metadata":{"id":"nKCzYr9ncc5V","execution":{"iopub.status.busy":"2024-02-25T15:17:51.479431Z","iopub.execute_input":"2024-02-25T15:17:51.479862Z","iopub.status.idle":"2024-02-25T15:17:51.488352Z","shell.execute_reply.started":"2024-02-25T15:17:51.479829Z","shell.execute_reply":"2024-02-25T15:17:51.487367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extreme_outliers=['OBS_30_CNT_SOCIAL_CIRCLE','DEF_30_CNT_SOCIAL_CIRCLE','DEF_60_CNT_SOCIAL_CIRCLE','CNT_FAM_MEMBERS']","metadata":{"id":"yM1lUwj5sHoG","execution":{"iopub.status.busy":"2024-02-25T15:17:51.492260Z","iopub.execute_input":"2024-02-25T15:17:51.492694Z","iopub.status.idle":"2024-02-25T15:17:51.499083Z","shell.execute_reply.started":"2024-02-25T15:17:51.492662Z","shell.execute_reply":"2024-02-25T15:17:51.497614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"outliers=['CNT_CHILDREN','AMT_CREDIT','AMT_ANNUITY','REGION_POPULATION_RELATIVE','AMT_REQ_CREDIT_BUREAU_YEAR']","metadata":{"id":"1gyK1PgLj3rR","execution":{"iopub.status.busy":"2024-02-25T15:17:51.501243Z","iopub.execute_input":"2024-02-25T15:17:51.501829Z","iopub.status.idle":"2024-02-25T15:17:51.508781Z","shell.execute_reply.started":"2024-02-25T15:17:51.501789Z","shell.execute_reply":"2024-02-25T15:17:51.507574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in extreme_outliers:\n        minv,maxv=calc_iqr(test_train_merged[i],3)\n        train[i].loc[train[i].astype('float64') > maxv]  = maxv\n        train[i].loc[train[i].astype('float64') < minv]  = minv\n        #train.drop(train[train[i].astype('float64')>maxv].index , inplace=True)\n        #train.drop(train[train[i].astype('float64')<minv].index , inplace=True)","metadata":{"id":"2Rhzbv_esA9T","execution":{"iopub.status.busy":"2024-02-25T15:17:51.510181Z","iopub.execute_input":"2024-02-25T15:17:51.510544Z","iopub.status.idle":"2024-02-25T15:17:51.579735Z","shell.execute_reply.started":"2024-02-25T15:17:51.510516Z","shell.execute_reply":"2024-02-25T15:17:51.578773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(np.where(train['DAYS_EMPLOYED']>0)[0])","metadata":{"id":"QWaKLalTeYhi","execution":{"iopub.status.busy":"2024-02-25T15:17:51.581186Z","iopub.execute_input":"2024-02-25T15:17:51.581615Z","iopub.status.idle":"2024-02-25T15:17:51.586459Z","shell.execute_reply.started":"2024-02-25T15:17:51.581553Z","shell.execute_reply":"2024-02-25T15:17:51.585581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in outliers:\n     minv,maxv=calc_iqr(test_train_merged[i],1.5)\n     train[i].loc[train[i].astype('float64') > maxv]  = maxv\n     train[i].loc[train[i].astype('float64') < minv]  = minv\n     #train.drop(train[train[i].astype('float64')>maxv].index , inplace=True)\n     #train.drop(train[train[i].astype('float64')<minv].index , inplace=True)","metadata":{"id":"SA9Oz7dS2x2z","execution":{"iopub.status.busy":"2024-02-25T15:17:51.588078Z","iopub.execute_input":"2024-02-25T15:17:51.588503Z","iopub.status.idle":"2024-02-25T15:17:51.675602Z","shell.execute_reply.started":"2024-02-25T15:17:51.588460Z","shell.execute_reply":"2024-02-25T15:17:51.674739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(np.where(train['DAYS_EMPLOYED']>0)[0])","metadata":{"id":"dGZnxMY9ghTD","execution":{"iopub.status.busy":"2024-02-25T15:17:51.677001Z","iopub.execute_input":"2024-02-25T15:17:51.677555Z","iopub.status.idle":"2024-02-25T15:17:51.681882Z","shell.execute_reply.started":"2024-02-25T15:17:51.677522Z","shell.execute_reply":"2024-02-25T15:17:51.680425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in outliers_manual:\n#   if i=='CNT_CHILDREN':\n#     train[i].loc[train[i].astype('float64') > 3]  = 3\n#     #train.drop(train[train[i].astype('float64')>3].index , inplace=True)","metadata":{"id":"TReXjVVk3Vw7","execution":{"iopub.status.busy":"2024-02-25T15:17:51.683197Z","iopub.execute_input":"2024-02-25T15:17:51.683823Z","iopub.status.idle":"2024-02-25T15:17:51.691491Z","shell.execute_reply.started":"2024-02-25T15:17:51.683783Z","shell.execute_reply":"2024-02-25T15:17:51.690464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"PLOTS AFTER REMOVING OUTLIERS","metadata":{"id":"7_bOEkib7yU_"}},{"cell_type":"code","source":"for i in train:\n  if (train[i].nunique()>2 and train[i].dtypes != 'object'):\n      sns.boxplot(train[i])\n      plt.show()","metadata":{"id":"pqb_kUou7xbu","execution":{"iopub.status.busy":"2024-02-25T15:17:51.692877Z","iopub.execute_input":"2024-02-25T15:17:51.693231Z","iopub.status.idle":"2024-02-25T15:17:59.307301Z","shell.execute_reply.started":"2024-02-25T15:17:51.693189Z","shell.execute_reply":"2024-02-25T15:17:59.306266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in train:\n  if (train[i].nunique()>2 and train[i].dtypes != 'object'):\n      sns.histplot(train[i],kde=True)\n      plt.show()","metadata":{"id":"J_XP9qd3F93Z","execution":{"iopub.status.busy":"2024-02-25T15:17:59.322282Z","iopub.execute_input":"2024-02-25T15:17:59.322733Z","iopub.status.idle":"2024-02-25T15:19:05.799323Z","shell.execute_reply.started":"2024-02-25T15:17:59.322699Z","shell.execute_reply":"2024-02-25T15:19:05.798186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**STANDARDISATION**","metadata":{"id":"D8DyX9d9zRBR"}},{"cell_type":"code","source":"# from sklearn.preprocessing import StandardScaler\n# sc = StandardScaler()\n# x_train = sc.fit_transform(x_train)\n# x_validation = sc.transform (x_validation)\n\n#Standardisation reduced F1 score for some reason so commented it out","metadata":{"id":"drmdM9yrzS2h","execution":{"iopub.status.busy":"2024-02-25T15:19:05.800596Z","iopub.execute_input":"2024-02-25T15:19:05.800941Z","iopub.status.idle":"2024-02-25T15:19:05.805717Z","shell.execute_reply.started":"2024-02-25T15:19:05.800912Z","shell.execute_reply":"2024-02-25T15:19:05.804493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**MODEL IMPLEMENTATION**","metadata":{"id":"z5Lv4ofQjlSG"}},{"cell_type":"markdown","source":"**IMPORTING LIBRARIES**","metadata":{"id":"eFjKkCnjl2__"}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.naive_bayes import GaussianNB\nfrom xgboost import XGBClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn import svm\nfrom lightgbm import LGBMClassifier\nfrom sklearn.ensemble import AdaBoostClassifier\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.linear_model import Perceptron\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import f1_score\nfrom sklearn.metrics import accuracy_score","metadata":{"id":"urwWPq4ftn6n","execution":{"iopub.status.busy":"2024-02-25T15:19:05.807462Z","iopub.execute_input":"2024-02-25T15:19:05.808146Z","iopub.status.idle":"2024-02-25T15:19:07.673319Z","shell.execute_reply.started":"2024-02-25T15:19:05.808106Z","shell.execute_reply":"2024-02-25T15:19:07.672129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train.drop(['TARGET'],axis=1)\n\ny=train['TARGET']","metadata":{"id":"ffqJskClWp4U","execution":{"iopub.status.busy":"2024-02-25T15:19:07.674697Z","iopub.execute_input":"2024-02-25T15:19:07.675058Z","iopub.status.idle":"2024-02-25T15:19:07.725139Z","shell.execute_reply.started":"2024-02-25T15:19:07.675027Z","shell.execute_reply":"2024-02-25T15:19:07.724130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_validation, y_train, y_validation = train_test_split(x,y,test_size=0.2,random_state=42)","metadata":{"id":"cBc8UHZobbuL","execution":{"iopub.status.busy":"2024-02-25T15:19:07.726599Z","iopub.execute_input":"2024-02-25T15:19:07.726928Z","iopub.status.idle":"2024-02-25T15:19:07.885526Z","shell.execute_reply.started":"2024-02-25T15:19:07.726899Z","shell.execute_reply":"2024-02-25T15:19:07.884345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**TRIAL MODELS**","metadata":{"id":"vA6ZFQlTPomY"}},{"cell_type":"markdown","source":"All of it is commented out as their scores were pretty less with default parameters compared to XGB and LGBM","metadata":{"id":"gBiz2_kXmxSu"}},{"cell_type":"markdown","source":"**LOGISTIC REGRESSION**","metadata":{"id":"SurhXOZXBiXX"}},{"cell_type":"code","source":"# lr = LogisticRegression(max_iter=3000)\n# lr.fit(x_train, y_train)\n\n# y_pred_lr = lr.predict(x_validation)\n\n# lr_train_score = lr.score(x_train, y_train)\n# lr_validation_score= lr.score(x_validation, y_validation)\n\n# lr_acc = accuracy_score(y_pred_lr,y_validation)\n# lr_f1_score=f1_score(y_validation, y_pred_lr, average='macro')\n\n# pred_lr=lr.predict(test)\n# pred_lr","metadata":{"id":"179YY22cXvyP","execution":{"iopub.status.busy":"2024-02-25T15:19:07.886640Z","iopub.execute_input":"2024-02-25T15:19:07.886965Z","iopub.status.idle":"2024-02-25T15:19:07.892253Z","shell.execute_reply.started":"2024-02-25T15:19:07.886937Z","shell.execute_reply":"2024-02-25T15:19:07.890830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('LogisticRegressionModel Train Score is : ' , lr_train_score)\n# print('LogisticRegressionModel Validation Score is : ' , lr_validation_score)\n# print('LogisticRegressionModel Accuracy is : ', lr_acc)\n# print('LogisticRegressionModel F1 Score is : ', lr_f1_score)","metadata":{"id":"FKW6ZqDaIn5n","execution":{"iopub.status.busy":"2024-02-25T15:19:07.893975Z","iopub.execute_input":"2024-02-25T15:19:07.894370Z","iopub.status.idle":"2024-02-25T15:19:07.901487Z","shell.execute_reply.started":"2024-02-25T15:19:07.894342Z","shell.execute_reply":"2024-02-25T15:19:07.900450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**DECISION TREES**","metadata":{"id":"dltCn-VjIBOZ"}},{"cell_type":"code","source":"# dt= DecisionTreeClassifier()\n# dt.fit(x_train, y_train)\n\n# y_pred_dt = dt.predict(x_validation)\n\n# dt_train_score = dt.score(x_train, y_train)\n# dt_validation_score= dt.score(x_validation, y_validation)\n\n# dt_acc = accuracy_score(y_pred_dt,y_validation)\n# dt_f1_score=f1_score(y_validation, y_pred_dt, average='macro')\n\n# pred_dt=dt.predict(test)\n# pred_dt","metadata":{"id":"bJLZHGyTaZeG","execution":{"iopub.status.busy":"2024-02-25T15:19:07.903535Z","iopub.execute_input":"2024-02-25T15:19:07.904087Z","iopub.status.idle":"2024-02-25T15:19:07.910286Z","shell.execute_reply.started":"2024-02-25T15:19:07.904038Z","shell.execute_reply":"2024-02-25T15:19:07.909438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('DecisionTreeClassifier Train Score is : ' , dt_train_score)\n# print('DecisionTreeClassifier Validation Score is : ' , dt_validation_score)\n# print('DecisionTreeClassifier Accuracy is : ', dt_acc)\n# print('DecisionTreeClassifier F1 Score is : ', dt_f1_score)","metadata":{"id":"MDaOnOSGIubA","execution":{"iopub.status.busy":"2024-02-25T15:19:07.911676Z","iopub.execute_input":"2024-02-25T15:19:07.912283Z","iopub.status.idle":"2024-02-25T15:19:07.920244Z","shell.execute_reply.started":"2024-02-25T15:19:07.912253Z","shell.execute_reply":"2024-02-25T15:19:07.919282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**RANDOM FOREST**","metadata":{"id":"hXA8IPTbJm9r"}},{"cell_type":"code","source":"# rf= RandomForestClassifier(n_estimators = 100, random_state = 50, verbose = 1, n_jobs = -1)\n# rf.fit(x_train, y_train)\n\n# y_pred_rf = rf.predict(x_validation)\n\n# rf_train_score = rf.score(x_train, y_train)\n# rf_validation_score= rf.score(x_validation, y_validation)\n\n# rf_acc = accuracy_score(y_pred_rf,y_validation)\n# rf_f1_score=f1_score(y_validation, y_pred_rf, average='macro')\n\n# pred_rf=rf.predict(test)\n# pred_rf","metadata":{"id":"jENegDC7az7O","execution":{"iopub.status.busy":"2024-02-25T15:19:07.921744Z","iopub.execute_input":"2024-02-25T15:19:07.922374Z","iopub.status.idle":"2024-02-25T15:19:07.931133Z","shell.execute_reply.started":"2024-02-25T15:19:07.922333Z","shell.execute_reply":"2024-02-25T15:19:07.929956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('RandomForestClassifier Train Score is : ' , rf_train_score)\n# print('RandomForestClassifier Validation Score is : ' , rf_validation_score)\n# print('RandomForestClassifier Accuracy is : ', rf_acc)\n# print('RandomForestClassifier F1 Score is : ', rf_f1_score)","metadata":{"id":"NrV4_pSpI-J3","execution":{"iopub.status.busy":"2024-02-25T15:19:07.932790Z","iopub.execute_input":"2024-02-25T15:19:07.933128Z","iopub.status.idle":"2024-02-25T15:19:07.944407Z","shell.execute_reply.started":"2024-02-25T15:19:07.933100Z","shell.execute_reply":"2024-02-25T15:19:07.943276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**NAIVE BAYES**","metadata":{"id":"c9n4Eeq8Jrkh"}},{"cell_type":"code","source":"# nb = GaussianNB()\n# nb.fit(x_train, y_train)\n\n# y_pred_nb = nb.predict(x_validation)\n\n# nb_train_score = nb.score(x_train, y_train)\n# nb_validation_score= nb.score(x_validation, y_validation)\n\n# nb_acc = accuracy_score(y_pred_nb,y_validation)\n# nb_f1_score=f1_score(y_validation, y_pred_nb, average='macro')\n\n# pred_nb=nb.predict(test)\n# pred_nb","metadata":{"id":"M-kCCjaqebdk","execution":{"iopub.status.busy":"2024-02-25T15:19:07.945749Z","iopub.execute_input":"2024-02-25T15:19:07.946072Z","iopub.status.idle":"2024-02-25T15:19:07.954544Z","shell.execute_reply.started":"2024-02-25T15:19:07.946045Z","shell.execute_reply":"2024-02-25T15:19:07.953372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('NaiveBayesClassifier Train Score is : ' , nb_train_score)\n# print('NaiveBayesClassifier Validation Score is : ' , nb_validation_score)\n# print('NaiveBayesClassifier Accuracy is : ', nb_acc)\n# print('NaiveBayesClassifier F1 Score is : ', nb_f1_score)","metadata":{"id":"v7HY_ZvKKhmM","execution":{"iopub.status.busy":"2024-02-25T15:19:07.955980Z","iopub.execute_input":"2024-02-25T15:19:07.956372Z","iopub.status.idle":"2024-02-25T15:19:07.964874Z","shell.execute_reply.started":"2024-02-25T15:19:07.956341Z","shell.execute_reply":"2024-02-25T15:19:07.963520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**ADABOOST**","metadata":{"id":"y9IobUicmlFd"}},{"cell_type":"code","source":"# adb = AdaBoostClassifier(random_state=0,n_estimators=200)\n\n# adb.fit(x_train, y_train)\n\n# y_pred_adb = adb.predict(x_validation)\n\n# adb_train_score = adb.score(x_train, y_train)\n# adb_validation_score= adb.score(x_validation, y_validation)\n\n# adb_acc = accuracy_score(y_pred_adb,y_validation)\n# adb_f1_score=f1_score(y_validation, y_pred_adb, average='macro')\n\n# pred_adb=adb.predict(test)\n# pred_adb","metadata":{"id":"EmxZm1zjmkh9","execution":{"iopub.status.busy":"2024-02-25T15:19:07.966510Z","iopub.execute_input":"2024-02-25T15:19:07.966974Z","iopub.status.idle":"2024-02-25T15:19:07.975677Z","shell.execute_reply.started":"2024-02-25T15:19:07.966937Z","shell.execute_reply":"2024-02-25T15:19:07.974490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('AdaBoostClassifier Train Score is : ' , adb_train_score)\n# print('AdaBoostClassifier Validation Score is : ' , adb_validation_score)\n# print('AdaBoostClassifier Accuracy is : ', adb_acc)\n# print('AdaBoostClassifier F1 Score is : ', adb_f1_score)","metadata":{"id":"-ftKf2CinYea","execution":{"iopub.status.busy":"2024-02-25T15:19:07.976907Z","iopub.execute_input":"2024-02-25T15:19:07.977513Z","iopub.status.idle":"2024-02-25T15:19:07.983580Z","shell.execute_reply.started":"2024-02-25T15:19:07.977480Z","shell.execute_reply":"2024-02-25T15:19:07.982552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**GRADIENT BOOST**","metadata":{"id":"jJHgAHgnmosh"}},{"cell_type":"code","source":"# gb = GradientBoostingClassifier(random_state=0,learning_rate= 0.01,n_estimators= 1000,max_depth=6)\n\n# gb.fit(x_train, y_train)\n\n# y_pred_gb = gb.predict(x_validation)\n\n# gb_train_score = gb.score(x_train, y_train)\n# gb_validation_score= gb.score(x_validation, y_validation)\n\n# gb_acc = accuracy_score(y_pred_gb,y_validation)\n# gb_f1_score=f1_score(y_validation, y_pred_gb, average='macro')\n\n# pred_gb=gb.predict(test)\n# pred_gb","metadata":{"id":"8NR29QSsm2Lk","execution":{"iopub.status.busy":"2024-02-25T15:19:07.984546Z","iopub.execute_input":"2024-02-25T15:19:07.984935Z","iopub.status.idle":"2024-02-25T15:19:07.993102Z","shell.execute_reply.started":"2024-02-25T15:19:07.984905Z","shell.execute_reply":"2024-02-25T15:19:07.992126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('GradientBoostingClassifier Train Score is : ' , gb_train_score)\n# print('GradientBoostingClassifier Validation Score is : ' , gb_validation_score)\n# print('GradientBoostingClassifier Accuracy is : ', gb_acc)\n# print('GradientBoostingClassifier F1 Score is : ', gb_f1_score)","metadata":{"id":"sxohCajinlZZ","execution":{"iopub.status.busy":"2024-02-25T15:19:07.994098Z","iopub.execute_input":"2024-02-25T15:19:07.994400Z","iopub.status.idle":"2024-02-25T15:19:08.005955Z","shell.execute_reply.started":"2024-02-25T15:19:07.994374Z","shell.execute_reply":"2024-02-25T15:19:08.004525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**SVM**","metadata":{"id":"_c8KXJTbfqTj"}},{"cell_type":"code","source":"# from sklearn.svm import SVC\n# svc = SVC(C=1.0, random_state=1, kernel='linear')\n# svc.fit(x_train, y_train)\n\n# y_pred_svc = svc.predict(x_validation)\n\n# svc_train_score = svc.score(x_train, y_train)\n# svc_validation_score= svc.score(x_validation, y_validation)\n\n# svc_acc = accuracy_score(y_pred_svc,y_validation)\n# svc_f1_score=f1_score(y_validation, y_pred_svc, average='macro')\n\n# pred_svc=svc.predict(test)\n# pred_svc","metadata":{"id":"L1t_UysQfpC_","execution":{"iopub.status.busy":"2024-02-25T15:19:08.007538Z","iopub.execute_input":"2024-02-25T15:19:08.007932Z","iopub.status.idle":"2024-02-25T15:19:08.017345Z","shell.execute_reply.started":"2024-02-25T15:19:08.007901Z","shell.execute_reply":"2024-02-25T15:19:08.015991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('SupportVectorMachineClassifier Train Score is : ' , svc_train_score)\n# print('SupportVectorMachineClassifier Validation Score is : ' , svc_validation_score)\n# print('SupportVectorMachineClassifier Accuracy is : ', svc_acc)\n# print('SupportVectorMachineClassifier F1 Score is : ', svc_f1_score)","metadata":{"id":"-zuYH2_eqFDH","execution":{"iopub.status.busy":"2024-02-25T15:19:08.018989Z","iopub.execute_input":"2024-02-25T15:19:08.019378Z","iopub.status.idle":"2024-02-25T15:19:08.027282Z","shell.execute_reply.started":"2024-02-25T15:19:08.019340Z","shell.execute_reply":"2024-02-25T15:19:08.026397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**CATBOOST**","metadata":{"id":"6aHmMSMVmsVJ"}},{"cell_type":"code","source":"# cb = CatBoostClassifier(thread_count=-1,random_state=0,border_count=5000,depth=4)\n# cb.fit(x_train, y_train)\n\n# y_pred_cb = cb.predict(x_validation)\n\n# cb_train_score = cb.score(x_train, y_train)\n# cb_validation_score= cb.score(x_validation, y_validation)\n\n# cb_acc = accuracy_score(y_pred_cb,y_validation)\n# cb_f1_score=f1_score(y_validation, y_pred_cb, average='macro')\n\n# pred_cb=svc.predict(test)\n# pred_cb","metadata":{"id":"qFFmaorSmz9D","execution":{"iopub.status.busy":"2024-02-25T15:19:08.028392Z","iopub.execute_input":"2024-02-25T15:19:08.028750Z","iopub.status.idle":"2024-02-25T15:19:08.037404Z","shell.execute_reply.started":"2024-02-25T15:19:08.028710Z","shell.execute_reply":"2024-02-25T15:19:08.036388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('CatBoostClassifier Train Score is : ' , cb_train_score)\n# print('CatBoostClassifier Validation Score is : ' , cb_validation_score)\n# print('CatBoostClassifier Accuracy is : ', cb_acc)\n# print('CatBoostClassifier F1 Score is : ', cb_f1_score)","metadata":{"id":"ordribcfrCqE","execution":{"iopub.status.busy":"2024-02-25T15:19:08.038448Z","iopub.execute_input":"2024-02-25T15:19:08.038924Z","iopub.status.idle":"2024-02-25T15:19:08.049817Z","shell.execute_reply.started":"2024-02-25T15:19:08.038890Z","shell.execute_reply":"2024-02-25T15:19:08.048431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**PERCEPTRON**","metadata":{"id":"HzSqFnRDmu2H"}},{"cell_type":"code","source":"# perc = Perceptron(random_state=1)\n# perc.fit(x_train, y_train)\n\n# y_pred_perc = perc.predict(x_validation)\n\n# perc_train_score = perc.score(x_train, y_train)\n# perc_validation_score= perc.score(x_validation, y_validation)\n\n# perc_acc = accuracy_score(y_pred_perc,y_validation)\n# perc_f1_score=f1_score(y_validation, y_pred_perc, average='macro')\n\n# pred_perc=perc.predict(test)\n# pred_perc","metadata":{"id":"NQ6wdi2ssvnt","execution":{"iopub.status.busy":"2024-02-25T15:19:08.051630Z","iopub.execute_input":"2024-02-25T15:19:08.052060Z","iopub.status.idle":"2024-02-25T15:19:08.061498Z","shell.execute_reply.started":"2024-02-25T15:19:08.052020Z","shell.execute_reply":"2024-02-25T15:19:08.060427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('PerceptronClassifier Train Score is : ' , perc_train_score)\n# print('PerceptronClassifier Validation Score is : ' , perc_validation_score)\n# print('PerceptronClassifier Accuracy is : ', perc_acc)\n# print('PerceptronClassifier F1 Score is : ', perc_f1_score)","metadata":{"id":"3w5I_IQ7tkcG","execution":{"iopub.status.busy":"2024-02-25T15:19:08.062928Z","iopub.execute_input":"2024-02-25T15:19:08.063318Z","iopub.status.idle":"2024-02-25T15:19:08.069596Z","shell.execute_reply.started":"2024-02-25T15:19:08.063278Z","shell.execute_reply":"2024-02-25T15:19:08.068629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**FINAL MODELS**","metadata":{"id":"AWpbx4XkPgM_"}},{"cell_type":"markdown","source":"**XGBOOST**","metadata":{"id":"qAhoJOljLNbz"}},{"cell_type":"markdown","source":"Tuning Optimal Parameters","metadata":{"id":"QniBgyZTP4UP"}},{"cell_type":"code","source":"# params={\n#  \"learning_rate\"    : [0.2] ,\n#  \"max_depth\"        : [4],\n#  \"min_child_weight\" : [12,13,14,15],\n#  \"gamma\"            : [0.2],\n#  \"colsample_bytree\" : [0.7],\n#  \"scale_pos_weight\" : [5],\n#  \"subsample\"        : [0.65,0.7,0.75,0.8,0.9,0.85]\n# }","metadata":{"id":"r938yV3v84Om","execution":{"iopub.status.busy":"2024-02-25T15:19:08.071358Z","iopub.execute_input":"2024-02-25T15:19:08.071906Z","iopub.status.idle":"2024-02-25T15:19:08.077702Z","shell.execute_reply.started":"2024-02-25T15:19:08.071736Z","shell.execute_reply":"2024-02-25T15:19:08.076846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from sklearn.model_selection import RandomizedSearchCV, GridSearchCV\n\n# def timer(start_time=None):\n#     if not start_time:\n#         start_time = datetime.now()\n#         return start_time\n#     elif start_time:\n#         thour, temp_sec = divmod((datetime.now() - start_time).total_seconds(), 3600)\n#         tmin, tsec = divmod(temp_sec, 60)\n#         print('\\n Time taken: %i hours %i minutes and %s seconds.' % (thour, tmin, round(tsec, 2)))\n\n# xgb=XGBClassifier()\n# random_search=RandomizedSearchCV(xgb,param_distributions=params,n_iter=5,scoring='roc_auc',n_jobs=-1,cv=5,verbose=3)","metadata":{"id":"2cLBuc_V3OpL","execution":{"iopub.status.busy":"2024-02-25T15:19:08.078901Z","iopub.execute_input":"2024-02-25T15:19:08.079286Z","iopub.status.idle":"2024-02-25T15:19:08.086670Z","shell.execute_reply.started":"2024-02-25T15:19:08.079257Z","shell.execute_reply":"2024-02-25T15:19:08.085770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from datetime import datetime\n# start_time = timer(None) # timing starts from this point for \"start_time\" variable\n# random_search.fit(x,y)\n# timer(start_time) # timing ends here for \"start_time\" variable","metadata":{"id":"gjmnqhk13js6","execution":{"iopub.status.busy":"2024-02-25T15:19:08.087721Z","iopub.execute_input":"2024-02-25T15:19:08.088072Z","iopub.status.idle":"2024-02-25T15:19:08.096239Z","shell.execute_reply.started":"2024-02-25T15:19:08.088033Z","shell.execute_reply":"2024-02-25T15:19:08.095312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# random_search.best_estimator_","metadata":{"id":"TnMCB-b33vGA","execution":{"iopub.status.busy":"2024-02-25T15:19:08.097998Z","iopub.execute_input":"2024-02-25T15:19:08.098466Z","iopub.status.idle":"2024-02-25T15:19:08.106833Z","shell.execute_reply.started":"2024-02-25T15:19:08.098425Z","shell.execute_reply":"2024-02-25T15:19:08.105760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# random_search.best_params_","metadata":{"id":"_j8m6LYy30SK","execution":{"iopub.status.busy":"2024-02-25T15:19:08.108541Z","iopub.execute_input":"2024-02-25T15:19:08.109086Z","iopub.status.idle":"2024-02-25T15:19:08.115679Z","shell.execute_reply.started":"2024-02-25T15:19:08.109046Z","shell.execute_reply":"2024-02-25T15:19:08.114643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Implementation:","metadata":{"id":"mnNc6eTJP-5-"}},{"cell_type":"code","source":"xgb = XGBClassifier(\n    scale_pos_weight=5,\n    max_depth = 4,\n    min_child_weight = 12,\n    gamma = 0.2,\n    subsample=0.9,\n    colsample_bytree = 0.7,\n    learning_rate=0.2,\n    n_estimaters=10000,\n    objective= 'binary:logistic'\n    )\nxgb.fit(x_train, y_train)\n\ny_pred_xgb1 = xgb.predict(x_validation)\ny_pred_xgb = [round(value) for value in y_pred_xgb1]\n\ny_pred_xgb = xgb.predict(x_validation)\n\nxgb_train_score = xgb.score(x_train, y_train)\nxgb_validation_score= xgb.score(x_validation, y_validation)\n\nxgb_acc = accuracy_score(y_pred_xgb,y_validation)\nxgb_f1_score=f1_score(y_validation, y_pred_xgb, average='macro')\n\npred_xgb=xgb.predict(test)\npred_xgb","metadata":{"id":"xQmh0nQ4fmcZ","execution":{"iopub.status.busy":"2024-02-25T15:19:08.116903Z","iopub.execute_input":"2024-02-25T15:19:08.117415Z","iopub.status.idle":"2024-02-25T15:19:11.236680Z","shell.execute_reply.started":"2024-02-25T15:19:08.117337Z","shell.execute_reply":"2024-02-25T15:19:11.235720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('XGBClassifier Train Score is : ' , xgb_train_score)\nprint('XGBClassifier Test Score is : ' , xgb_validation_score)\nprint('XGBClassifier Accuracy is : ', xgb_acc)\nprint('XGBClassifier F1 Score is : ', xgb_f1_score)","metadata":{"id":"IkAZrzq-MEGc","execution":{"iopub.status.busy":"2024-02-25T15:19:11.240684Z","iopub.execute_input":"2024-02-25T15:19:11.242769Z","iopub.status.idle":"2024-02-25T15:19:11.249632Z","shell.execute_reply.started":"2024-02-25T15:19:11.242731Z","shell.execute_reply":"2024-02-25T15:19:11.248885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**LIGHT GBM**","metadata":{"id":"17y9H3GEf6Zc"}},{"cell_type":"markdown","source":"Tuning Optimal Parameters","metadata":{"id":"twVrha1-QCwm"}},{"cell_type":"code","source":"# from lightgbm import LGBMRegressor\n# import numpy as np\n# import pandas as pd\n# from sklearn.model_selection import KFold\n# from sklearn.metrics import mean_squared_error\n# from sklearn.preprocessing import LabelEncoder\n# from sklearn.model_selection import train_test_split","metadata":{"id":"A-4MUt4IRJCY","execution":{"iopub.status.busy":"2024-02-25T15:19:11.250826Z","iopub.execute_input":"2024-02-25T15:19:11.251696Z","iopub.status.idle":"2024-02-25T15:19:11.259706Z","shell.execute_reply.started":"2024-02-25T15:19:11.251666Z","shell.execute_reply":"2024-02-25T15:19:11.258575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def objective(trial,data=x,target=y):\n\n#     train_x, test_x, train_y, test_y = train_test_split(data, target, test_size=0.2,random_state=42)\n#     # param = {\n#     #     'metric': 'rmse',\n#     #     'random_state': 48,\n#     #     'n_estimators': 20000,\n#     #     'reg_alpha': trial.suggest_loguniform('reg_alpha', 1e-3, 10.0),\n#     #     'reg_lambda': trial.suggest_loguniform('reg_lambda', 1e-3, 10.0),\n#     #     'colsample_bytree': trial.suggest_categorical('colsample_bytree', [0.3,0.4,0.5,0.6,0.7,0.8,0.9, 1.0]),\n#     #     'subsample': trial.suggest_categorical('subsample', [0.4,0.5,0.6,0.7,0.8,1.0]),\n#     #     'learning_rate': trial.suggest_categorical('learning_rate', [0.006,0.008,0.01,0.014,0.017,0.02]),\n#     #     'max_depth': trial.suggest_categorical('max_depth', [10,20,100]),\n#     #     'num_leaves' : trial.suggest_int('num_leaves', 1, 1000),\n#     #     'min_child_samples': trial.suggest_int('min_child_samples', 1, 300),\n#     #     'cat_smooth' : trial.suggest_int('min_data_per_groups', 1, 100)\n#     # }\n#     param = {\n#         'metric': 'rmse',\n#         'random_state': 48,\n#         'n_estimators': 10000,\n#         'reg_alpha': 1.751849103761535,\n#         'reg_lambda': 0.06277933961586747,\n#         'colsample_bytree': 0.7,\n#         'subsample': trial.suggest_categorical('subsample', [0.6,0.65,0.9]),\n#         'learning_rate': 0.008,\n#         'max_depth': trial.suggest_categorical('max_depth', [9,10]),\n#         'num_leaves' : trial.suggest_int('num_leaves', 1, 1024),\n#     }\n#     model = LGBMRegressor(**param)\n\n#     model.fit(train_x,train_y,eval_set=[(test_x,test_y)],early_stopping_rounds=100,verbose=False)\n\n#     preds = model.predict(test_x)\n\n#     rmse = mean_squared_error(test_y, preds,squared=False)\n\n#     return rmse","metadata":{"id":"vacxx0lmRL77","execution":{"iopub.status.busy":"2024-02-25T15:19:11.260905Z","iopub.execute_input":"2024-02-25T15:19:11.261254Z","iopub.status.idle":"2024-02-25T15:19:11.270526Z","shell.execute_reply.started":"2024-02-25T15:19:11.261226Z","shell.execute_reply":"2024-02-25T15:19:11.269552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #pip install optuna\n# import optuna","metadata":{"id":"4UZBJ_XDRQzv","execution":{"iopub.status.busy":"2024-02-25T15:19:11.271670Z","iopub.execute_input":"2024-02-25T15:19:11.271981Z","iopub.status.idle":"2024-02-25T15:19:11.281777Z","shell.execute_reply.started":"2024-02-25T15:19:11.271955Z","shell.execute_reply":"2024-02-25T15:19:11.280846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# study = optuna.create_study(direction='minimize')\n# study.optimize(objective, n_trials=15)\n# print('Number of finished trials:', len(study.trials))\n# print('Best trial:', study.best_trial.params)","metadata":{"id":"tGjhkhutRWLR","execution":{"iopub.status.busy":"2024-02-25T15:19:11.285472Z","iopub.execute_input":"2024-02-25T15:19:11.285881Z","iopub.status.idle":"2024-02-25T15:19:11.291334Z","shell.execute_reply.started":"2024-02-25T15:19:11.285846Z","shell.execute_reply":"2024-02-25T15:19:11.290464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Final Implementation","metadata":{"id":"E0QQZDJkQFoL"}},{"cell_type":"code","source":"lgbm = LGBMClassifier(\n       verbosity = -1,\n       feature_pre_filter = False,\n       reg_lambda=1.751849103761535,\n       reg_alpha=0.06277933961586747,\n       num_leaves= 52,\n       max_depth=10,\n       min_child_samples= 110,\n       learning_rate= 0.008,\n       n_estimators= 10000,\n       scale_pos_weight=5,\n       objective='binary',\n       metrics='auc',\n       colsample_bytree=0.7,\n       subsample=0.6,\n       )\n\n\nlgbm.fit(x_train, y_train)\n\ny_pred_lgbm = lgbm.predict(x_validation)\n\nlgbm_train_score = lgbm.score(x_train, y_train)\nlgbm_validation_score= lgbm.score(x_validation, y_validation)\n\nlgbm_acc = accuracy_score(y_pred_lgbm,y_validation)\nlgbm_f1_score=f1_score(y_validation, y_pred_lgbm, average='macro')\n\npred_lgbm=lgbm.predict(test)\npred_lgbm","metadata":{"id":"Z-sNAtHvgEWv","execution":{"iopub.status.busy":"2024-02-25T15:19:11.292678Z","iopub.execute_input":"2024-02-25T15:19:11.293341Z","iopub.status.idle":"2024-02-25T15:35:13.056094Z","shell.execute_reply.started":"2024-02-25T15:19:11.293310Z","shell.execute_reply":"2024-02-25T15:35:13.054631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('LGBMClassifier Train Score is : ' , lgbm_train_score)\nprint('LGBMClassifier Test Score is : ' , lgbm_validation_score)\nprint('LGBMClassifier Accuracy is : ', lgbm_acc)\nprint('LGBMClassifier F1 Score is : ', lgbm_f1_score)","metadata":{"id":"BcsK0jSfhwQA","execution":{"iopub.status.busy":"2024-02-25T15:35:13.057320Z","iopub.execute_input":"2024-02-25T15:35:13.057863Z","iopub.status.idle":"2024-02-25T15:35:13.062928Z","shell.execute_reply.started":"2024-02-25T15:35:13.057834Z","shell.execute_reply":"2024-02-25T15:35:13.062187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**SUMMARY**","metadata":{"id":"Pn4tz0FohxJs"}},{"cell_type":"code","source":"data = {'Models':['Light GBM', 'XGB' ],\n        'Accuracy Score':[lgbm_acc,xgb_acc],\n        'F1 Score':[lgbm_f1_score,xgb_f1_score]}\ncompare=df = pd.DataFrame(data)\ncompare.sort_values(ascending= False , by = ['F1 Score'])","metadata":{"id":"8VR4WpXFM9KG","execution":{"iopub.status.busy":"2024-02-25T15:35:13.064019Z","iopub.execute_input":"2024-02-25T15:35:13.064490Z","iopub.status.idle":"2024-02-25T15:35:13.081865Z","shell.execute_reply.started":"2024-02-25T15:35:13.064462Z","shell.execute_reply":"2024-02-25T15:35:13.080759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LR_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_lr })\n# RF_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_rf })\n# NB_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_nb })\n# GB_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_gb })\n# SVC_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_svc })\n# ADB_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_adb })\n# PERC_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_perc })\n# DT_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_dt })","metadata":{"id":"RPVjYSsnNpBo","execution":{"iopub.status.busy":"2024-02-25T15:35:13.085525Z","iopub.execute_input":"2024-02-25T15:35:13.085868Z","iopub.status.idle":"2024-02-25T15:35:13.090879Z","shell.execute_reply.started":"2024-02-25T15:35:13.085841Z","shell.execute_reply":"2024-02-25T15:35:13.089638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"XGB_Final= pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_xgb })\nLGBM_Final = pd.DataFrame({ 'SK_ID_CURR': test_data['SK_ID_CURR'],'TARGET': pred_lgbm })","metadata":{"id":"oGgcGUHWnES_","execution":{"iopub.status.busy":"2024-02-25T15:35:13.092295Z","iopub.execute_input":"2024-02-25T15:35:13.092671Z","iopub.status.idle":"2024-02-25T15:35:13.101820Z","shell.execute_reply.started":"2024-02-25T15:35:13.092638Z","shell.execute_reply":"2024-02-25T15:35:13.100720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LR_Final.TARGET.value_counts()","metadata":{"id":"-XpvHvgNVVfE","execution":{"iopub.status.busy":"2024-02-25T15:35:13.103345Z","iopub.execute_input":"2024-02-25T15:35:13.103813Z","iopub.status.idle":"2024-02-25T15:35:13.110437Z","shell.execute_reply.started":"2024-02-25T15:35:13.103782Z","shell.execute_reply":"2024-02-25T15:35:13.109596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# RF_Final.TARGET.value_counts()","metadata":{"id":"HCb7axMUV80q","execution":{"iopub.status.busy":"2024-02-25T15:35:13.111796Z","iopub.execute_input":"2024-02-25T15:35:13.112362Z","iopub.status.idle":"2024-02-25T15:35:13.117931Z","shell.execute_reply.started":"2024-02-25T15:35:13.112334Z","shell.execute_reply":"2024-02-25T15:35:13.117143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# NB_Final.TARGET.value_counts()","metadata":{"id":"uy-9IoPyW8Bs","execution":{"iopub.status.busy":"2024-02-25T15:35:13.119394Z","iopub.execute_input":"2024-02-25T15:35:13.119812Z","iopub.status.idle":"2024-02-25T15:35:13.125674Z","shell.execute_reply.started":"2024-02-25T15:35:13.119783Z","shell.execute_reply":"2024-02-25T15:35:13.124544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ADB_Final.TARGET.value_counts()","metadata":{"id":"laTXFSGUoQ2X","execution":{"iopub.status.busy":"2024-02-25T15:35:13.127104Z","iopub.execute_input":"2024-02-25T15:35:13.127406Z","iopub.status.idle":"2024-02-25T15:35:13.134779Z","shell.execute_reply.started":"2024-02-25T15:35:13.127370Z","shell.execute_reply":"2024-02-25T15:35:13.133934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# DT_Final.TARGET.value_counts()","metadata":{"id":"R3fgKmWNXCae","execution":{"iopub.status.busy":"2024-02-25T15:35:13.135949Z","iopub.execute_input":"2024-02-25T15:35:13.136456Z","iopub.status.idle":"2024-02-25T15:35:13.144205Z","shell.execute_reply.started":"2024-02-25T15:35:13.136427Z","shell.execute_reply":"2024-02-25T15:35:13.143197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# GB_Final.TARGET.value_counts()","metadata":{"id":"dvMS15FVoRfi","execution":{"iopub.status.busy":"2024-02-25T15:35:13.145616Z","iopub.execute_input":"2024-02-25T15:35:13.145934Z","iopub.status.idle":"2024-02-25T15:35:13.152481Z","shell.execute_reply.started":"2024-02-25T15:35:13.145883Z","shell.execute_reply":"2024-02-25T15:35:13.151553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# SVC_Final.TARGET.value_counts()","metadata":{"id":"JtID2XXSsW6p","execution":{"iopub.status.busy":"2024-02-25T15:35:13.154022Z","iopub.execute_input":"2024-02-25T15:35:13.154347Z","iopub.status.idle":"2024-02-25T15:35:13.160093Z","shell.execute_reply.started":"2024-02-25T15:35:13.154321Z","shell.execute_reply":"2024-02-25T15:35:13.158913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# PERC_Final.TARGET.value_counts()","metadata":{"id":"BOFahwBat6yo","execution":{"iopub.status.busy":"2024-02-25T15:35:13.161590Z","iopub.execute_input":"2024-02-25T15:35:13.162273Z","iopub.status.idle":"2024-02-25T15:35:13.168865Z","shell.execute_reply.started":"2024-02-25T15:35:13.162235Z","shell.execute_reply":"2024-02-25T15:35:13.168066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"XGB_Final.TARGET.value_counts()","metadata":{"id":"R3sNdso7XA1H","execution":{"iopub.status.busy":"2024-02-25T15:35:13.170373Z","iopub.execute_input":"2024-02-25T15:35:13.171043Z","iopub.status.idle":"2024-02-25T15:35:13.182961Z","shell.execute_reply.started":"2024-02-25T15:35:13.171007Z","shell.execute_reply":"2024-02-25T15:35:13.181799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LGBM_Final.TARGET.value_counts()","metadata":{"id":"aEWw5iLsihoS","execution":{"iopub.status.busy":"2024-02-25T15:35:13.184674Z","iopub.execute_input":"2024-02-25T15:35:13.185552Z","iopub.status.idle":"2024-02-25T15:35:13.194712Z","shell.execute_reply.started":"2024-02-25T15:35:13.185512Z","shell.execute_reply":"2024-02-25T15:35:13.193817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# DT_Final.to_csv(\"DT_Final.csv\", index=False)\n# RF_Final.to_csv(\"RF_Final.csv\", index=False)\n# NB_Final.to_csv(\"NB_Final.csv\", index=False)\n# LR_Final.to_csv(\"LR_Final.csv\", index=False)\n# ADB_Final.to_csv(\"ADB_Final.csv\", index=False)\n# SVC_Final.to_csv(\"SVC_Final.csv\", index=False)\n# PERC_Final.to_csv(\"PERC_Final.csv\", index=False)\n# GB_Final.to_csv(\"GB_Final.csv\", index=False)\n\nXGB_Final.to_csv(\"XGB_Final.csv\", index=False)\nLGBM_Final.to_csv(\"LGBM_Final.csv\", index=False)","metadata":{"id":"CDUFoXzIWxXD","execution":{"iopub.status.busy":"2024-02-25T15:35:13.195927Z","iopub.execute_input":"2024-02-25T15:35:13.196416Z","iopub.status.idle":"2024-02-25T15:35:13.540120Z","shell.execute_reply.started":"2024-02-25T15:35:13.196381Z","shell.execute_reply":"2024-02-25T15:35:13.538964Z"},"trusted":true},"execution_count":null,"outputs":[]}]}