{"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":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","execution":{"iopub.status.busy":"2024-05-28T12:28:13.866519Z","iopub.execute_input":"2024-05-28T12:28:13.866928Z","iopub.status.idle":"2024-05-28T12:28:15.086222Z","shell.execute_reply.started":"2024-05-28T12:28:13.866892Z","shell.execute_reply":"2024-05-28T12:28:15.085198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ntest=pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/test.csv')\ntrain=pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/train.csv')\nprint(train.head())\nprint(test.head())","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:30:25.226136Z","iopub.execute_input":"2024-05-28T12:30:25.226545Z","iopub.status.idle":"2024-05-28T12:30:29.337903Z","shell.execute_reply.started":"2024-05-28T12:30:25.226502Z","shell.execute_reply":"2024-05-28T12:30:29.336784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:30:51.280713Z","iopub.execute_input":"2024-05-28T12:30:51.281238Z","iopub.status.idle":"2024-05-28T12:30:51.319548Z","shell.execute_reply.started":"2024-05-28T12:30:51.281196Z","shell.execute_reply":"2024-05-28T12:30:51.318585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:31:14.183530Z","iopub.execute_input":"2024-05-28T12:31:14.183925Z","iopub.status.idle":"2024-05-28T12:31:14.208016Z","shell.execute_reply.started":"2024-05-28T12:31:14.183896Z","shell.execute_reply":"2024-05-28T12:31:14.206721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape,test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:31:48.547662Z","iopub.execute_input":"2024-05-28T12:31:48.548094Z","iopub.status.idle":"2024-05-28T12:31:48.553938Z","shell.execute_reply.started":"2024-05-28T12:31:48.548059Z","shell.execute_reply":"2024-05-28T12:31:48.552877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols=list(train.columns[1:31])","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:33:56.635629Z","iopub.execute_input":"2024-05-28T12:33:56.636006Z","iopub.status.idle":"2024-05-28T12:33:56.640434Z","shell.execute_reply.started":"2024-05-28T12:33:56.635974Z","shell.execute_reply":"2024-05-28T12:33:56.639694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_id=test.pop('id')","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:35:12.652919Z","iopub.execute_input":"2024-05-28T12:35:12.653283Z","iopub.status.idle":"2024-05-28T12:35:12.659156Z","shell.execute_reply.started":"2024-05-28T12:35:12.653255Z","shell.execute_reply":"2024-05-28T12:35:12.657956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train['Class']","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:36:33.685218Z","iopub.execute_input":"2024-05-28T12:36:33.685625Z","iopub.status.idle":"2024-05-28T12:36:33.691067Z","shell.execute_reply.started":"2024-05-28T12:36:33.685573Z","shell.execute_reply":"2024-05-28T12:36:33.689902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_tr, X_val, y_tr, y_val=train_test_split(train[cols],target,test_size=0.2, random_state=0)\n\nprint(X_tr.shape, X_val.shape, y_tr.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:38:04.790262Z","iopub.execute_input":"2024-05-28T12:38:04.790945Z","iopub.status.idle":"2024-05-28T12:38:05.002417Z","shell.execute_reply.started":"2024-05-28T12:38:04.790909Z","shell.execute_reply":"2024-05-28T12:38:05.000861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrfc=RandomForestClassifier()\nrfc.fit(X_tr,y_tr)\npred=rfc.predict(X_val)\npred","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:40:46.499875Z","iopub.execute_input":"2024-05-28T12:40:46.500245Z","iopub.status.idle":"2024-05-28T12:42:49.697560Z","shell.execute_reply.started":"2024-05-28T12:40:46.500219Z","shell.execute_reply":"2024-05-28T12:42:49.696473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_proba=rfc.predict_proba(X_val)\npred_proba","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:43:11.515415Z","iopub.execute_input":"2024-05-28T12:43:11.515839Z","iopub.status.idle":"2024-05-28T12:43:11.827319Z","shell.execute_reply.started":"2024-05-28T12:43:11.515804Z","shell.execute_reply":"2024-05-28T12:43:11.826237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\nprint(roc_auc_score(y_val,pred))","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:46:20.862230Z","iopub.execute_input":"2024-05-28T12:46:20.862583Z","iopub.status.idle":"2024-05-28T12:46:20.879902Z","shell.execute_reply.started":"2024-05-28T12:46:20.862555Z","shell.execute_reply":"2024-05-28T12:46:20.878807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(roc_auc_score(y_val,pred_proba[:,1]))","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:47:34.594728Z","iopub.execute_input":"2024-05-28T12:47:34.595170Z","iopub.status.idle":"2024-05-28T12:47:34.608848Z","shell.execute_reply.started":"2024-05-28T12:47:34.595125Z","shell.execute_reply":"2024-05-28T12:47:34.607913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test=rfc.predict_proba(test)[:,1]\npred_test","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:52:34.523552Z","iopub.execute_input":"2024-05-28T12:52:34.524011Z","iopub.status.idle":"2024-05-28T12:52:35.557249Z","shell.execute_reply.started":"2024-05-28T12:52:34.523974Z","shell.execute_reply":"2024-05-28T12:52:35.556114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit=pd.DataFrame(\n    {\n    'id': test_id,\n    'Class': pred_test\n    }\n)\n\nsubmit","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:54:17.270814Z","iopub.execute_input":"2024-05-28T12:54:17.271221Z","iopub.status.idle":"2024-05-28T12:54:17.287527Z","shell.execute_reply.started":"2024-05-28T12:54:17.271187Z","shell.execute_reply":"2024-05-28T12:54:17.286502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:56:47.098421Z","iopub.execute_input":"2024-05-28T12:56:47.098816Z","iopub.status.idle":"2024-05-28T12:56:47.317150Z","shell.execute_reply.started":"2024-05-28T12:56:47.098780Z","shell.execute_reply":"2024-05-28T12:56:47.316136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('submission.csv')","metadata":{"execution":{"iopub.status.busy":"2024-05-28T12:57:04.725985Z","iopub.execute_input":"2024-05-28T12:57:04.726364Z","iopub.status.idle":"2024-05-28T12:57:04.767612Z","shell.execute_reply.started":"2024-05-28T12:57:04.726336Z","shell.execute_reply":"2024-05-28T12:57:04.766497Z"},"trusted":true},"execution_count":null,"outputs":[]}]}