{"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":"markdown","source":"# Libraries","metadata":{}},{"cell_type":"code","source":"#===========================\n# Team 4 - Preprocessing   =\n# KIEU HAI DANG - 19127347 =\n# TRAN DONG BA - 19127334  =\n# LE VAN DONG - 19127363   =\n# LA MINH HIEU - 19127400  =\n#===========================\n\n\n#======================================================================\n# Popular libraries used for data preprocessing & visualization\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns # data visualization\nimport gc\n#======================================================================\n\n\n#======================================================================\n# Libraries used for data modeling, training & prediction\n# from sklearn import\n#======================================================================\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-22T13:18:34.561486Z","iopub.execute_input":"2022-12-22T13:18:34.562014Z","iopub.status.idle":"2022-12-22T13:18:35.835756Z","shell.execute_reply.started":"2022-12-22T13:18:34.561971Z","shell.execute_reply":"2022-12-22T13:18:35.834455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Look through the sample output","metadata":{}},{"cell_type":"markdown","source":"# Read trainning data","metadata":{}},{"cell_type":"markdown","source":"At this step, because of the large of the file's size, we can't read them normally.\n\nFortunately, we found & thanks for the solution called parquet file format.\n\nBig thanks to - https://www.kaggle.com/code/odins0n/load-parquet-files-with-low-memory/","metadata":{}},{"cell_type":"code","source":"from xgboost import XGBClassifier\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:18:35.838747Z","iopub.execute_input":"2022-12-22T13:18:35.839127Z","iopub.status.idle":"2022-12-22T13:18:36.183851Z","shell.execute_reply.started":"2022-12-22T13:18:35.839094Z","shell.execute_reply":"2022-12-22T13:18:36.182960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBClassifier(\n         learning_rate =0.01,\n         n_estimators=10,\n         max_depth=3,\n#          tree_method=\"gpu_hist\"\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:18:36.185386Z","iopub.execute_input":"2022-12-22T13:18:36.185804Z","iopub.status.idle":"2022-12-22T13:18:36.191232Z","shell.execute_reply.started":"2022-12-22T13:18:36.185768Z","shell.execute_reply":"2022-12-22T13:18:36.190057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.load_model(\"/kaggle/input/training-1-2-3-4/model.json\")","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:18:36.194440Z","iopub.execute_input":"2022-12-22T13:18:36.195322Z","iopub.status.idle":"2022-12-22T13:18:36.243031Z","shell.execute_reply.started":"2022-12-22T13:18:36.195272Z","shell.execute_reply":"2022-12-22T13:18:36.241893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_data = pd.read_parquet('/kaggle/input/preprocesing-test-data/test_features.parquet.gzip')","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:18:36.244857Z","iopub.execute_input":"2022-12-22T13:18:36.245534Z","iopub.status.idle":"2022-12-22T13:19:23.864423Z","shell.execute_reply.started":"2022-12-22T13:18:36.245494Z","shell.execute_reply":"2022-12-22T13:19:23.863140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_data","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:23.866201Z","iopub.execute_input":"2022-12-22T13:19:23.866560Z","iopub.status.idle":"2022-12-22T13:19:28.438874Z","shell.execute_reply.started":"2022-12-22T13:19:23.866528Z","shell.execute_reply":"2022-12-22T13:19:28.437600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_ID = df_test_data['customer_ID']\ncustomer_ID","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:28.440480Z","iopub.execute_input":"2022-12-22T13:19:28.440889Z","iopub.status.idle":"2022-12-22T13:19:28.453613Z","shell.execute_reply.started":"2022-12-22T13:19:28.440852Z","shell.execute_reply":"2022-12-22T13:19:28.452261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = df_test_data.drop(['customer_ID'], axis=1)\ndata","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:28.455953Z","iopub.execute_input":"2022-12-22T13:19:28.456449Z","iopub.status.idle":"2022-12-22T13:19:35.273482Z","shell.execute_reply.started":"2022-12-22T13:19:28.456401Z","shell.execute_reply":"2022-12-22T13:19:35.272014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(data)\npred","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:35.275011Z","iopub.execute_input":"2022-12-22T13:19:35.275429Z","iopub.status.idle":"2022-12-22T13:19:52.847357Z","shell.execute_reply.started":"2022-12-22T13:19:35.275394Z","shell.execute_reply":"2022-12-22T13:19:52.845374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.DataFrame({'customer_ID': customer_ID, 'prediction': pred})\n# result = result.groupby(['customer_ID'])['prediction'].apply(pd.Series.mode)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:52.853387Z","iopub.execute_input":"2022-12-22T13:19:52.854306Z","iopub.status.idle":"2022-12-22T13:19:52.979262Z","shell.execute_reply.started":"2022-12-22T13:19:52.854260Z","shell.execute_reply":"2022-12-22T13:19:52.978076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = pd.DataFrame(result.groupby('customer_ID'))","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:19:52.980891Z","iopub.execute_input":"2022-12-22T13:19:52.981267Z","iopub.status.idle":"2022-12-22T13:20:41.955433Z","shell.execute_reply.started":"2022-12-22T13:19:52.981232Z","shell.execute_reply":"2022-12-22T13:20:41.953230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp.columns = ['customer_ID', 'predict']\ntemp","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:20:41.957280Z","iopub.execute_input":"2022-12-22T13:20:41.959712Z","iopub.status.idle":"2022-12-22T13:20:42.021300Z","shell.execute_reply.started":"2022-12-22T13:20:41.959632Z","shell.execute_reply":"2022-12-22T13:20:42.019929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mode = []\nfor i in temp['predict']:\n    mode.append(i.prediction.mode()[0])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:20:42.022904Z","iopub.execute_input":"2022-12-22T13:20:42.024052Z","iopub.status.idle":"2022-12-22T13:25:03.495517Z","shell.execute_reply.started":"2022-12-22T13:20:42.023999Z","shell.execute_reply":"2022-12-22T13:25:03.494148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mode = pd.DataFrame(mode)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:30:50.072474Z","iopub.execute_input":"2022-12-22T13:30:50.073280Z","iopub.status.idle":"2022-12-22T13:30:50.395392Z","shell.execute_reply.started":"2022-12-22T13:30:50.073237Z","shell.execute_reply":"2022-12-22T13:30:50.394031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.concat([temp.customer_ID, mode], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:31:48.156738Z","iopub.execute_input":"2022-12-22T13:31:48.157247Z","iopub.status.idle":"2022-12-22T13:31:48.214569Z","shell.execute_reply.started":"2022-12-22T13:31:48.157207Z","shell.execute_reply":"2022-12-22T13:31:48.213194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.columns = ['customer_ID', 'prediction']","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:33:16.167398Z","iopub.execute_input":"2022-12-22T13:33:16.169088Z","iopub.status.idle":"2022-12-22T13:33:16.176219Z","shell.execute_reply.started":"2022-12-22T13:33:16.169006Z","shell.execute_reply":"2022-12-22T13:33:16.174560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:33:19.536991Z","iopub.execute_input":"2022-12-22T13:33:19.537448Z","iopub.status.idle":"2022-12-22T13:33:21.609907Z","shell.execute_reply.started":"2022-12-22T13:33:19.537414Z","shell.execute_reply":"2022-12-22T13:33:21.608950Z"},"trusted":true},"execution_count":null,"outputs":[]}]}