{"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":true,"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-28T10:33:20.990547Z","iopub.execute_input":"2024-11-28T10:33:20.990971Z","iopub.status.idle":"2024-11-28T10:33:21.415054Z","shell.execute_reply.started":"2024-11-28T10:33:20.990929Z","shell.execute_reply":"2024-11-28T10:33:21.413695Z"}},"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-28T10:33:21.416708Z","iopub.execute_input":"2024-11-28T10:33:21.417154Z","iopub.status.idle":"2024-11-28T10:33:25.483154Z","shell.execute_reply.started":"2024-11-28T10:33:21.417118Z","shell.execute_reply":"2024-11-28T10:33:25.482034Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.484768Z","iopub.execute_input":"2024-11-28T10:33:25.485192Z","iopub.status.idle":"2024-11-28T10:33:25.523333Z","shell.execute_reply.started":"2024-11-28T10:33:25.485154Z","shell.execute_reply":"2024-11-28T10:33:25.522183Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.526140Z","iopub.execute_input":"2024-11-28T10:33:25.526596Z","iopub.status.idle":"2024-11-28T10:33:25.553082Z","shell.execute_reply.started":"2024-11-28T10:33:25.526545Z","shell.execute_reply":"2024-11-28T10:33:25.551864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.shape, test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.554452Z","iopub.execute_input":"2024-11-28T10:33:25.554785Z","iopub.status.idle":"2024-11-28T10:33:25.560872Z","shell.execute_reply.started":"2024-11-28T10:33:25.554750Z","shell.execute_reply":"2024-11-28T10:33:25.559875Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.562349Z","iopub.execute_input":"2024-11-28T10:33:25.562800Z","iopub.status.idle":"2024-11-28T10:33:25.612106Z","shell.execute_reply.started":"2024-11-28T10:33:25.562753Z","shell.execute_reply":"2024-11-28T10:33:25.610768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.613284Z","iopub.execute_input":"2024-11-28T10:33:25.613676Z","iopub.status.idle":"2024-11-28T10:33:25.933107Z","shell.execute_reply.started":"2024-11-28T10:33:25.613630Z","shell.execute_reply":"2024-11-28T10:33:25.931920Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.934530Z","iopub.execute_input":"2024-11-28T10:33:25.935185Z","iopub.status.idle":"2024-11-28T10:33:25.951766Z","shell.execute_reply.started":"2024-11-28T10:33:25.935145Z","shell.execute_reply":"2024-11-28T10:33:25.950475Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\ncols = ['Time','Amount']\nfor col in cols:\n    scaler = StandardScaler()\n    scaler.fit(train[[col]])\n    train[col] = scaler.transform(train[[col]])\n    test[col] = scaler.transform(test[[col]])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:25.953460Z","iopub.execute_input":"2024-11-28T10:33:25.953905Z","iopub.status.idle":"2024-11-28T10:33:26.476963Z","shell.execute_reply.started":"2024-11-28T10:33:25.953853Z","shell.execute_reply":"2024-11-28T10:33:26.476062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.480353Z","iopub.execute_input":"2024-11-28T10:33:26.480880Z","iopub.status.idle":"2024-11-28T10:33:26.504241Z","shell.execute_reply.started":"2024-11-28T10:33:26.480840Z","shell.execute_reply":"2024-11-28T10:33:26.503096Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train = train.pop('Class')\ny_train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.505362Z","iopub.execute_input":"2024-11-28T10:33:26.505718Z","iopub.status.idle":"2024-11-28T10:33:26.522062Z","shell.execute_reply.started":"2024-11-28T10:33:26.505685Z","shell.execute_reply":"2024-11-28T10:33:26.520931Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.value_counts(normalize=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.523254Z","iopub.execute_input":"2024-11-28T10:33:26.523677Z","iopub.status.idle":"2024-11-28T10:33:26.540736Z","shell.execute_reply.started":"2024-11-28T10:33:26.523630Z","shell.execute_reply":"2024-11-28T10:33:26.539399Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.542128Z","iopub.execute_input":"2024-11-28T10:33:26.542452Z","iopub.status.idle":"2024-11-28T10:33:26.557152Z","shell.execute_reply.started":"2024-11-28T10:33:26.542416Z","shell.execute_reply":"2024-11-28T10:33:26.555898Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop('id', axis=1)\ntest.drop('id', axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.558612Z","iopub.execute_input":"2024-11-28T10:33:26.558974Z","iopub.status.idle":"2024-11-28T10:33:26.684073Z","shell.execute_reply.started":"2024-11-28T10:33:26.558938Z","shell.execute_reply":"2024-11-28T10:33:26.683073Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_tr,x_va,y_tr,y_va = train_test_split(train,y_train,test_size=0.2,stratify=y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.685229Z","iopub.execute_input":"2024-11-28T10:33:26.685532Z","iopub.status.idle":"2024-11-28T10:33:26.997083Z","shell.execute_reply.started":"2024-11-28T10:33:26.685500Z","shell.execute_reply":"2024-11-28T10:33:26.995475Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(x_tr.shape, x_va.shape, y_tr.shape, y_va.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:26.998791Z","iopub.execute_input":"2024-11-28T10:33:26.999221Z","iopub.status.idle":"2024-11-28T10:33:27.006071Z","shell.execute_reply.started":"2024-11-28T10:33:26.999185Z","shell.execute_reply":"2024-11-28T10:33:27.004903Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_tr.value_counts(normalize=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:33:27.007528Z","iopub.execute_input":"2024-11-28T10:33:27.008021Z","iopub.status.idle":"2024-11-28T10:33:27.023942Z","shell.execute_reply.started":"2024-11-28T10:33:27.007960Z","shell.execute_reply":"2024-11-28T10:33:27.022646Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrf = RandomForestClassifier()\nrf.fit(x_tr,y_tr)\npredict = rf.predict_proba(x_va)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:38:38.013856Z","iopub.execute_input":"2024-11-28T10:38:38.014269Z","iopub.status.idle":"2024-11-28T10:40:45.971853Z","shell.execute_reply.started":"2024-11-28T10:38:38.014236Z","shell.execute_reply":"2024-11-28T10:40:45.970635Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predict","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:40:50.242001Z","iopub.execute_input":"2024-11-28T10:40:50.242441Z","iopub.status.idle":"2024-11-28T10:40:50.250384Z","shell.execute_reply.started":"2024-11-28T10:40:50.242404Z","shell.execute_reply":"2024-11-28T10:40:50.249020Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\nroc_auc_score(y_va, predict[:,1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:41:30.251653Z","iopub.execute_input":"2024-11-28T10:41:30.252066Z","iopub.status.idle":"2024-11-28T10:41:30.268367Z","shell.execute_reply.started":"2024-11-28T10:41:30.252027Z","shell.execute_reply":"2024-11-28T10:41:30.267238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression \nlr = LogisticRegression()\nlr.fit(x_tr,y_tr)\npredict = lr.predict_proba(x_va)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:41:51.126332Z","iopub.execute_input":"2024-11-28T10:41:51.126700Z","iopub.status.idle":"2024-11-28T10:41:53.411578Z","shell.execute_reply.started":"2024-11-28T10:41:51.126667Z","shell.execute_reply":"2024-11-28T10:41:53.410283Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"roc_auc_score(y_va, predict[:,1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:41:53.413498Z","iopub.execute_input":"2024-11-28T10:41:53.414523Z","iopub.status.idle":"2024-11-28T10:41:53.448586Z","shell.execute_reply.started":"2024-11-28T10:41:53.414458Z","shell.execute_reply":"2024-11-28T10:41:53.446703Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import VotingClassifier\nmodel3 = VotingClassifier(estimators=[('logistic', lr),\n                                      ('random', rf)],\n                         voting='soft')\nmodel3.fit(x_tr, y_tr)\npred3= model3.predict_proba(x_va)\nroc_auc_score(y_va, pred3[:,1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:42:24.613471Z","iopub.execute_input":"2024-11-28T10:42:24.614524Z","iopub.status.idle":"2024-11-28T10:44:35.094414Z","shell.execute_reply.started":"2024-11-28T10:42:24.614477Z","shell.execute_reply":"2024-11-28T10:44:35.093282Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model3.fit(train,y_train)\npredict = model3.predict_proba(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:45:28.538217Z","iopub.execute_input":"2024-11-28T10:45:28.539398Z","iopub.status.idle":"2024-11-28T10:48:22.857370Z","shell.execute_reply.started":"2024-11-28T10:45:28.539351Z","shell.execute_reply":"2024-11-28T10:48:22.856281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({'id': test['id'], 'Class': predict[:,1]})\nsubmission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:48:48.524762Z","iopub.execute_input":"2024-11-28T10:48:48.525225Z","iopub.status.idle":"2024-11-28T10:48:48.539958Z","shell.execute_reply.started":"2024-11-28T10:48:48.525187Z","shell.execute_reply":"2024-11-28T10:48:48.538745Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:48:55.942264Z","iopub.execute_input":"2024-11-28T10:48:55.942633Z","iopub.status.idle":"2024-11-28T10:48:56.230601Z","shell.execute_reply.started":"2024-11-28T10:48:55.942599Z","shell.execute_reply":"2024-11-28T10:48:56.229352Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.read_csv(\"submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T10:48:58.844101Z","iopub.execute_input":"2024-11-28T10:48:58.844504Z","iopub.status.idle":"2024-11-28T10:48:58.896694Z","shell.execute_reply.started":"2024-11-28T10:48:58.844466Z","shell.execute_reply":"2024-11-28T10:48:58.895570Z"}},"outputs":[],"execution_count":null}]}