{"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-21T15:13:31.180179Z","iopub.execute_input":"2022-12-21T15:13:31.180533Z","iopub.status.idle":"2022-12-21T15:13:31.771522Z","shell.execute_reply.started":"2022-12-21T15:13:31.180502Z","shell.execute_reply":"2022-12-21T15:13:31.770528Z"},"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":"%%time\ndf_train_data = pd.read_parquet('/kaggle/input/preprocesing-train-data/features.parquet.gzip')","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:13:31.773254Z","iopub.execute_input":"2022-12-21T15:13:31.775226Z","iopub.status.idle":"2022-12-21T15:13:52.367965Z","shell.execute_reply.started":"2022-12-21T15:13:31.775195Z","shell.execute_reply":"2022-12-21T15:13:52.366920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-21T15:13:52.369366Z","iopub.execute_input":"2022-12-21T15:13:52.369940Z","iopub.status.idle":"2022-12-21T15:13:52.549866Z","shell.execute_reply.started":"2022-12-21T15:13:52.369900Z","shell.execute_reply":"2022-12-21T15:13:52.548946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df_train_data.iloc[:,:-1]\ny= df_train_data.iloc[:,-1]","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:13:52.552415Z","iopub.execute_input":"2022-12-21T15:13:52.552741Z","iopub.status.idle":"2022-12-21T15:13:53.230061Z","shell.execute_reply.started":"2022-12-21T15:13:52.552705Z","shell.execute_reply":"2022-12-21T15:13:53.228855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_train_data=df_train_data.dropna(axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:13:53.235537Z","iopub.execute_input":"2022-12-21T15:13:53.236583Z","iopub.status.idle":"2022-12-21T15:13:53.240769Z","shell.execute_reply.started":"2022-12-21T15:13:53.236202Z","shell.execute_reply":"2022-12-21T15:13:53.239642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 42)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:13:53.242394Z","iopub.execute_input":"2022-12-21T15:13:53.243053Z","iopub.status.idle":"2022-12-21T15:13:53.249815Z","shell.execute_reply.started":"2022-12-21T15:13:53.243016Z","shell.execute_reply":"2022-12-21T15:13:53.248832Z"},"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-21T15:13:53.251226Z","iopub.execute_input":"2022-12-21T15:13:53.251576Z","iopub.status.idle":"2022-12-21T15:13:53.263842Z","shell.execute_reply.started":"2022-12-21T15:13:53.251541Z","shell.execute_reply":"2022-12-21T15:13:53.262864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.fit(X_train, y_train)\nmodel.fit(X, y)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:13:53.265324Z","iopub.execute_input":"2022-12-21T15:13:53.265936Z","iopub.status.idle":"2022-12-21T15:14:13.025004Z","shell.execute_reply.started":"2022-12-21T15:13:53.265901Z","shell.execute_reply":"2022-12-21T15:14:13.024056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.026412Z","iopub.execute_input":"2022-12-21T15:14:13.026814Z","iopub.status.idle":"2022-12-21T15:14:13.031877Z","shell.execute_reply.started":"2022-12-21T15:14:13.026762Z","shell.execute_reply":"2022-12-21T15:14:13.030827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# acc = accuracy_score(y_test, pred)\n# acc","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.037107Z","iopub.execute_input":"2022-12-21T15:14:13.038110Z","iopub.status.idle":"2022-12-21T15:14:13.042290Z","shell.execute_reply.started":"2022-12-21T15:14:13.038063Z","shell.execute_reply":"2022-12-21T15:14:13.041173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save_model(\"./model.json\")","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.043630Z","iopub.execute_input":"2022-12-21T15:14:13.044633Z","iopub.status.idle":"2022-12-21T15:14:13.052339Z","shell.execute_reply.started":"2022-12-21T15:14:13.044598Z","shell.execute_reply":"2022-12-21T15:14:13.051473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model_load = 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-21T15:14:13.053365Z","iopub.execute_input":"2022-12-21T15:14:13.054165Z","iopub.status.idle":"2022-12-21T15:14:13.057396Z","shell.execute_reply.started":"2022-12-21T15:14:13.054134Z","shell.execute_reply":"2022-12-21T15:14:13.056663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model_load.load_model(\"/kaggle/working/model.json\")","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.058378Z","iopub.execute_input":"2022-12-21T15:14:13.059270Z","iopub.status.idle":"2022-12-21T15:14:13.067228Z","shell.execute_reply.started":"2022-12-21T15:14:13.059236Z","shell.execute_reply":"2022-12-21T15:14:13.066470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred =model_load.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.068399Z","iopub.execute_input":"2022-12-21T15:14:13.069227Z","iopub.status.idle":"2022-12-21T15:14:13.074450Z","shell.execute_reply.started":"2022-12-21T15:14:13.069198Z","shell.execute_reply":"2022-12-21T15:14:13.073582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# accuracy_score(y_test, pred)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.075757Z","iopub.execute_input":"2022-12-21T15:14:13.076681Z","iopub.status.idle":"2022-12-21T15:14:13.081537Z","shell.execute_reply.started":"2022-12-21T15:14:13.076651Z","shell.execute_reply":"2022-12-21T15:14:13.080581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from sklearn.metrics import classification_report","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.083076Z","iopub.execute_input":"2022-12-21T15:14:13.084170Z","iopub.status.idle":"2022-12-21T15:14:13.088882Z","shell.execute_reply.started":"2022-12-21T15:14:13.084134Z","shell.execute_reply":"2022-12-21T15:14:13.087891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(classification_report(y_test.to_numpy(), pred, labels=[0, 1]))","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:13.090178Z","iopub.execute_input":"2022-12-21T15:14:13.091636Z","iopub.status.idle":"2022-12-21T15:14:13.097404Z","shell.execute_reply.started":"2022-12-21T15:14:13.091608Z","shell.execute_reply":"2022-12-21T15:14:13.096159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test","metadata":{}},{"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-21T15:14:13.099217Z","iopub.execute_input":"2022-12-21T15:14:13.100046Z","iopub.status.idle":"2022-12-21T15:14:19.327181Z","shell.execute_reply.started":"2022-12-21T15:14:13.099951Z","shell.execute_reply":"2022-12-21T15:14:19.326148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_data","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:19.328555Z","iopub.execute_input":"2022-12-21T15:14:19.330323Z","iopub.status.idle":"2022-12-21T15:14:19.895797Z","shell.execute_reply.started":"2022-12-21T15:14:19.330281Z","shell.execute_reply":"2022-12-21T15:14:19.894702Z"},"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-21T15:14:19.897019Z","iopub.execute_input":"2022-12-21T15:14:19.897369Z","iopub.status.idle":"2022-12-21T15:14:19.908267Z","shell.execute_reply.started":"2022-12-21T15:14:19.897332Z","shell.execute_reply":"2022-12-21T15:14:19.907282Z"},"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-21T15:14:19.909865Z","iopub.execute_input":"2022-12-21T15:14:19.910682Z","iopub.status.idle":"2022-12-21T15:14:20.176650Z","shell.execute_reply.started":"2022-12-21T15:14:19.910646Z","shell.execute_reply":"2022-12-21T15:14:20.175676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(data)\npred","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:48.332489Z","iopub.execute_input":"2022-12-21T15:14:48.332886Z","iopub.status.idle":"2022-12-21T15:14:49.517635Z","shell.execute_reply.started":"2022-12-21T15:14:48.332852Z","shell.execute_reply":"2022-12-21T15:14:49.516563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.DataFrame({'customer_ID': customer_ID, 'prediction': pred})\nresult","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:49.519535Z","iopub.execute_input":"2022-12-21T15:14:49.520568Z","iopub.status.idle":"2022-12-21T15:14:49.544187Z","shell.execute_reply.started":"2022-12-21T15:14:49.520530Z","shell.execute_reply":"2022-12-21T15:14:49.543264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-12-21T15:14:49.545533Z","iopub.execute_input":"2022-12-21T15:14:49.546189Z","iopub.status.idle":"2022-12-21T15:14:52.790547Z","shell.execute_reply.started":"2022-12-21T15:14:49.546151Z","shell.execute_reply":"2022-12-21T15:14:52.789592Z"},"trusted":true},"execution_count":null,"outputs":[]}]}