{"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-09T08:42:57.760946Z","iopub.execute_input":"2022-12-09T08:42:57.761894Z","iopub.status.idle":"2022-12-09T08:42:58.923859Z","shell.execute_reply.started":"2022-12-09T08:42:57.761758Z","shell.execute_reply":"2022-12-09T08:42:58.922774Z"},"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-1-2-3-4/features.parquet.gzip')","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:42:58.926034Z","iopub.execute_input":"2022-12-09T08:42:58.926975Z","iopub.status.idle":"2022-12-09T08:43:35.670987Z","shell.execute_reply.started":"2022-12-09T08:42:58.926908Z","shell.execute_reply":"2022-12-09T08:43:35.669634Z"},"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-09T08:43:35.672043Z","iopub.execute_input":"2022-12-09T08:43:35.672356Z","iopub.status.idle":"2022-12-09T08:43:35.905520Z","shell.execute_reply.started":"2022-12-09T08:43:35.672327Z","shell.execute_reply":"2022-12-09T08:43:35.904619Z"},"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-09T08:43:35.907672Z","iopub.execute_input":"2022-12-09T08:43:35.908450Z","iopub.status.idle":"2022-12-09T08:43:37.489984Z","shell.execute_reply.started":"2022-12-09T08:43:35.908416Z","shell.execute_reply":"2022-12-09T08:43:37.489110Z"},"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-09T08:43:37.491039Z","iopub.execute_input":"2022-12-09T08:43:37.491798Z","iopub.status.idle":"2022-12-09T08:43:40.129766Z","shell.execute_reply.started":"2022-12-09T08:43:37.491764Z","shell.execute_reply":"2022-12-09T08:43:40.128459Z"},"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-09T08:43:40.131257Z","iopub.execute_input":"2022-12-09T08:43:40.131604Z","iopub.status.idle":"2022-12-09T08:43:53.127247Z","shell.execute_reply.started":"2022-12-09T08:43:40.131572Z","shell.execute_reply":"2022-12-09T08:43:53.125990Z"},"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)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:43:53.128876Z","iopub.execute_input":"2022-12-09T08:43:53.129358Z","iopub.status.idle":"2022-12-09T08:43:53.135287Z","shell.execute_reply.started":"2022-12-09T08:43:53.129315Z","shell.execute_reply":"2022-12-09T08:43:53.134143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:43:53.136842Z","iopub.execute_input":"2022-12-09T08:43:53.137470Z","iopub.status.idle":"2022-12-09T08:54:19.561787Z","shell.execute_reply.started":"2022-12-09T08:43:53.137428Z","shell.execute_reply":"2022-12-09T08:54:19.559686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:54:19.564359Z","iopub.execute_input":"2022-12-09T08:54:19.564750Z","iopub.status.idle":"2022-12-09T08:54:22.104831Z","shell.execute_reply.started":"2022-12-09T08:54:19.564708Z","shell.execute_reply":"2022-12-09T08:54:22.103895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = accuracy_score(y_test, pred)\nacc","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:54:22.108399Z","iopub.execute_input":"2022-12-09T08:54:22.108748Z","iopub.status.idle":"2022-12-09T08:54:22.317418Z","shell.execute_reply.started":"2022-12-09T08:54:22.108717Z","shell.execute_reply":"2022-12-09T08:54:22.316182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save_model(\"./model.json\")","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:54:22.318827Z","iopub.execute_input":"2022-12-09T08:54:22.319281Z","iopub.status.idle":"2022-12-09T08:54:22.328984Z","shell.execute_reply.started":"2022-12-09T08:54:22.319246Z","shell.execute_reply":"2022-12-09T08:54:22.327959Z"},"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-09T08:55:45.776854Z","iopub.execute_input":"2022-12-09T08:55:45.777372Z","iopub.status.idle":"2022-12-09T08:55:45.785725Z","shell.execute_reply.started":"2022-12-09T08:55:45.777332Z","shell.execute_reply":"2022-12-09T08:55:45.783575Z"},"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-09T08:55:52.104268Z","iopub.execute_input":"2022-12-09T08:55:52.104750Z","iopub.status.idle":"2022-12-09T08:55:52.119358Z","shell.execute_reply.started":"2022-12-09T08:55:52.104712Z","shell.execute_reply":"2022-12-09T08:55:52.118015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred =model_load.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:58:08.131815Z","iopub.execute_input":"2022-12-09T08:58:08.132406Z","iopub.status.idle":"2022-12-09T08:58:11.276035Z","shell.execute_reply.started":"2022-12-09T08:58:08.132360Z","shell.execute_reply":"2022-12-09T08:58:11.274713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test, pred)","metadata":{"execution":{"iopub.status.busy":"2022-12-09T08:58:12.794782Z","iopub.execute_input":"2022-12-09T08:58:12.795255Z","iopub.status.idle":"2022-12-09T08:58:13.005738Z","shell.execute_reply.started":"2022-12-09T08:58:12.795219Z","shell.execute_reply":"2022-12-09T08:58:13.004393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}