{"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":"# 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-28T22:26:40.727856Z","iopub.execute_input":"2024-05-28T22:26:40.728382Z","iopub.status.idle":"2024-05-28T22:26:41.209802Z","shell.execute_reply.started":"2024-05-28T22:26:40.728342Z","shell.execute_reply":"2024-05-28T22:26:41.208577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\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')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:46:55.304683Z","iopub.execute_input":"2024-05-28T22:46:55.305073Z","iopub.status.idle":"2024-05-28T22:46:57.902295Z","shell.execute_reply.started":"2024-05-28T22:46:55.305045Z","shell.execute_reply":"2024-05-28T22:46:57.901070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape,'\\n')\nprint(train.info(),'\\n')\nprint(train.describe(),'\\n')\nprint(test.shape,'\\n')\nprint(test.info(),'\\n')\nprint(test.describe())","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:02.831014Z","iopub.execute_input":"2024-05-28T22:47:02.831432Z","iopub.status.idle":"2024-05-28T22:47:03.367843Z","shell.execute_reply.started":"2024-05-28T22:47:02.831399Z","shell.execute_reply":"2024-05-28T22:47:03.366670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = pd.DataFrame(train['Class'])\nX = train.drop(['id','Class'],axis=1)\nprint(X.head())\nprint(y.head())\nprint(X.shape, y.shape)\n\nid_test = pd.DataFrame(test['id'])\nX_test = test.drop('id', axis=1)\nprint(X_test.head())\nprint(id_test.shape, X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:09.338194Z","iopub.execute_input":"2024-05-28T22:47:09.338581Z","iopub.status.idle":"2024-05-28T22:47:09.393725Z","shell.execute_reply.started":"2024-05-28T22:47:09.338551Z","shell.execute_reply":"2024-05-28T22:47:09.392457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.15,\n                                                  random_state=2024)\nprint(X_train.shape, X_val.shape, y_train.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:10.930841Z","iopub.execute_input":"2024-05-28T22:47:10.931218Z","iopub.status.idle":"2024-05-28T22:47:10.995089Z","shell.execute_reply.started":"2024-05-28T22:47:10.931191Z","shell.execute_reply":"2024-05-28T22:47:10.993702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_train.value_counts())\nprint(y_val.value_counts())","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:12.155723Z","iopub.execute_input":"2024-05-28T22:47:12.156120Z","iopub.status.idle":"2024-05-28T22:47:12.169702Z","shell.execute_reply.started":"2024-05-28T22:47:12.156091Z","shell.execute_reply":"2024-05-28T22:47:12.168464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('y_train Class ratio : ',y_train.value_counts()[0]/y_train.value_counts()[1])\nprint('y_val Class ratio : ',y_val.value_counts()[0]/y_val.value_counts()[1])","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:12.645433Z","iopub.execute_input":"2024-05-28T22:47:12.645866Z","iopub.status.idle":"2024-05-28T22:47:12.663792Z","shell.execute_reply.started":"2024-05-28T22:47:12.645832Z","shell.execute_reply":"2024-05-28T22:47:12.662677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nrfc = RandomForestClassifier(100, max_depth = 5, random_state=2024)\nrfc.fit(X_train, y_train)\npred = rfc.predict(X_val)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:47:38.688506Z","iopub.execute_input":"2024-05-28T22:47:38.689400Z","iopub.status.idle":"2024-05-28T22:48:30.637407Z","shell.execute_reply.started":"2024-05-28T22:47:38.689353Z","shell.execute_reply":"2024-05-28T22:48:30.636403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:48:34.622980Z","iopub.execute_input":"2024-05-28T22:48:34.623390Z","iopub.status.idle":"2024-05-28T22:48:34.631094Z","shell.execute_reply.started":"2024-05-28T22:48:34.623358Z","shell.execute_reply":"2024-05-28T22:48:34.629693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\n\nroc_auc_score(y_val, pred)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:48:36.491722Z","iopub.execute_input":"2024-05-28T22:48:36.492162Z","iopub.status.idle":"2024-05-28T22:48:36.510613Z","shell.execute_reply.started":"2024-05-28T22:48:36.492130Z","shell.execute_reply":"2024-05-28T22:48:36.509133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test = rfc.predict(X_test)\nsubmission = pd.DataFrame({'id' : id_test['id'], 'Class' : pred_test})\ndisplay(submission)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:57:02.557539Z","iopub.execute_input":"2024-05-28T22:57:02.558541Z","iopub.status.idle":"2024-05-28T22:57:03.139244Z","shell.execute_reply.started":"2024-05-28T22:57:02.558495Z","shell.execute_reply":"2024-05-28T22:57:03.137806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T22:57:05.910300Z","iopub.execute_input":"2024-05-28T22:57:05.910744Z","iopub.status.idle":"2024-05-28T22:57:06.075175Z","shell.execute_reply.started":"2024-05-28T22:57:05.910708Z","shell.execute_reply":"2024-05-28T22:57:06.073994Z"},"trusted":true},"execution_count":null,"outputs":[]}]}