{"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-09-07T12:16:39.408211Z","iopub.execute_input":"2022-09-07T12:16:39.408981Z","iopub.status.idle":"2022-09-07T12:16:39.420592Z","shell.execute_reply.started":"2022-09-07T12:16:39.408943Z","shell.execute_reply":"2022-09-07T12:16:39.419423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 오른쪽 ACCELERATOR에서 GPU를 사용해주세요","metadata":{}},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error, r2_score\nfrom sklearn.model_selection import RandomizedSearchCV\nfrom xgboost import XGBRegressor","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:20:05.239009Z","iopub.execute_input":"2022-09-07T12:20:05.239410Z","iopub.status.idle":"2022-09-07T12:20:05.245746Z","shell.execute_reply.started":"2022-09-07T12:20:05.239359Z","shell.execute_reply":"2022-09-07T12:20:05.244697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/financemachinelearning/train.csv')\n","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:16:40.353220Z","iopub.execute_input":"2022-09-07T12:16:40.354348Z","iopub.status.idle":"2022-09-07T12:16:51.782600Z","shell.execute_reply.started":"2022-09-07T12:16:40.354300Z","shell.execute_reply":"2022-09-07T12:16:51.781545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.drop('r05_fwd', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:17:16.923842Z","iopub.execute_input":"2022-09-07T12:17:16.924932Z","iopub.status.idle":"2022-09-07T12:17:17.065100Z","shell.execute_reply.started":"2022-09-07T12:17:16.924886Z","shell.execute_reply":"2022-09-07T12:17:17.063911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train[['r05_fwd']]","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:17:24.244190Z","iopub.execute_input":"2022-09-07T12:17:24.244578Z","iopub.status.idle":"2022-09-07T12:17:24.255831Z","shell.execute_reply.started":"2022-09-07T12:17:24.244544Z","shell.execute_reply":"2022-09-07T12:17:24.254584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Parameter Setting","metadata":{}},{"cell_type":"code","source":"params = {\n \"learning_rate\" : [0.05,0.10,0.15,0.20,0.25,0.30],\n \"max_depth\" : [ 3, 4, 5, 6, 8, 10, 12, 15],\n \"min_child_weight\" : [ 1, 3, 5, 7 ],\n \"gamma\": [ 0.0, 0.1, 0.2 , 0.3, 0.4 ],\n \"colsample_bytree\" : [ 0.3, 0.4, 0.5 , 0.7 ]\n}","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:20:49.854065Z","iopub.execute_input":"2022-09-07T12:20:49.855134Z","iopub.status.idle":"2022-09-07T12:20:49.862268Z","shell.execute_reply.started":"2022-09-07T12:20:49.855088Z","shell.execute_reply":"2022-09-07T12:20:49.861300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using GPU\nmodel = XGBRegressor(tree_method='gpu_hist', gpu_id=0)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:21:39.993526Z","iopub.execute_input":"2022-09-07T12:21:39.994726Z","iopub.status.idle":"2022-09-07T12:21:40.000165Z","shell.execute_reply.started":"2022-09-07T12:21:39.994686Z","shell.execute_reply":"2022-09-07T12:21:39.999171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs_model=RandomizedSearchCV(model,param_distributions=params,n_iter=5,cv=5,verbose=3)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:22:12.241914Z","iopub.execute_input":"2022-09-07T12:22:12.242548Z","iopub.status.idle":"2022-09-07T12:22:12.247942Z","shell.execute_reply.started":"2022-09-07T12:22:12.242509Z","shell.execute_reply":"2022-09-07T12:22:12.246665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs_model.fit(X, y)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:24:09.310407Z","iopub.execute_input":"2022-09-07T12:24:09.311590Z","iopub.status.idle":"2022-09-07T12:25:54.951616Z","shell.execute_reply.started":"2022-09-07T12:24:09.311542Z","shell.execute_reply":"2022-09-07T12:25:54.950673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Best Score","metadata":{}},{"cell_type":"code","source":"rs_model.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:26:36.200107Z","iopub.execute_input":"2022-09-07T12:26:36.200501Z","iopub.status.idle":"2022-09-07T12:26:36.208351Z","shell.execute_reply.started":"2022-09-07T12:26:36.200465Z","shell.execute_reply":"2022-09-07T12:26:36.207236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Test","metadata":{}},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/financemachinelearning/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:27:36.791121Z","iopub.execute_input":"2022-09-07T12:27:36.792292Z","iopub.status.idle":"2022-09-07T12:27:38.407691Z","shell.execute_reply.started":"2022-09-07T12:27:36.792249Z","shell.execute_reply":"2022-09-07T12:27:38.406678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_ = test['id']\nX_test = test[X.columns]","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:27:45.210994Z","iopub.execute_input":"2022-09-07T12:27:45.211629Z","iopub.status.idle":"2022-09-07T12:27:45.229852Z","shell.execute_reply.started":"2022-09-07T12:27:45.211591Z","shell.execute_reply":"2022-09-07T12:27:45.228686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict = rs_model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:28:05.218224Z","iopub.execute_input":"2022-09-07T12:28:05.218735Z","iopub.status.idle":"2022-09-07T12:28:05.664208Z","shell.execute_reply.started":"2022-09-07T12:28:05.218695Z","shell.execute_reply":"2022-09-07T12:28:05.660933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame(zip(id_, predict), columns=['id', 'r05_fwd'])","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:28:11.987349Z","iopub.execute_input":"2022-09-07T12:28:11.988076Z","iopub.status.idle":"2022-09-07T12:28:12.213865Z","shell.execute_reply.started":"2022-09-07T12:28:11.988039Z","shell.execute_reply":"2022-09-07T12:28:12.211831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:28:14.924930Z","iopub.execute_input":"2022-09-07T12:28:14.925635Z","iopub.status.idle":"2022-09-07T12:28:14.943897Z","shell.execute_reply.started":"2022-09-07T12:28:14.925598Z","shell.execute_reply":"2022-09-07T12:28:14.942472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-09-07T12:28:22.514799Z","iopub.execute_input":"2022-09-07T12:28:22.515516Z","iopub.status.idle":"2022-09-07T12:28:22.872195Z","shell.execute_reply.started":"2022-09-07T12:28:22.515478Z","shell.execute_reply":"2022-09-07T12:28:22.871170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}