{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Import libraries\nimport os\nimport warnings\n\nimport numpy as np\nimport pandas as pd\n\nimport gc  # Garbage collector\n\n\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn import metrics\n\nfrom xgboost import XGBClassifier","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the model\nimport joblib\nxgb_classifier = joblib.load(\"../input/01-starter-xgboost-implementation/xgb_classifier_v1.h5\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oe = joblib.load(\"../input/01-starter-xgboost-implementation/oe.h5\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_feather('../input/amexfeather/test_data.ftr')#.iloc[6000000:]","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:19:11.838551Z","iopub.execute_input":"2022-06-22T07:19:11.838976Z","iopub.status.idle":"2022-06-22T07:19:19.451625Z","shell.execute_reply.started":"2022-06-22T07:19:11.838944Z","shell.execute_reply":"2022-06-22T07:19:19.450876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Handling date column\n\ntest[\"S_2_day\"] = test[\"S_2\"].dt.day\ntest[\"S_2_month\"] = test[\"S_2\"].dt.month\ntest[\"S_2_year\"] = test[\"S_2\"].dt.year","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:19:19.453108Z","iopub.execute_input":"2022-06-22T07:19:19.453573Z","iopub.status.idle":"2022-06-22T07:19:21.745081Z","shell.execute_reply.started":"2022-06-22T07:19:19.453541Z","shell.execute_reply":"2022-06-22T07:19:21.744106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop_cols = ['D_87', 'D_88', 'D_108', 'D_111', 'D_110', 'B_39', 'D_73', 'B_42', 'D_136',\n 'D_138', 'D_137', 'D_135', 'D_134', 'R_9', 'B_29', 'D_106', 'D_132', 'D_49',\n 'R_26', 'D_76', 'D_66', 'D_42', 'D_142', 'D_53', 'D_82','S_2']\n\ntest.drop(columns = drop_cols,axis=1, inplace=True)\n\n# converting pandas \"categorical\" dtype to numeric\ncols = [\"D_68\", \"B_30\", \"B_38\", \"D_114\", \"D_116\", \"D_117\", \"D_120\", \"D_126\"]\ntest[cols] = test[cols].apply(pd.to_numeric, errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:19:21.746173Z","iopub.execute_input":"2022-06-22T07:19:21.746435Z","iopub.status.idle":"2022-06-22T07:19:52.206214Z","shell.execute_reply.started":"2022-06-22T07:19:21.746411Z","shell.execute_reply":"2022-06-22T07:19:52.205187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical_columns = [\"D_63\",\"D_64\"]\ntest_enc = oe.transform(test[categorical_columns])\ntest[categorical_columns] = test_enc","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_ = gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:19:52.208241Z","iopub.execute_input":"2022-06-22T07:19:52.208674Z","iopub.status.idle":"2022-06-22T07:19:52.323274Z","shell.execute_reply.started":"2022-06-22T07:19:52.208636Z","shell.execute_reply":"2022-06-22T07:19:52.322409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# considering only one data point per customer (latest one) as time series is not being used\ntest = test.groupby(['customer_ID']).nth(-1).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:20:11.219506Z","iopub.execute_input":"2022-06-22T07:20:11.219911Z","iopub.status.idle":"2022-06-22T07:20:11.315018Z","shell.execute_reply.started":"2022-06-22T07:20:11.219882Z","shell.execute_reply":"2022-06-22T07:20:11.313587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test.isna().sum()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # For numeric columns\n# numeric_columns = test.select_dtypes(np.number).columns\n# test[numeric_columns] = test[numeric_columns].fillna(test[numeric_columns].mean())","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Score up the test dataset\ntest_preds = xgb_classifier.predict(test)\n# test_preds.view()\n","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:21:09.61259Z","iopub.execute_input":"2022-06-22T07:21:09.614003Z","iopub.status.idle":"2022-06-22T07:21:12.612803Z","shell.execute_reply.started":"2022-06-22T07:21:09.613947Z","shell.execute_reply":"2022-06-22T07:21:12.612042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Submission","metadata":{}},{"cell_type":"code","source":"# Make submission\nsub_data = pd.read_csv('../input/amex-default-prediction/sample_submission.csv')\nsub_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:21:14.433515Z","iopub.execute_input":"2022-06-22T07:21:14.433917Z","iopub.status.idle":"2022-06-22T07:21:15.52154Z","shell.execute_reply.started":"2022-06-22T07:21:14.433889Z","shell.execute_reply":"2022-06-22T07:21:15.520401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:21:15.523636Z","iopub.execute_input":"2022-06-22T07:21:15.524077Z","iopub.status.idle":"2022-06-22T07:21:15.530935Z","shell.execute_reply.started":"2022-06-22T07:21:15.524041Z","shell.execute_reply":"2022-06-22T07:21:15.529977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_data['prediction'] = test_preds\nsub_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:21:19.825398Z","iopub.execute_input":"2022-06-22T07:21:19.825792Z","iopub.status.idle":"2022-06-22T07:21:19.837688Z","shell.execute_reply.started":"2022-06-22T07:21:19.825763Z","shell.execute_reply":"2022-06-22T07:21:19.836751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission file\nsub_data.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-22T07:21:23.814694Z","iopub.execute_input":"2022-06-22T07:21:23.815351Z","iopub.status.idle":"2022-06-22T07:21:27.028162Z","shell.execute_reply.started":"2022-06-22T07:21:23.815316Z","shell.execute_reply":"2022-06-22T07:21:27.026977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}