{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import dask.dataframe as dd\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom dask.diagnostics import ProgressBar","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:50:25.737964Z","iopub.execute_input":"2022-07-29T18:50:25.738346Z","iopub.status.idle":"2022-07-29T18:50:25.746828Z","shell.execute_reply.started":"2022-07-29T18:50:25.738316Z","shell.execute_reply":"2022-07-29T18:50:25.74523Z"},"trusted":true},"execution_count":11,"outputs":[]},{"cell_type":"code","source":"test=dd.read_csv('../input/amex-default-prediction/test_data.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:50:29.097637Z","iopub.execute_input":"2022-07-29T18:50:29.098061Z","iopub.status.idle":"2022-07-29T18:50:29.201887Z","shell.execute_reply.started":"2022-07-29T18:50:29.098026Z","shell.execute_reply":"2022-07-29T18:50:29.200586Z"},"trusted":true},"execution_count":12,"outputs":[]},{"cell_type":"code","source":"test1 = test.drop_duplicates(subset=['customer_ID'], keep='last').compute()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:50:31.918186Z","iopub.execute_input":"2022-07-29T18:50:31.918681Z","iopub.status.idle":"2022-07-29T18:55:40.895911Z","shell.execute_reply.started":"2022-07-29T18:50:31.918638Z","shell.execute_reply":"2022-07-29T18:55:40.894429Z"},"trusted":true},"execution_count":13,"outputs":[]},{"cell_type":"code","source":"test1.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:55:40.898916Z","iopub.execute_input":"2022-07-29T18:55:40.899381Z","iopub.status.idle":"2022-07-29T18:55:40.907347Z","shell.execute_reply.started":"2022-07-29T18:55:40.89934Z","shell.execute_reply":"2022-07-29T18:55:40.906132Z"},"trusted":true},"execution_count":14,"outputs":[{"execution_count":14,"output_type":"execute_result","data":{"text/plain":"(924621, 190)"},"metadata":{}}]},{"cell_type":"code","source":"test1.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:55:40.90858Z","iopub.execute_input":"2022-07-29T18:55:40.908884Z","iopub.status.idle":"2022-07-29T18:55:40.93014Z","shell.execute_reply.started":"2022-07-29T18:55:40.908855Z","shell.execute_reply":"2022-07-29T18:55:40.929047Z"},"trusted":true},"execution_count":15,"outputs":[{"execution_count":15,"output_type":"execute_result","data":{"text/plain":"customer_ID     object\nS_2             object\nP_2            float64\nD_39           float64\nB_1            float64\n                ...   \nD_141          float64\nD_142          float64\nD_143          float64\nD_144          float64\nD_145          float64\nLength: 190, dtype: object"},"metadata":{}}]},{"cell_type":"code","source":"ddf = test1.filter(['customer_ID', 'P_2', 'D_39', 'B_1', 'R_1',\n 'S_3', 'D_41', 'D_43', 'D_44', 'B_4', 'D_45', 'B_5', 'R_2',\n 'D_46', 'D_47', 'D_48', 'B_6', 'B_8', 'D_51', 'B_9', 'R_3',\n 'D_52', 'P_3', 'S_5', 'S_6', 'D_54', 'B_12', 'S_8', 'R_5',\n 'D_58', 'B_14', 'D_59', 'D_60', 'B_15', 'S_11', 'D_62', 'D_63',\n 'D_64', 'D_65', 'D_68', 'S_12', 'R_6', 'S_13', 'B_21', 'D_69',\n 'B_22', 'D_70', 'D_71', 'D_72', 'P_4', 'B_24', 'R_7', 'B_25', 'B_26',\n 'D_78', 'D_79', 'S_16', 'D_80', 'R_10', 'R_11', 'B_27', 'D_81',\n 'S_17', 'R_12', 'R_13', 'D_83', 'R_14', 'R_15', 'D_84', 'R_16',\n 'S_18', 'D_86', 'R_17', 'R_18', 'S_19', 'R_19', 'B_32', 'S_20',\n 'R_20', 'R_21', 'D_89', 'R_22', 'R_23', 'D_91', 'D_92', 'D_93',\n 'D_94', 'R_24', 'R_25', 'D_96', 'S_22', 'S_23', 'S_25', 'S_26',\n 'D_102', 'D_103', 'B_36', 'R_27', 'D_109', 'D_112', 'S_27', 'D_113',\n 'D_114', 'D_115', 'D_116', 'D_117', 'D_120', 'D_121', 'D_122',\n 'D_123', 'D_124', 'D_125','D_126', 'D_127', 'D_128', 'B_41',\n 'D_130', 'D_133', 'R_28', 'D_139', 'D_140', 'D_144', 'D_145']\n\n\n, axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T19:03:37.560295Z","iopub.execute_input":"2022-07-29T19:03:37.560914Z","iopub.status.idle":"2022-07-29T19:03:38.104893Z","shell.execute_reply.started":"2022-07-29T19:03:37.560871Z","shell.execute_reply":"2022-07-29T19:03:38.103645Z"},"trusted":true},"execution_count":21,"outputs":[]},{"cell_type":"code","source":"ddf.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-29T19:04:03.757682Z","iopub.execute_input":"2022-07-29T19:04:03.758076Z","iopub.status.idle":"2022-07-29T19:04:03.768799Z","shell.execute_reply.started":"2022-07-29T19:04:03.758046Z","shell.execute_reply":"2022-07-29T19:04:03.767639Z"},"trusted":true},"execution_count":22,"outputs":[{"execution_count":22,"output_type":"execute_result","data":{"text/plain":"(924621, 123)"},"metadata":{}}]},{"cell_type":"code","source":"ddf.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T19:04:06.897719Z","iopub.execute_input":"2022-07-29T19:04:06.898107Z","iopub.status.idle":"2022-07-29T19:04:16.775181Z","shell.execute_reply.started":"2022-07-29T19:04:06.898076Z","shell.execute_reply":"2022-07-29T19:04:16.773754Z"},"trusted":true},"execution_count":23,"outputs":[{"execution_count":23,"output_type":"execute_result","data":{"text/plain":"customer_ID    924621\nP_2            919837\nD_39           924621\nB_1            924621\nR_1            924621\n                ...  \nR_28           924621\nD_139          919571\nD_140          924621\nD_144          924621\nD_145          919571\nLength: 123, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"#ddf.to_csv('test_new.csv', index= False)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T18:55:44.363648Z","iopub.execute_input":"2022-07-29T18:55:44.364047Z","iopub.status.idle":"2022-07-29T18:56:43.168721Z","shell.execute_reply.started":"2022-07-29T18:55:44.363988Z","shell.execute_reply":"2022-07-29T18:56:43.167518Z"},"trusted":true},"execution_count":20,"outputs":[]},{"cell_type":"code","source":"import catboost\nfrom catboost import *\nimport lightgbm as lgb","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:41:50.191366Z","iopub.execute_input":"2022-07-29T11:41:50.191706Z","iopub.status.idle":"2022-07-29T11:41:51.266291Z","shell.execute_reply.started":"2022-07-29T11:41:50.191675Z","shell.execute_reply":"2022-07-29T11:41:51.265252Z"},"trusted":true},"execution_count":10,"outputs":[{"output_type":"display_data","data":{"text/plain":"<IPython.core.display.HTML object>","text/html":"<style type='text/css'>\n.datatable table.frame { margin-bottom: 0; }\n.datatable table.frame thead { border-bottom: none; }\n.datatable table.frame tr.coltypes td {  color: #FFFFFF;  line-height: 6px;  padding: 0 0.5em;}\n.datatable .bool    { background: #DDDD99; }\n.datatable .object  { background: #565656; }\n.datatable .int     { background: #5D9E5D; }\n.datatable .float   { background: #4040CC; }\n.datatable .str     { background: #CC4040; }\n.datatable .time    { background: #40CC40; }\n.datatable .row_index {  background: var(--jp-border-color3);  border-right: 1px solid var(--jp-border-color0);  color: var(--jp-ui-font-color3);  font-size: 9px;}\n.datatable .frame tbody td { text-align: left; }\n.datatable .frame tr.coltypes .row_index {  background: var(--jp-border-color0);}\n.datatable th:nth-child(2) { padding-left: 12px; }\n.datatable .hellipsis {  color: var(--jp-cell-editor-border-color);}\n.datatable .vellipsis {  background: var(--jp-layout-color0);  color: var(--jp-cell-editor-border-color);}\n.datatable .na {  color: var(--jp-cell-editor-border-color);  font-size: 80%;}\n.datatable .sp {  opacity: 0.25;}\n.datatable .footer { font-size: 9px; }\n.datatable .frame_dimensions {  background: var(--jp-border-color3);  border-top: 1px solid var(--jp-border-color0);  color: var(--jp-ui-font-color3);  display: inline-block;  opacity: 0.6;  padding: 1px 10px 1px 5px;}\n</style>\n"},"metadata":{}}]},{"cell_type":"code","source":"df = pd.read_csv('../input/amex-refined-data/df_merge_1.csv')\ndf.drop('Unnamed: 0', inplace=True, axis=1)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:41:51.26762Z","iopub.execute_input":"2022-07-29T11:41:51.267936Z","iopub.status.idle":"2022-07-29T11:41:55.853466Z","shell.execute_reply.started":"2022-07-29T11:41:51.267907Z","shell.execute_reply":"2022-07-29T11:41:55.8524Z"},"trusted":true},"execution_count":11,"outputs":[{"execution_count":11,"output_type":"execute_result","data":{"text/plain":"                                         customer_ID         S_2       P_2  \\\n0  049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...  2017-06-28  0.646443   \n1  049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...  2017-07-29  0.678957   \n2  049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...  2017-08-29  0.596738   \n3  049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...  2017-09-28  0.562010   \n4  049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...  2017-10-28  0.579042   \n\n       D_39       B_1       R_1       S_3      D_41      D_43      D_44  ...  \\\n0  0.003469  0.005910  0.001193  0.350619  0.004155  0.181031  0.129174  ...   \n1  0.002406  0.002401  0.002783  0.099639  0.001750  0.380634  0.127985  ...   \n2  0.002992  0.008875  0.009667  0.302294  0.002089  0.253343  0.252516  ...   \n3  0.008478  0.009952  0.008482  0.125204  0.005918  0.216366  0.251808  ...   \n4  0.003158  0.002666  0.003798  0.463154  0.004334  0.202221  0.255705  ...   \n\n      D_128      B_41     D_130     D_133      R_28     D_139     D_140  \\\n0  0.001340  0.002906  0.008399  0.005409  0.004898  0.018179  0.004253   \n1  0.006370  0.006544  0.009645  0.006835  0.001462  0.018179  0.003184   \n2  0.005337  0.008663  0.000683  0.007491  0.007990  0.018179  0.005652   \n3  0.003993  0.006707  0.003684  0.003582  0.001176  0.018179  0.009931   \n4  0.005632  0.001383  0.005206  0.003378  0.009943  0.018179  0.001935   \n\n      D_144    D_145  target  \n0  0.016517  0.01821       0  \n1  0.016517  0.01821       0  \n2  0.016517  0.01821       0  \n3  0.016517  0.01821       0  \n4  0.016517  0.01821       0  \n\n[5 rows x 125 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>customer_ID</th>\n      <th>S_2</th>\n      <th>P_2</th>\n      <th>D_39</th>\n      <th>B_1</th>\n      <th>R_1</th>\n      <th>S_3</th>\n      <th>D_41</th>\n      <th>D_43</th>\n      <th>D_44</th>\n      <th>...</th>\n      <th>D_128</th>\n      <th>B_41</th>\n      <th>D_130</th>\n      <th>D_133</th>\n      <th>R_28</th>\n      <th>D_139</th>\n      <th>D_140</th>\n      <th>D_144</th>\n      <th>D_145</th>\n      <th>target</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...</td>\n      <td>2017-06-28</td>\n      <td>0.646443</td>\n      <td>0.003469</td>\n      <td>0.005910</td>\n      <td>0.001193</td>\n      <td>0.350619</td>\n      <td>0.004155</td>\n      <td>0.181031</td>\n      <td>0.129174</td>\n      <td>...</td>\n      <td>0.001340</td>\n      <td>0.002906</td>\n      <td>0.008399</td>\n      <td>0.005409</td>\n      <td>0.004898</td>\n      <td>0.018179</td>\n      <td>0.004253</td>\n      <td>0.016517</td>\n      <td>0.01821</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...</td>\n      <td>2017-07-29</td>\n      <td>0.678957</td>\n      <td>0.002406</td>\n      <td>0.002401</td>\n      <td>0.002783</td>\n      <td>0.099639</td>\n      <td>0.001750</td>\n      <td>0.380634</td>\n      <td>0.127985</td>\n      <td>...</td>\n      <td>0.006370</td>\n      <td>0.006544</td>\n      <td>0.009645</td>\n      <td>0.006835</td>\n      <td>0.001462</td>\n      <td>0.018179</td>\n      <td>0.003184</td>\n      <td>0.016517</td>\n      <td>0.01821</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...</td>\n      <td>2017-08-29</td>\n      <td>0.596738</td>\n      <td>0.002992</td>\n      <td>0.008875</td>\n      <td>0.009667</td>\n      <td>0.302294</td>\n      <td>0.002089</td>\n      <td>0.253343</td>\n      <td>0.252516</td>\n      <td>...</td>\n      <td>0.005337</td>\n      <td>0.008663</td>\n      <td>0.000683</td>\n      <td>0.007491</td>\n      <td>0.007990</td>\n      <td>0.018179</td>\n      <td>0.005652</td>\n      <td>0.016517</td>\n      <td>0.01821</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...</td>\n      <td>2017-09-28</td>\n      <td>0.562010</td>\n      <td>0.008478</td>\n      <td>0.009952</td>\n      <td>0.008482</td>\n      <td>0.125204</td>\n      <td>0.005918</td>\n      <td>0.216366</td>\n      <td>0.251808</td>\n      <td>...</td>\n      <td>0.003993</td>\n      <td>0.006707</td>\n      <td>0.003684</td>\n      <td>0.003582</td>\n      <td>0.001176</td>\n      <td>0.018179</td>\n      <td>0.009931</td>\n      <td>0.016517</td>\n      <td>0.01821</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>049e0948e285ec6767bf07e6e3f5e0919821ee200e359d...</td>\n      <td>2017-10-28</td>\n      <td>0.579042</td>\n      <td>0.003158</td>\n      <td>0.002666</td>\n      <td>0.003798</td>\n      <td>0.463154</td>\n      <td>0.004334</td>\n      <td>0.202221</td>\n      <td>0.255705</td>\n      <td>...</td>\n      <td>0.005632</td>\n      <td>0.001383</td>\n      <td>0.005206</td>\n      <td>0.003378</td>\n      <td>0.009943</td>\n      <td>0.018179</td>\n      <td>0.001935</td>\n      <td>0.016517</td>\n      <td>0.01821</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 125 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"df1 = pd.read_csv('../input/amex-refined-data/df_merge.csv')\ndf1.drop('Unnamed: 0', inplace=True, axis=1)\ndf1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:41:55.855048Z","iopub.execute_input":"2022-07-29T11:41:55.85583Z","iopub.status.idle":"2022-07-29T11:42:00.173377Z","shell.execute_reply.started":"2022-07-29T11:41:55.855793Z","shell.execute_reply":"2022-07-29T11:42:00.172323Z"},"trusted":true},"execution_count":12,"outputs":[{"execution_count":12,"output_type":"execute_result","data":{"text/plain":"                                         customer_ID         S_2       P_2  \\\n0  00000fd6641609c6ece5454664794f0340ad84dddce9a2...  2017-03-01  0.929122   \n1  00000fd6641609c6ece5454664794f0340ad84dddce9a2...  2017-04-16  0.918431   \n2  00000fd6641609c6ece5454664794f0340ad84dddce9a2...  2017-05-07  0.922563   \n3  00000fd6641609c6ece5454664794f0340ad84dddce9a2...  2017-06-25  0.919253   \n4  00000fd6641609c6ece5454664794f0340ad84dddce9a2...  2017-07-30  0.901860   \n\n       D_39       B_1       R_1       S_3      D_41      D_43      D_44  ...  \\\n0  0.382790  0.025782  0.005515  0.089799  0.001479  0.136476  0.009873  ...   \n1  0.002224  0.006806  0.003287  0.095966  0.007831  0.054606  0.007450  ...   \n2  0.567403  0.033713  0.005594  0.094655  0.003162  0.101951  0.004221  ...   \n3  0.213193  0.031170  0.008996  0.099089  0.009513  0.015646  0.001658  ...   \n4  0.325467  0.109644  0.008041  0.108526  0.000732  0.040903  0.001454  ...   \n\n      D_128      B_41     D_130     D_133      R_28     D_139     D_140  \\\n0  1.002662  0.002124  0.002148  0.001289  0.003198  0.003776  0.001808   \n1  1.004011  0.004754  0.003031  0.001774  0.009974  0.004046  0.008288   \n2  1.003222  0.007655  0.002805  0.001329  0.002501  0.007742  0.002693   \n3  1.003092  0.001912  0.006008  0.006118  0.006614  0.002502  0.003399   \n4  1.000972  0.009942  0.006812  0.002646  0.003082  0.000275  0.007992   \n\n      D_144     D_145  target  \n0  0.000027  0.002629       0  \n1  0.002669  0.006912       0  \n2  0.003254  0.004469       0  \n3  0.004325  0.006308       0  \n4  0.002979  0.005527       0  \n\n[5 rows x 125 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>customer_ID</th>\n      <th>S_2</th>\n      <th>P_2</th>\n      <th>D_39</th>\n      <th>B_1</th>\n      <th>R_1</th>\n      <th>S_3</th>\n      <th>D_41</th>\n      <th>D_43</th>\n      <th>D_44</th>\n      <th>...</th>\n      <th>D_128</th>\n      <th>B_41</th>\n      <th>D_130</th>\n      <th>D_133</th>\n      <th>R_28</th>\n      <th>D_139</th>\n      <th>D_140</th>\n      <th>D_144</th>\n      <th>D_145</th>\n      <th>target</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>00000fd6641609c6ece5454664794f0340ad84dddce9a2...</td>\n      <td>2017-03-01</td>\n      <td>0.929122</td>\n      <td>0.382790</td>\n      <td>0.025782</td>\n      <td>0.005515</td>\n      <td>0.089799</td>\n      <td>0.001479</td>\n      <td>0.136476</td>\n      <td>0.009873</td>\n      <td>...</td>\n      <td>1.002662</td>\n      <td>0.002124</td>\n      <td>0.002148</td>\n      <td>0.001289</td>\n      <td>0.003198</td>\n      <td>0.003776</td>\n      <td>0.001808</td>\n      <td>0.000027</td>\n      <td>0.002629</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>00000fd6641609c6ece5454664794f0340ad84dddce9a2...</td>\n      <td>2017-04-16</td>\n      <td>0.918431</td>\n      <td>0.002224</td>\n      <td>0.006806</td>\n      <td>0.003287</td>\n      <td>0.095966</td>\n      <td>0.007831</td>\n      <td>0.054606</td>\n      <td>0.007450</td>\n      <td>...</td>\n      <td>1.004011</td>\n      <td>0.004754</td>\n      <td>0.003031</td>\n      <td>0.001774</td>\n      <td>0.009974</td>\n      <td>0.004046</td>\n      <td>0.008288</td>\n      <td>0.002669</td>\n      <td>0.006912</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>00000fd6641609c6ece5454664794f0340ad84dddce9a2...</td>\n      <td>2017-05-07</td>\n      <td>0.922563</td>\n      <td>0.567403</td>\n      <td>0.033713</td>\n      <td>0.005594</td>\n      <td>0.094655</td>\n      <td>0.003162</td>\n      <td>0.101951</td>\n      <td>0.004221</td>\n      <td>...</td>\n      <td>1.003222</td>\n      <td>0.007655</td>\n      <td>0.002805</td>\n      <td>0.001329</td>\n      <td>0.002501</td>\n      <td>0.007742</td>\n      <td>0.002693</td>\n      <td>0.003254</td>\n      <td>0.004469</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>00000fd6641609c6ece5454664794f0340ad84dddce9a2...</td>\n      <td>2017-06-25</td>\n      <td>0.919253</td>\n      <td>0.213193</td>\n      <td>0.031170</td>\n      <td>0.008996</td>\n      <td>0.099089</td>\n      <td>0.009513</td>\n      <td>0.015646</td>\n      <td>0.001658</td>\n      <td>...</td>\n      <td>1.003092</td>\n      <td>0.001912</td>\n      <td>0.006008</td>\n      <td>0.006118</td>\n      <td>0.006614</td>\n      <td>0.002502</td>\n      <td>0.003399</td>\n      <td>0.004325</td>\n      <td>0.006308</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>00000fd6641609c6ece5454664794f0340ad84dddce9a2...</td>\n      <td>2017-07-30</td>\n      <td>0.901860</td>\n      <td>0.325467</td>\n      <td>0.109644</td>\n      <td>0.008041</td>\n      <td>0.108526</td>\n      <td>0.000732</td>\n      <td>0.040903</td>\n      <td>0.001454</td>\n      <td>...</td>\n      <td>1.000972</td>\n      <td>0.009942</td>\n      <td>0.006812</td>\n      <td>0.002646</td>\n      <td>0.003082</td>\n      <td>0.000275</td>\n      <td>0.007992</td>\n      <td>0.002979</td>\n      <td>0.005527</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 125 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"jdf = pd.concat([df, df1], axis=0,ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:00.174847Z","iopub.execute_input":"2022-07-29T11:42:00.175187Z","iopub.status.idle":"2022-07-29T11:42:00.257815Z","shell.execute_reply.started":"2022-07-29T11:42:00.17515Z","shell.execute_reply":"2022-07-29T11:42:00.256952Z"},"trusted":true},"execution_count":13,"outputs":[]},{"cell_type":"code","source":"for col in ddf.columns:\n    ddf[col][ddf[col].isnull()] = ddf[col].dropna().sample(ddf[col].isnull().sum()).values","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:00.259578Z","iopub.execute_input":"2022-07-29T11:42:00.260387Z","iopub.status.idle":"2022-07-29T11:42:05.977834Z","shell.execute_reply.started":"2022-07-29T11:42:00.260342Z","shell.execute_reply":"2022-07-29T11:42:05.976887Z"},"trusted":true},"execution_count":14,"outputs":[{"name":"stderr","text":"/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \nA value is trying to be set on a copy of a slice from a DataFrame\n\nSee the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n  \n","output_type":"stream"}]},{"cell_type":"code","source":"ddf.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:05.979467Z","iopub.execute_input":"2022-07-29T11:42:05.979922Z","iopub.status.idle":"2022-07-29T11:42:05.999175Z","shell.execute_reply.started":"2022-07-29T11:42:05.979867Z","shell.execute_reply":"2022-07-29T11:42:05.998401Z"},"trusted":true},"execution_count":15,"outputs":[{"name":"stdout","text":"<class 'pandas.core.frame.DataFrame'>\nInt64Index: 924621 entries, 8 to 21520\nColumns: 123 entries, customer_ID to D_145\ndtypes: float64(120), object(3)\nmemory usage: 874.7+ MB\n","output_type":"stream"}]},{"cell_type":"code","source":"cat_col = ['D_63', 'D_64']","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:06.000361Z","iopub.execute_input":"2022-07-29T11:42:06.001273Z","iopub.status.idle":"2022-07-29T11:42:06.005822Z","shell.execute_reply.started":"2022-07-29T11:42:06.001238Z","shell.execute_reply":"2022-07-29T11:42:06.004662Z"},"trusted":true},"execution_count":16,"outputs":[]},{"cell_type":"code","source":"for col in ddf[cat_col].columns:\n    var = ddf[col].value_counts()\n    cat = ddf[col].value_counts().index.tolist()\n    print(cat)\n    freq = []\n    for i in var:\n        freq.append(i/ddf[col].count())\n        print(freq)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:06.007836Z","iopub.execute_input":"2022-07-29T11:42:06.008376Z","iopub.status.idle":"2022-07-29T11:42:06.596119Z","shell.execute_reply.started":"2022-07-29T11:42:06.008345Z","shell.execute_reply":"2022-07-29T11:42:06.594862Z"},"trusted":true},"execution_count":17,"outputs":[{"name":"stdout","text":"['CO', 'CR', 'CL', 'XZ', 'XM', 'XL']\n[0.7407370154906713]\n[0.7407370154906713, 0.1584043624360684]\n[0.7407370154906713, 0.1584043624360684, 0.08066223890653576]\n[0.7407370154906713, 0.1584043624360684, 0.08066223890653576, 0.012053587361740649]\n[0.7407370154906713, 0.1584043624360684, 0.08066223890653576, 0.012053587361740649, 0.005323262179855313]\n[0.7407370154906713, 0.1584043624360684, 0.08066223890653576, 0.012053587361740649, 0.005323262179855313, 0.002819533625128566]\n['O', 'U', 'R']\n[0.5357146333470687]\n[0.5357146333470687, 0.2694412088845051]\n[0.5357146333470687, 0.2694412088845051, 0.1948441577684262]\n","output_type":"stream"}]},{"cell_type":"code","source":"ddf['D_63'].replace(['CO', 'CR', 'CL', 'XZ', 'XM', 'XL'],[0.74073, 0.1584, 0.08066, 0.01205, 0.005323,  0.00281], inplace=True)\nddf['D_63'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:06.597621Z","iopub.execute_input":"2022-07-29T11:42:06.597963Z","iopub.status.idle":"2022-07-29T11:42:06.979741Z","shell.execute_reply.started":"2022-07-29T11:42:06.597932Z","shell.execute_reply":"2022-07-29T11:42:06.978604Z"},"trusted":true},"execution_count":18,"outputs":[{"execution_count":18,"output_type":"execute_result","data":{"text/plain":"0.740730    684901\n0.158400    146464\n0.080660     74582\n0.012050     11145\n0.005323      4922\n0.002810      2607\nName: D_63, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"ddf['D_64'].replace(['O', 'U', 'R'],[0.5355, 0.269559, 0.19487], inplace=True)\nddf['D_64'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:06.981347Z","iopub.execute_input":"2022-07-29T11:42:06.981682Z","iopub.status.idle":"2022-07-29T11:42:07.25205Z","shell.execute_reply.started":"2022-07-29T11:42:06.981653Z","shell.execute_reply":"2022-07-29T11:42:07.250937Z"},"trusted":true},"execution_count":19,"outputs":[{"execution_count":19,"output_type":"execute_result","data":{"text/plain":"0.535500    495333\n0.269559    249131\n0.194870    180157\nName: D_64, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"cat_features = ['customer_ID']","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:07.253943Z","iopub.execute_input":"2022-07-29T11:42:07.254662Z","iopub.status.idle":"2022-07-29T11:42:07.260087Z","shell.execute_reply.started":"2022-07-29T11:42:07.254616Z","shell.execute_reply":"2022-07-29T11:42:07.258996Z"},"trusted":true},"execution_count":20,"outputs":[]},{"cell_type":"code","source":"y = jdf.target\nx = jdf.drop(['target', 'S_2'], axis=1)\nx_test = ddf","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:07.261724Z","iopub.execute_input":"2022-07-29T11:42:07.262371Z","iopub.status.idle":"2022-07-29T11:42:07.342545Z","shell.execute_reply.started":"2022-07-29T11:42:07.262327Z","shell.execute_reply":"2022-07-29T11:42:07.341041Z"},"trusted":true},"execution_count":21,"outputs":[]},{"cell_type":"code","source":"model = CatBoostClassifier(iterations = 300, learning_rate=0.01, random_seed=3, loss_function='CrossEntropy')\nmodel.fit(x,y, cat_features=cat_features, verbose=False, plot=True)\ny_pred = model.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:42:07.344207Z","iopub.execute_input":"2022-07-29T11:42:07.344712Z","iopub.status.idle":"2022-07-29T11:43:05.632807Z","shell.execute_reply.started":"2022-07-29T11:42:07.344673Z","shell.execute_reply":"2022-07-29T11:43:05.631543Z"},"trusted":true},"execution_count":22,"outputs":[{"output_type":"display_data","data":{"text/plain":"MetricVisualizer(layout=Layout(align_self='stretch', height='500px'))","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"003e66a2a41d470a944439447eb921ff"}},"metadata":{}}]},{"cell_type":"code","source":"unique, counts = np.unique(y_pred, return_counts=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:52:39.871653Z","iopub.execute_input":"2022-07-29T11:52:39.87216Z","iopub.status.idle":"2022-07-29T11:52:39.902575Z","shell.execute_reply.started":"2022-07-29T11:52:39.872107Z","shell.execute_reply":"2022-07-29T11:52:39.90145Z"},"trusted":true},"execution_count":32,"outputs":[]},{"cell_type":"code","source":"unique","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:52:46.72272Z","iopub.execute_input":"2022-07-29T11:52:46.723751Z","iopub.status.idle":"2022-07-29T11:52:46.731578Z","shell.execute_reply.started":"2022-07-29T11:52:46.723694Z","shell.execute_reply":"2022-07-29T11:52:46.730438Z"},"trusted":true},"execution_count":33,"outputs":[{"execution_count":33,"output_type":"execute_result","data":{"text/plain":"array([0, 1])"},"metadata":{}}]},{"cell_type":"code","source":"counts","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:52:50.301375Z","iopub.execute_input":"2022-07-29T11:52:50.302676Z","iopub.status.idle":"2022-07-29T11:52:50.310478Z","shell.execute_reply.started":"2022-07-29T11:52:50.302619Z","shell.execute_reply":"2022-07-29T11:52:50.309199Z"},"trusted":true},"execution_count":34,"outputs":[{"execution_count":34,"output_type":"execute_result","data":{"text/plain":"array([674251, 250370])"},"metadata":{}}]},{"cell_type":"code","source":"ddf1 = pd.DataFrame(data=y_pred, columns = ['prediction'])","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:52:57.151163Z","iopub.execute_input":"2022-07-29T11:52:57.151614Z","iopub.status.idle":"2022-07-29T11:52:57.157794Z","shell.execute_reply.started":"2022-07-29T11:52:57.151574Z","shell.execute_reply":"2022-07-29T11:52:57.156556Z"},"trusted":true},"execution_count":35,"outputs":[]},{"cell_type":"code","source":"ddf1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:53:04.896051Z","iopub.execute_input":"2022-07-29T11:53:04.896476Z","iopub.status.idle":"2022-07-29T11:53:04.908098Z","shell.execute_reply.started":"2022-07-29T11:53:04.896441Z","shell.execute_reply":"2022-07-29T11:53:04.907222Z"},"trusted":true},"execution_count":36,"outputs":[{"execution_count":36,"output_type":"execute_result","data":{"text/plain":"   prediction\n0           0\n1           0\n2           0\n3           0\n4           1","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>prediction</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ddf1.insert(0,'customer_ID',ddf['customer_ID'].values)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:53:08.563743Z","iopub.execute_input":"2022-07-29T11:53:08.564307Z","iopub.status.idle":"2022-07-29T11:53:08.597126Z","shell.execute_reply.started":"2022-07-29T11:53:08.564254Z","shell.execute_reply":"2022-07-29T11:53:08.596078Z"},"trusted":true},"execution_count":37,"outputs":[]},{"cell_type":"code","source":"ddf1['customer_ID'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:53:14.408854Z","iopub.execute_input":"2022-07-29T11:53:14.409906Z","iopub.status.idle":"2022-07-29T11:53:14.827253Z","shell.execute_reply.started":"2022-07-29T11:53:14.409862Z","shell.execute_reply":"2022-07-29T11:53:14.826188Z"},"trusted":true},"execution_count":38,"outputs":[{"execution_count":38,"output_type":"execute_result","data":{"text/plain":"924621"},"metadata":{}}]},{"cell_type":"code","source":"ddf1.to_csv('submission_new.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:53:46.109268Z","iopub.execute_input":"2022-07-29T11:53:46.109676Z","iopub.status.idle":"2022-07-29T11:53:48.187181Z","shell.execute_reply.started":"2022-07-29T11:53:46.109643Z","shell.execute_reply":"2022-07-29T11:53:48.186125Z"},"trusted":true},"execution_count":40,"outputs":[]},{"cell_type":"code","source":"fd = pd.read_csv('./submission_new.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:54:02.837492Z","iopub.execute_input":"2022-07-29T11:54:02.837941Z","iopub.status.idle":"2022-07-29T11:54:04.081282Z","shell.execute_reply.started":"2022-07-29T11:54:02.837901Z","shell.execute_reply":"2022-07-29T11:54:04.079993Z"},"trusted":true},"execution_count":41,"outputs":[]},{"cell_type":"code","source":"fd.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:54:08.440873Z","iopub.execute_input":"2022-07-29T11:54:08.441293Z","iopub.status.idle":"2022-07-29T11:54:08.452439Z","shell.execute_reply.started":"2022-07-29T11:54:08.441251Z","shell.execute_reply":"2022-07-29T11:54:08.451317Z"},"trusted":true},"execution_count":42,"outputs":[{"execution_count":42,"output_type":"execute_result","data":{"text/plain":"                                         customer_ID  prediction\n0  00000469ba478561f23a92a868bd366de6f6527a684c9a...           0\n1  00001bf2e77ff879fab36aa4fac689b9ba411dae63ae39...           0\n2  0000210045da4f81e5f122c6bde5c2a617d03eef67f82c...           0\n3  00003b41e58ede33b8daf61ab56d9952f17c9ad1c3976c...           0\n4  00004b22eaeeeb0ec976890c1d9bfc14fd9427e98c4ee9...           1","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>customer_ID</th>\n      <th>prediction</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>00000469ba478561f23a92a868bd366de6f6527a684c9a...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>00001bf2e77ff879fab36aa4fac689b9ba411dae63ae39...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0000210045da4f81e5f122c6bde5c2a617d03eef67f82c...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>00003b41e58ede33b8daf61ab56d9952f17c9ad1c3976c...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>00004b22eaeeeb0ec976890c1d9bfc14fd9427e98c4ee9...</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"fd.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T11:54:13.297718Z","iopub.execute_input":"2022-07-29T11:54:13.298128Z","iopub.status.idle":"2022-07-29T11:54:13.726054Z","shell.execute_reply.started":"2022-07-29T11:54:13.298092Z","shell.execute_reply":"2022-07-29T11:54:13.724855Z"},"trusted":true},"execution_count":43,"outputs":[{"execution_count":43,"output_type":"execute_result","data":{"text/plain":"customer_ID    924621\nprediction          2\ndtype: int64"},"metadata":{}}]}]}