{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","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":30786,"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,"execution":{"iopub.status.busy":"2024-11-26T04:25:19.431512Z","iopub.execute_input":"2024-11-26T04:25:19.431898Z","iopub.status.idle":"2024-11-26T04:25:19.439973Z","shell.execute_reply.started":"2024-11-26T04:25:19.431866Z","shell.execute_reply":"2024-11-26T04:25:19.438760Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = 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')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-26T04:25:20.029288Z","iopub.execute_input":"2024-11-26T04:25:20.029712Z","iopub.status.idle":"2024-11-26T04:25:23.013824Z","shell.execute_reply.started":"2024-11-26T04:25:20.029676Z","shell.execute_reply":"2024-11-26T04:25:23.012281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop('id', axis = 1, inplace=True)\ny = train.pop('Class')\nX = train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-26T04:25:23.015967Z","iopub.execute_input":"2024-11-26T04:25:23.016476Z","iopub.status.idle":"2024-11-26T04:25:23.042948Z","shell.execute_reply.started":"2024-11-26T04:25:23.016424Z","shell.execute_reply":"2024-11-26T04:25:23.041848Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0, stratify = y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-26T04:25:23.044144Z","iopub.execute_input":"2024-11-26T04:25:23.044535Z","iopub.status.idle":"2024-11-26T04:25:23.138453Z","shell.execute_reply.started":"2024-11-26T04:25:23.044501Z","shell.execute_reply":"2024-11-26T04:25:23.137149Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nmodel = RandomForestClassifier(\n    class_weight='balanced', \n    random_state = 0)\nmodel.fit(X_train, y_train)\n\n# y_pred = model.predict(X_test)\ny_pred_prob = model.predict_proba(X_test)\n\nfrom sklearn.metrics import roc_auc_score\nprint(roc_auc_score(y_test, y_pred_prob[:,1]))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-26T04:25:23.141067Z","iopub.execute_input":"2024-11-26T04:25:23.141542Z","iopub.status.idle":"2024-11-26T04:26:38.951989Z","shell.execute_reply.started":"2024-11-26T04:25:23.141491Z","shell.execute_reply":"2024-11-26T04:26:38.950608Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_id = test.pop('id')\nres = model.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":"2024-11-26T04:26:38.953217Z","iopub.execute_input":"2024-11-26T04:26:38.953563Z","iopub.status.idle":"2024-11-26T04:26:39.937770Z","shell.execute_reply.started":"2024-11-26T04:26:38.953532Z","shell.execute_reply":"2024-11-26T04:26:39.936382Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}