{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":80687,"databundleVersionId":8672016,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"## 평가 지표 : roc-auc\n## y : Class\n\nimport pandas as pd\ntrain = pd.read_csv(\"/kaggle/input/big-data-analytics-certification-kr-2024-2/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/big-data-analytics-certification-kr-2024-2/test.csv\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:02:52.850692Z","iopub.execute_input":"2025-05-21T08:02:52.851030Z","iopub.status.idle":"2025-05-21T08:02:55.664486Z","shell.execute_reply.started":"2025-05-21T08:02:52.850998Z","shell.execute_reply":"2025-05-21T08:02:55.663270Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.shape, test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T07:52:36.042508Z","iopub.execute_input":"2025-05-21T07:52:36.042938Z","iopub.status.idle":"2025-05-21T07:52:36.050154Z","shell.execute_reply.started":"2025-05-21T07:52:36.042905Z","shell.execute_reply":"2025-05-21T07:52:36.049046Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.info())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T07:50:21.592144Z","iopub.execute_input":"2025-05-21T07:50:21.592451Z","iopub.status.idle":"2025-05-21T07:50:21.654001Z","shell.execute_reply.started":"2025-05-21T07:50:21.592428Z","shell.execute_reply":"2025-05-21T07:50:21.653179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.isnull().sum())\nprint(\"\\n\")\nprint(test.isnull().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:03:00.961484Z","iopub.execute_input":"2025-05-21T08:03:00.961870Z","iopub.status.idle":"2025-05-21T08:03:01.007724Z","shell.execute_reply.started":"2025-05-21T08:03:00.961847Z","shell.execute_reply":"2025-05-21T08:03:01.006187Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop('id', axis=1, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:03:03.553229Z","iopub.execute_input":"2025-05-21T08:03:03.553594Z","iopub.status.idle":"2025-05-21T08:03:03.567789Z","shell.execute_reply.started":"2025-05-21T08:03:03.553570Z","shell.execute_reply":"2025-05-21T08:03:03.566822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = train.pop(\"Class\")\nprint(train.shape, test.shape)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:03:04.762362Z","iopub.execute_input":"2025-05-21T08:03:04.762720Z","iopub.status.idle":"2025-05-21T08:03:04.769216Z","shell.execute_reply.started":"2025-05-21T08:03:04.762698Z","shell.execute_reply":"2025-05-21T08:03:04.767889Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_val, y_train, y_val = train_test_split(\n    train, target, test_size=0.2, random_state=0\n)\nX_train.shape, X_val.shape, y_train.shape, y_val.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:03:06.138025Z","iopub.execute_input":"2025-05-21T08:03:06.138357Z","iopub.status.idle":"2025-05-21T08:03:06.198601Z","shell.execute_reply.started":"2025-05-21T08:03:06.138334Z","shell.execute_reply":"2025-05-21T08:03:06.197408Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrf = RandomForestClassifier()\nrf.fit(X_train, y_train)\npred = rf.predict_proba(X_val)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:03:07.384424Z","iopub.execute_input":"2025-05-21T08:03:07.384770Z","iopub.status.idle":"2025-05-21T08:05:12.216876Z","shell.execute_reply.started":"2025-05-21T08:03:07.384746Z","shell.execute_reply":"2025-05-21T08:05:12.216087Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\nresult = roc_auc_score(y_val, pred[:,1])\nprint(result)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:05:25.476214Z","iopub.execute_input":"2025-05-21T08:05:25.476505Z","iopub.status.idle":"2025-05-21T08:05:25.489257Z","shell.execute_reply.started":"2025-05-21T08:05:25.476485Z","shell.execute_reply":"2025-05-21T08:05:25.488429Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_id = test.pop('id')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:07:30.809526Z","iopub.execute_input":"2025-05-21T08:07:30.810474Z","iopub.status.idle":"2025-05-21T08:07:30.816579Z","shell.execute_reply.started":"2025-05-21T08:07:30.810437Z","shell.execute_reply":"2025-05-21T08:07:30.815606Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"res = rf.predict_proba(test)[:,1]\ndf = pd.DataFrame({'id' : test_id, 'Class' : res})\ndf.to_csv('result.csv', index = False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:08:28.845387Z","iopub.execute_input":"2025-05-21T08:08:28.845723Z","iopub.status.idle":"2025-05-21T08:08:30.034601Z","shell.execute_reply.started":"2025-05-21T08:08:28.845700Z","shell.execute_reply":"2025-05-21T08:08:30.033392Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.read_csv(\"/kaggle/working/result.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-21T08:09:03.204344Z","iopub.execute_input":"2025-05-21T08:09:03.204704Z","iopub.status.idle":"2025-05-21T08:09:03.247206Z","shell.execute_reply.started":"2025-05-21T08:09:03.204676Z","shell.execute_reply":"2025-05-21T08:09:03.246242Z"}},"outputs":[],"execution_count":null}]}