{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-14T18:56:06.651830Z","iopub.execute_input":"2022-06-14T18:56:06.652431Z","iopub.status.idle":"2022-06-14T18:56:06.663550Z","shell.execute_reply.started":"2022-06-14T18:56:06.652394Z","shell.execute_reply":"2022-06-14T18:56:06.662601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.preprocessing import StandardScaler  \nfrom sklearn.model_selection import train_test_split\nfrom xgboost import XGBClassifier\nfrom sklearn.metrics import confusion_matrix, accuracy_score, classification_report\nfrom sklearn.metrics import roc_auc_score,roc_curve\nfrom sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score\nfrom warnings import filterwarnings\nfilterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:06.667982Z","iopub.execute_input":"2022-06-14T18:56:06.668393Z","iopub.status.idle":"2022-06-14T18:56:06.673625Z","shell.execute_reply.started":"2022-06-14T18:56:06.668362Z","shell.execute_reply":"2022-06-14T18:56:06.672867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nrows=50000","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:06.679848Z","iopub.execute_input":"2022-06-14T18:56:06.680119Z","iopub.status.idle":"2022-06-14T18:56:06.686649Z","shell.execute_reply.started":"2022-06-14T18:56:06.680088Z","shell.execute_reply":"2022-06-14T18:56:06.685815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data=pd.read_csv(\"../input/amex-default-prediction/train_data.csv\",nrows=nrows)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:06.699325Z","iopub.execute_input":"2022-06-14T18:56:06.700088Z","iopub.status.idle":"2022-06-14T18:56:08.775917Z","shell.execute_reply.started":"2022-06-14T18:56:06.700050Z","shell.execute_reply":"2022-06-14T18:56:08.775138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=pd.read_csv(\"../input/amex-default-prediction/train_labels.csv\",nrows=nrows)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:08.777809Z","iopub.execute_input":"2022-06-14T18:56:08.778601Z","iopub.status.idle":"2022-06-14T18:56:08.837304Z","shell.execute_reply.started":"2022-06-14T18:56:08.778553Z","shell.execute_reply":"2022-06-14T18:56:08.836566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data=pd.read_csv(\"../input/amex-default-prediction/test_data.csv\",nrows=nrows)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:08.840632Z","iopub.execute_input":"2022-06-14T18:56:08.840937Z","iopub.status.idle":"2022-06-14T18:56:10.894854Z","shell.execute_reply.started":"2022-06-14T18:56:08.840905Z","shell.execute_reply":"2022-06-14T18:56:10.893986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:10.897114Z","iopub.execute_input":"2022-06-14T18:56:10.897357Z","iopub.status.idle":"2022-06-14T18:56:10.928943Z","shell.execute_reply.started":"2022-06-14T18:56:10.897328Z","shell.execute_reply":"2022-06-14T18:56:10.928092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:10.930626Z","iopub.execute_input":"2022-06-14T18:56:10.931208Z","iopub.status.idle":"2022-06-14T18:56:10.958180Z","shell.execute_reply.started":"2022-06-14T18:56:10.931167Z","shell.execute_reply":"2022-06-14T18:56:10.957391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:10.959831Z","iopub.execute_input":"2022-06-14T18:56:10.960416Z","iopub.status.idle":"2022-06-14T18:56:10.970170Z","shell.execute_reply.started":"2022-06-14T18:56:10.960374Z","shell.execute_reply":"2022-06-14T18:56:10.969591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.merge(train_data,train_labels,how=\"inner\")","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:10.971959Z","iopub.execute_input":"2022-06-14T18:56:10.972693Z","iopub.status.idle":"2022-06-14T18:56:11.098655Z","shell.execute_reply.started":"2022-06-14T18:56:10.972650Z","shell.execute_reply":"2022-06-14T18:56:11.097776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.100037Z","iopub.execute_input":"2022-06-14T18:56:11.100362Z","iopub.status.idle":"2022-06-14T18:56:11.128653Z","shell.execute_reply.started":"2022-06-14T18:56:11.100325Z","shell.execute_reply":"2022-06-14T18:56:11.127683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.129920Z","iopub.execute_input":"2022-06-14T18:56:11.130303Z","iopub.status.idle":"2022-06-14T18:56:11.809396Z","shell.execute_reply.started":"2022-06-14T18:56:11.130260Z","shell.execute_reply":"2022-06-14T18:56:11.808587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.812087Z","iopub.execute_input":"2022-06-14T18:56:11.812355Z","iopub.status.idle":"2022-06-14T18:56:11.837340Z","shell.execute_reply.started":"2022-06-14T18:56:11.812326Z","shell.execute_reply":"2022-06-14T18:56:11.836678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.840083Z","iopub.execute_input":"2022-06-14T18:56:11.840689Z","iopub.status.idle":"2022-06-14T18:56:11.849037Z","shell.execute_reply.started":"2022-06-14T18:56:11.840646Z","shell.execute_reply":"2022-06-14T18:56:11.848093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"target\"].unique","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.851869Z","iopub.execute_input":"2022-06-14T18:56:11.852176Z","iopub.status.idle":"2022-06-14T18:56:11.861987Z","shell.execute_reply.started":"2022-06-14T18:56:11.852148Z","shell.execute_reply":"2022-06-14T18:56:11.861343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(train[\"target\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.863023Z","iopub.execute_input":"2022-06-14T18:56:11.863556Z","iopub.status.idle":"2022-06-14T18:56:11.872761Z","shell.execute_reply.started":"2022-06-14T18:56:11.863516Z","shell.execute_reply":"2022-06-14T18:56:11.871896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train[\"customer_ID\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.873849Z","iopub.execute_input":"2022-06-14T18:56:11.874151Z","iopub.status.idle":"2022-06-14T18:56:11.881518Z","shell.execute_reply.started":"2022-06-14T18:56:11.874114Z","shell.execute_reply":"2022-06-14T18:56:11.880811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train[\"target\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.882535Z","iopub.execute_input":"2022-06-14T18:56:11.882732Z","iopub.status.idle":"2022-06-14T18:56:11.891298Z","shell.execute_reply.started":"2022-06-14T18:56:11.882708Z","shell.execute_reply":"2022-06-14T18:56:11.890711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.892816Z","iopub.execute_input":"2022-06-14T18:56:11.893371Z","iopub.status.idle":"2022-06-14T18:56:11.924277Z","shell.execute_reply.started":"2022-06-14T18:56:11.893329Z","shell.execute_reply":"2022-06-14T18:56:11.923409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = train.columns\nnum_cols=train._get_numeric_data().columns\n","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.925918Z","iopub.execute_input":"2022-06-14T18:56:11.926603Z","iopub.status.idle":"2022-06-14T18:56:11.931909Z","shell.execute_reply.started":"2022-06-14T18:56:11.926560Z","shell.execute_reply":"2022-06-14T18:56:11.931129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list(set(cols) - set(num_cols))","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.933117Z","iopub.execute_input":"2022-06-14T18:56:11.933323Z","iopub.status.idle":"2022-06-14T18:56:11.944055Z","shell.execute_reply.started":"2022-06-14T18:56:11.933300Z","shell.execute_reply":"2022-06-14T18:56:11.943521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[[\"S_2\",\"customer_ID\",\"D_64\",\"D_63\"]]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.945125Z","iopub.execute_input":"2022-06-14T18:56:11.945665Z","iopub.status.idle":"2022-06-14T18:56:11.966707Z","shell.execute_reply.started":"2022-06-14T18:56:11.945633Z","shell.execute_reply":"2022-06-14T18:56:11.966033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.to_datetime(train['S_2']).astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:11.967758Z","iopub.execute_input":"2022-06-14T18:56:11.968106Z","iopub.status.idle":"2022-06-14T18:56:12.011966Z","shell.execute_reply.started":"2022-06-14T18:56:11.968079Z","shell.execute_reply":"2022-06-14T18:56:12.011070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.S_2.max()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.013254Z","iopub.execute_input":"2022-06-14T18:56:12.013528Z","iopub.status.idle":"2022-06-14T18:56:12.028188Z","shell.execute_reply.started":"2022-06-14T18:56:12.013480Z","shell.execute_reply":"2022-06-14T18:56:12.027292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(pd.to_datetime(train['S_2']).astype('int64'))","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.029424Z","iopub.execute_input":"2022-06-14T18:56:12.029717Z","iopub.status.idle":"2022-06-14T18:56:12.072380Z","shell.execute_reply.started":"2022-06-14T18:56:12.029689Z","shell.execute_reply":"2022-06-14T18:56:12.071591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain['S_2'] = pd.to_datetime(train['S_2']).astype('int64')\nmax_a = train.S_2.max()\nmin_a = train.S_2.min()\nmin_norm = -1\nmax_norm =1\n","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.073827Z","iopub.execute_input":"2022-06-14T18:56:12.074281Z","iopub.status.idle":"2022-06-14T18:56:12.114643Z","shell.execute_reply.started":"2022-06-14T18:56:12.074242Z","shell.execute_reply":"2022-06-14T18:56:12.113957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['S_2'] = (train.S_2- min_a) *(max_norm - min_norm) / (max_a-min_a) + min_norm","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.116493Z","iopub.execute_input":"2022-06-14T18:56:12.119199Z","iopub.status.idle":"2022-06-14T18:56:12.126132Z","shell.execute_reply.started":"2022-06-14T18:56:12.119164Z","shell.execute_reply":"2022-06-14T18:56:12.125461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot = pd.get_dummies(train, columns = [\"D_64\"], prefix = [\"D_64\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.127482Z","iopub.execute_input":"2022-06-14T18:56:12.128393Z","iopub.status.idle":"2022-06-14T18:56:12.222987Z","shell.execute_reply.started":"2022-06-14T18:56:12.128350Z","shell.execute_reply":"2022-06-14T18:56:12.222324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.224250Z","iopub.execute_input":"2022-06-14T18:56:12.224544Z","iopub.status.idle":"2022-06-14T18:56:12.251198Z","shell.execute_reply.started":"2022-06-14T18:56:12.224514Z","shell.execute_reply":"2022-06-14T18:56:12.250605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot2 = pd.get_dummies(df_one_hot, columns = [\"D_63\"], prefix = [\"D_63\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.252094Z","iopub.execute_input":"2022-06-14T18:56:12.252489Z","iopub.status.idle":"2022-06-14T18:56:12.339332Z","shell.execute_reply.started":"2022-06-14T18:56:12.252446Z","shell.execute_reply":"2022-06-14T18:56:12.338702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot2.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.345151Z","iopub.execute_input":"2022-06-14T18:56:12.345397Z","iopub.status.idle":"2022-06-14T18:56:12.368932Z","shell.execute_reply.started":"2022-06-14T18:56:12.345371Z","shell.execute_reply":"2022-06-14T18:56:12.367948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=df_one_hot2","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.370167Z","iopub.execute_input":"2022-06-14T18:56:12.370487Z","iopub.status.idle":"2022-06-14T18:56:12.375122Z","shell.execute_reply.started":"2022-06-14T18:56:12.370434Z","shell.execute_reply":"2022-06-14T18:56:12.374375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.376618Z","iopub.execute_input":"2022-06-14T18:56:12.377076Z","iopub.status.idle":"2022-06-14T18:56:12.390041Z","shell.execute_reply.started":"2022-06-14T18:56:12.377036Z","shell.execute_reply":"2022-06-14T18:56:12.389152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot3 = pd.get_dummies(train, columns = [\"customer_ID\"], prefix = [\"customer_ID\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.391221Z","iopub.execute_input":"2022-06-14T18:56:12.391664Z","iopub.status.idle":"2022-06-14T18:56:12.786914Z","shell.execute_reply.started":"2022-06-14T18:56:12.391616Z","shell.execute_reply":"2022-06-14T18:56:12.786160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot3.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.788506Z","iopub.execute_input":"2022-06-14T18:56:12.788996Z","iopub.status.idle":"2022-06-14T18:56:12.813906Z","shell.execute_reply.started":"2022-06-14T18:56:12.788965Z","shell.execute_reply":"2022-06-14T18:56:12.813278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=df_one_hot3","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.815206Z","iopub.execute_input":"2022-06-14T18:56:12.815631Z","iopub.status.idle":"2022-06-14T18:56:12.819324Z","shell.execute_reply.started":"2022-06-14T18:56:12.815601Z","shell.execute_reply":"2022-06-14T18:56:12.818536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.820441Z","iopub.execute_input":"2022-06-14T18:56:12.822018Z","iopub.status.idle":"2022-06-14T18:56:12.831231Z","shell.execute_reply.started":"2022-06-14T18:56:12.821985Z","shell.execute_reply":"2022-06-14T18:56:12.830527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler.fit(train)\nX_train_scaled = scaler.transform(train)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:12.832186Z","iopub.execute_input":"2022-06-14T18:56:12.832752Z","iopub.status.idle":"2022-06-14T18:56:24.820050Z","shell.execute_reply.started":"2022-06-14T18:56:12.832723Z","shell.execute_reply":"2022-06-14T18:56:24.819210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:24.823037Z","iopub.execute_input":"2022-06-14T18:56:24.823783Z","iopub.status.idle":"2022-06-14T18:56:24.854428Z","shell.execute_reply.started":"2022-06-14T18:56:24.823735Z","shell.execute_reply":"2022-06-14T18:56:24.853580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = train.copy()\ny = df[\"target\"]\nX = df.drop(['target'], axis=1)\n","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:24.855635Z","iopub.execute_input":"2022-06-14T18:56:24.855910Z","iopub.status.idle":"2022-06-14T18:56:25.086667Z","shell.execute_reply.started":"2022-06-14T18:56:24.855882Z","shell.execute_reply":"2022-06-14T18:56:25.085769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(y)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.088279Z","iopub.execute_input":"2022-06-14T18:56:25.088953Z","iopub.status.idle":"2022-06-14T18:56:25.095248Z","shell.execute_reply.started":"2022-06-14T18:56:25.088908Z","shell.execute_reply":"2022-06-14T18:56:25.094361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.columns","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.096661Z","iopub.execute_input":"2022-06-14T18:56:25.096973Z","iopub.status.idle":"2022-06-14T18:56:25.108262Z","shell.execute_reply.started":"2022-06-14T18:56:25.096932Z","shell.execute_reply":"2022-06-14T18:56:25.107388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.109176Z","iopub.execute_input":"2022-06-14T18:56:25.109404Z","iopub.status.idle":"2022-06-14T18:56:25.121219Z","shell.execute_reply.started":"2022-06-14T18:56:25.109378Z","shell.execute_reply":"2022-06-14T18:56:25.120578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(y)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.122083Z","iopub.execute_input":"2022-06-14T18:56:25.122303Z","iopub.status.idle":"2022-06-14T18:56:25.133784Z","shell.execute_reply.started":"2022-06-14T18:56:25.122277Z","shell.execute_reply":"2022-06-14T18:56:25.133000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, \n                                                    test_size=0.30, \n                                                    random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.135092Z","iopub.execute_input":"2022-06-14T18:56:25.135521Z","iopub.status.idle":"2022-06-14T18:56:25.650487Z","shell.execute_reply.started":"2022-06-14T18:56:25.135456Z","shell.execute_reply":"2022-06-14T18:56:25.649688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.651709Z","iopub.execute_input":"2022-06-14T18:56:25.651943Z","iopub.status.idle":"2022-06-14T18:56:25.658410Z","shell.execute_reply.started":"2022-06-14T18:56:25.651918Z","shell.execute_reply":"2022-06-14T18:56:25.657714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgb_model = XGBClassifier().fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T18:56:25.659413Z","iopub.execute_input":"2022-06-14T18:56:25.659742Z","iopub.status.idle":"2022-06-14T19:01:38.117217Z","shell.execute_reply.started":"2022-06-14T18:56:25.659712Z","shell.execute_reply":"2022-06-14T19:01:38.116383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgb_model","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:38.119236Z","iopub.execute_input":"2022-06-14T19:01:38.119538Z","iopub.status.idle":"2022-06-14T19:01:38.131569Z","shell.execute_reply.started":"2022-06-14T19:01:38.119510Z","shell.execute_reply":"2022-06-14T19:01:38.130781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(X_train.columns)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:38.132902Z","iopub.execute_input":"2022-06-14T19:01:38.133145Z","iopub.status.idle":"2022-06-14T19:01:38.139140Z","shell.execute_reply.started":"2022-06-14T19:01:38.133119Z","shell.execute_reply":"2022-06-14T19:01:38.138580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.iloc[:,:4283]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:38.140426Z","iopub.execute_input":"2022-06-14T19:01:38.140956Z","iopub.status.idle":"2022-06-14T19:01:38.292125Z","shell.execute_reply.started":"2022-06-14T19:01:38.140927Z","shell.execute_reply":"2022-06-14T19:01:38.291316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = xgb_model.predict(X_train)\naccuracy_score(y_train, y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:38.293318Z","iopub.execute_input":"2022-06-14T19:01:38.293573Z","iopub.status.idle":"2022-06-14T19:01:43.687680Z","shell.execute_reply.started":"2022-06-14T19:01:38.293547Z","shell.execute_reply":"2022-06-14T19:01:43.687032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = xgb_model.predict(X_test)\naccuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:43.689821Z","iopub.execute_input":"2022-06-14T19:01:43.690174Z","iopub.status.idle":"2022-06-14T19:01:45.186572Z","shell.execute_reply.started":"2022-06-14T19:01:43.690132Z","shell.execute_reply":"2022-06-14T19:01:45.185919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.190139Z","iopub.execute_input":"2022-06-14T19:01:45.190814Z","iopub.status.idle":"2022-06-14T19:01:45.220704Z","shell.execute_reply.started":"2022-06-14T19:01:45.190762Z","shell.execute_reply":"2022-06-14T19:01:45.219984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.224136Z","iopub.execute_input":"2022-06-14T19:01:45.224680Z","iopub.status.idle":"2022-06-14T19:01:45.231245Z","shell.execute_reply.started":"2022-06-14T19:01:45.224636Z","shell.execute_reply":"2022-06-14T19:01:45.230248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = test_data.columns\nnum_cols=train._get_numeric_data().columns","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.232741Z","iopub.execute_input":"2022-06-14T19:01:45.233227Z","iopub.status.idle":"2022-06-14T19:01:45.241085Z","shell.execute_reply.started":"2022-06-14T19:01:45.233186Z","shell.execute_reply":"2022-06-14T19:01:45.240502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list(set(cols) - set(num_cols))","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.241961Z","iopub.execute_input":"2022-06-14T19:01:45.242733Z","iopub.status.idle":"2022-06-14T19:01:45.257268Z","shell.execute_reply.started":"2022-06-14T19:01:45.242700Z","shell.execute_reply":"2022-06-14T19:01:45.256681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[['customer_ID', 'D_64', 'D_63']]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.258877Z","iopub.execute_input":"2022-06-14T19:01:45.259347Z","iopub.status.idle":"2022-06-14T19:01:45.279103Z","shell.execute_reply.started":"2022-06-14T19:01:45.259304Z","shell.execute_reply":"2022-06-14T19:01:45.278268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot1 = pd.get_dummies(test_data, columns = [\"D_63\"], prefix = [\"D_63\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.280347Z","iopub.execute_input":"2022-06-14T19:01:45.280560Z","iopub.status.idle":"2022-06-14T19:01:45.340921Z","shell.execute_reply.started":"2022-06-14T19:01:45.280536Z","shell.execute_reply":"2022-06-14T19:01:45.340161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot2 = pd.get_dummies(df_one_hot1, columns = [\"D_64\"], prefix = [\"D_64\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.342023Z","iopub.execute_input":"2022-06-14T19:01:45.342709Z","iopub.status.idle":"2022-06-14T19:01:45.447413Z","shell.execute_reply.started":"2022-06-14T19:01:45.342675Z","shell.execute_reply":"2022-06-14T19:01:45.446574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_one_hot2.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.449434Z","iopub.execute_input":"2022-06-14T19:01:45.450795Z","iopub.status.idle":"2022-06-14T19:01:45.474232Z","shell.execute_reply.started":"2022-06-14T19:01:45.450750Z","shell.execute_reply":"2022-06-14T19:01:45.473274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.get_dummies(df_one_hot2, columns = [\"customer_ID\"], prefix = [\"customer_ID\"])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.475684Z","iopub.execute_input":"2022-06-14T19:01:45.476079Z","iopub.status.idle":"2022-06-14T19:01:45.854708Z","shell.execute_reply.started":"2022-06-14T19:01:45.476036Z","shell.execute_reply":"2022-06-14T19:01:45.853953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in test.columns:\n    if i.startswith(\"D_63\"):\n        print(\"Yes\")\n    elif i.startswith(\"D_64\"):\n        print(\"Yes\")\n    else:\n        print(\"No\")","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:45.855946Z","iopub.execute_input":"2022-06-14T19:01:45.856247Z","iopub.status.idle":"2022-06-14T19:01:46.323744Z","shell.execute_reply.started":"2022-06-14T19:01:45.856212Z","shell.execute_reply":"2022-06-14T19:01:46.322870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\" OR \"\"\"","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.325169Z","iopub.execute_input":"2022-06-14T19:01:46.325630Z","iopub.status.idle":"2022-06-14T19:01:46.330760Z","shell.execute_reply.started":"2022-06-14T19:01:46.325584Z","shell.execute_reply":"2022-06-14T19:01:46.330173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" set([\"Yes\" if i.startswith(\"D_63\") else 'No' if i.startswith(\"D_64\") else 'No' for i in test.columns])","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.331941Z","iopub.execute_input":"2022-06-14T19:01:46.332136Z","iopub.status.idle":"2022-06-14T19:01:46.348086Z","shell.execute_reply.started":"2022-06-14T19:01:46.332112Z","shell.execute_reply":"2022-06-14T19:01:46.346497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.349233Z","iopub.execute_input":"2022-06-14T19:01:46.350720Z","iopub.status.idle":"2022-06-14T19:01:46.379511Z","shell.execute_reply.started":"2022-06-14T19:01:46.350672Z","shell.execute_reply":"2022-06-14T19:01:46.378741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['S_2'] = pd.to_datetime(test['S_2']).astype('int64')\nmax_a = test.S_2.max()\nmin_a = test.S_2.min()\nmin_norm = -1\nmax_norm =1\n","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.380444Z","iopub.execute_input":"2022-06-14T19:01:46.380678Z","iopub.status.idle":"2022-06-14T19:01:46.431560Z","shell.execute_reply.started":"2022-06-14T19:01:46.380653Z","shell.execute_reply":"2022-06-14T19:01:46.430952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['S_2'] = (test.S_2- min_a) *(max_norm - min_norm) / (max_a-min_a) + min_norm","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.432411Z","iopub.execute_input":"2022-06-14T19:01:46.433143Z","iopub.status.idle":"2022-06-14T19:01:46.439987Z","shell.execute_reply.started":"2022-06-14T19:01:46.433109Z","shell.execute_reply":"2022-06-14T19:01:46.439152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler.fit(test)\nX_test_scaled = scaler.transform(test)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:46.441670Z","iopub.execute_input":"2022-06-14T19:01:46.442233Z","iopub.status.idle":"2022-06-14T19:01:52.283268Z","shell.execute_reply.started":"2022-06-14T19:01:46.442193Z","shell.execute_reply":"2022-06-14T19:01:52.282592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgb_model = XGBClassifier().fit(X_train.iloc[:,:4283], y_train)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:01:52.284507Z","iopub.execute_input":"2022-06-14T19:01:52.284878Z","iopub.status.idle":"2022-06-14T19:07:05.487423Z","shell.execute_reply.started":"2022-06-14T19:01:52.284833Z","shell.execute_reply":"2022-06-14T19:07:05.486370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred = xgb_model.predict(X_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:05.490002Z","iopub.execute_input":"2022-06-14T19:07:05.490278Z","iopub.status.idle":"2022-06-14T19:07:11.886645Z","shell.execute_reply.started":"2022-06-14T19:07:05.490248Z","shell.execute_reply":"2022-06-14T19:07:11.885921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.888022Z","iopub.execute_input":"2022-06-14T19:07:11.888568Z","iopub.status.idle":"2022-06-14T19:07:11.918655Z","shell.execute_reply.started":"2022-06-14T19:07:11.888533Z","shell.execute_reply":"2022-06-14T19:07:11.917968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"customer_ID\"][0]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.920184Z","iopub.execute_input":"2022-06-14T19:07:11.920419Z","iopub.status.idle":"2022-06-14T19:07:11.925969Z","shell.execute_reply.started":"2022-06-14T19:07:11.920392Z","shell.execute_reply":"2022-06-14T19:07:11.925150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test[\"customer_ID_00000469ba478561f23a92a868bd366de6f6527a684c9a2e78fb826dcac3b9b7\"]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.927168Z","iopub.execute_input":"2022-06-14T19:07:11.927401Z","iopub.status.idle":"2022-06-14T19:07:11.943177Z","shell.execute_reply.started":"2022-06-14T19:07:11.927376Z","shell.execute_reply":"2022-06-14T19:07:11.942579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.944315Z","iopub.execute_input":"2022-06-14T19:07:11.944755Z","iopub.status.idle":"2022-06-14T19:07:11.954959Z","shell.execute_reply.started":"2022-06-14T19:07:11.944722Z","shell.execute_reply":"2022-06-14T19:07:11.954177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data[\"customer_ID\"]","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.956287Z","iopub.execute_input":"2022-06-14T19:07:11.956534Z","iopub.status.idle":"2022-06-14T19:07:11.970182Z","shell.execute_reply.started":"2022-06-14T19:07:11.956503Z","shell.execute_reply":"2022-06-14T19:07:11.969353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = ({\n    'customer_ID':test_data[\"customer_ID\"],\n    'prediction' :test_pred\n               })","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.971173Z","iopub.execute_input":"2022-06-14T19:07:11.971602Z","iopub.status.idle":"2022-06-14T19:07:11.979772Z","shell.execute_reply.started":"2022-06-14T19:07:11.971569Z","shell.execute_reply":"2022-06-14T19:07:11.979205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame(sub)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.980753Z","iopub.execute_input":"2022-06-14T19:07:11.981005Z","iopub.status.idle":"2022-06-14T19:07:11.993286Z","shell.execute_reply.started":"2022-06-14T19:07:11.980978Z","shell.execute_reply":"2022-06-14T19:07:11.992364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:11.994646Z","iopub.execute_input":"2022-06-14T19:07:11.994957Z","iopub.status.idle":"2022-06-14T19:07:12.010147Z","shell.execute_reply.started":"2022-06-14T19:07:11.994929Z","shell.execute_reply":"2022-06-14T19:07:12.009397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sub)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.011464Z","iopub.execute_input":"2022-06-14T19:07:12.011944Z","iopub.status.idle":"2022-06-14T19:07:12.018674Z","shell.execute_reply.started":"2022-06-14T19:07:12.011905Z","shell.execute_reply":"2022-06-14T19:07:12.017853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=sub.groupby([\"customer_ID\"])[\"prediction\"].agg('mean')","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.019992Z","iopub.execute_input":"2022-06-14T19:07:12.020220Z","iopub.status.idle":"2022-06-14T19:07:12.047761Z","shell.execute_reply.started":"2022-06-14T19:07:12.020195Z","shell.execute_reply":"2022-06-14T19:07:12.047101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.048884Z","iopub.execute_input":"2022-06-14T19:07:12.049562Z","iopub.status.idle":"2022-06-14T19:07:12.057894Z","shell.execute_reply.started":"2022-06-14T19:07:12.049516Z","shell.execute_reply":"2022-06-14T19:07:12.056983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(sub)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.059317Z","iopub.execute_input":"2022-06-14T19:07:12.060163Z","iopub.status.idle":"2022-06-14T19:07:12.070096Z","shell.execute_reply.started":"2022-06-14T19:07:12.060118Z","shell.execute_reply":"2022-06-14T19:07:12.069455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.values","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.071431Z","iopub.execute_input":"2022-06-14T19:07:12.071881Z","iopub.status.idle":"2022-06-14T19:07:12.083687Z","shell.execute_reply.started":"2022-06-14T19:07:12.071845Z","shell.execute_reply":"2022-06-14T19:07:12.082949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.index","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.085130Z","iopub.execute_input":"2022-06-14T19:07:12.085344Z","iopub.status.idle":"2022-06-14T19:07:12.096233Z","shell.execute_reply.started":"2022-06-14T19:07:12.085320Z","shell.execute_reply":"2022-06-14T19:07:12.095196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=pd.DataFrame({'customer_ID':sub.index, 'prediction':sub.values})","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.105380Z","iopub.execute_input":"2022-06-14T19:07:12.105879Z","iopub.status.idle":"2022-06-14T19:07:12.110756Z","shell.execute_reply.started":"2022-06-14T19:07:12.105841Z","shell.execute_reply":"2022-06-14T19:07:12.110074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub[\"prediction\"]=sub.prediction.round()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.111909Z","iopub.execute_input":"2022-06-14T19:07:12.112190Z","iopub.status.idle":"2022-06-14T19:07:12.125845Z","shell.execute_reply.started":"2022-06-14T19:07:12.112138Z","shell.execute_reply":"2022-06-14T19:07:12.124962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.127195Z","iopub.execute_input":"2022-06-14T19:07:12.127464Z","iopub.status.idle":"2022-06-14T19:07:12.138960Z","shell.execute_reply.started":"2022-06-14T19:07:12.127436Z","shell.execute_reply":"2022-06-14T19:07:12.138075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sub)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.139933Z","iopub.execute_input":"2022-06-14T19:07:12.140531Z","iopub.status.idle":"2022-06-14T19:07:12.150864Z","shell.execute_reply.started":"2022-06-14T19:07:12.140493Z","shell.execute_reply":"2022-06-14T19:07:12.150275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-14T19:07:12.151759Z","iopub.execute_input":"2022-06-14T19:07:12.152363Z","iopub.status.idle":"2022-06-14T19:07:12.189843Z","shell.execute_reply.started":"2022-06-14T19:07:12.152330Z","shell.execute_reply":"2022-06-14T19:07:12.189085Z"},"trusted":true},"execution_count":null,"outputs":[]}]}