{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","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":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import roc_auc_score\nfrom sklearn.model_selection import train_test_split","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-28T10:30:28.777249Z","iopub.execute_input":"2024-05-28T10:30:28.777646Z","iopub.status.idle":"2024-05-28T10:30:28.783882Z","shell.execute_reply.started":"2024-05-28T10:30:28.777615Z","shell.execute_reply":"2024-05-28T10:30:28.782565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-28T10:30:28.919655Z","iopub.execute_input":"2024-05-28T10:30:28.920030Z","iopub.status.idle":"2024-05-28T10:30:31.687357Z","shell.execute_reply.started":"2024-05-28T10:30:28.920001Z","shell.execute_reply":"2024-05-28T10:30:31.685877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.drop(['id', 'Class'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:30:31.689650Z","iopub.execute_input":"2024-05-28T10:30:31.689995Z","iopub.status.idle":"2024-05-28T10:30:31.716970Z","shell.execute_reply.started":"2024-05-28T10:30:31.689964Z","shell.execute_reply":"2024-05-28T10:30:31.715744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train['Class']","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:30:31.718533Z","iopub.execute_input":"2024-05-28T10:30:31.718888Z","iopub.status.idle":"2024-05-28T10:30:31.724154Z","shell.execute_reply.started":"2024-05-28T10:30:31.718857Z","shell.execute_reply":"2024-05-28T10:30:31.722994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습/검증 데이터 분리\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.3, random_state=42, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:30:31.726887Z","iopub.execute_input":"2024-05-28T10:30:31.727257Z","iopub.status.idle":"2024-05-28T10:30:31.782581Z","shell.execute_reply.started":"2024-05-28T10:30:31.727228Z","shell.execute_reply":"2024-05-28T10:30:31.781437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 로지스틱 회귀 모델 학습\nmodel = RandomForestClassifier()\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:30:31.783971Z","iopub.execute_input":"2024-05-28T10:30:31.784345Z","iopub.status.idle":"2024-05-28T10:32:18.941597Z","shell.execute_reply.started":"2024-05-28T10:30:31.784313Z","shell.execute_reply":"2024-05-28T10:32:18.940242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 검증 데이터에 대한 예측\npreds = model.predict_proba(X_val)\npreds","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:32:18.943108Z","iopub.execute_input":"2024-05-28T10:32:18.943458Z","iopub.status.idle":"2024-05-28T10:32:19.425648Z","shell.execute_reply.started":"2024-05-28T10:32:18.943428Z","shell.execute_reply":"2024-05-28T10:32:19.424294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_probs = preds[:, 1]\npreds_probs","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:32:19.427228Z","iopub.execute_input":"2024-05-28T10:32:19.427620Z","iopub.status.idle":"2024-05-28T10:32:19.434256Z","shell.execute_reply.started":"2024-05-28T10:32:19.427590Z","shell.execute_reply":"2024-05-28T10:32:19.433107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"roc_auc = roc_auc_score(y_val, preds_probs)\nroc_auc","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:32:19.436786Z","iopub.execute_input":"2024-05-28T10:32:19.437156Z","iopub.status.idle":"2024-05-28T10:32:19.463456Z","shell.execute_reply.started":"2024-05-28T10:32:19.437126Z","shell.execute_reply":"2024-05-28T10:32:19.462284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test 데이터 예측\nX = test.drop(['id'], axis=1)\npreds = model.predict_proba(X)\npreds_probs = preds[:, 1]","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:33:40.172113Z","iopub.execute_input":"2024-05-28T10:33:40.173357Z","iopub.status.idle":"2024-05-28T10:33:41.260689Z","shell.execute_reply.started":"2024-05-28T10:33:40.173309Z","shell.execute_reply":"2024-05-28T10:33:41.259480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 제출 파일 생성\nsubmission = pd.DataFrame({'id': test['id'], 'Class': preds_probs})\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T10:33:50.225272Z","iopub.execute_input":"2024-05-28T10:33:50.225734Z","iopub.status.idle":"2024-05-28T10:33:50.448773Z","shell.execute_reply.started":"2024-05-28T10:33:50.225700Z","shell.execute_reply":"2024-05-28T10:33:50.447734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}