{"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-29T06:06:59.836710Z","iopub.execute_input":"2024-05-29T06:06:59.838073Z","iopub.status.idle":"2024-05-29T06:07:01.260204Z","shell.execute_reply.started":"2024-05-29T06:06:59.838027Z","shell.execute_reply":"2024-05-29T06:07:01.259271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nfrom sklearn.metrics import recall_score\nfrom sklearn.metrics import precision_score\nfrom sklearn.metrics import f1_score\nfrom sklearn.metrics import roc_auc_score\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom lightgbm import LGBMClassifier","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:04.887425Z","iopub.execute_input":"2024-05-29T06:07:04.888161Z","iopub.status.idle":"2024-05-29T06:07:07.163231Z","shell.execute_reply.started":"2024-05-29T06:07:04.888112Z","shell.execute_reply":"2024-05-29T06:07:07.162034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sample = pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/sample_submission.csv')\n# sample\ndf = pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/train.csv')\ndf_submit = pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/test.csv')\n# print(test.head()) #id : 170883~end\ndf # id: 0 ~ 170882\n# test","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:10.108742Z","iopub.execute_input":"2024-05-29T06:07:10.109507Z","iopub.status.idle":"2024-05-29T06:07:15.728560Z","shell.execute_reply.started":"2024-05-29T06:07:10.109446Z","shell.execute_reply":"2024-05-29T06:07:15.727480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Class'].value_counts(dropna=False).to_frame('count').join(\n    df['Class'].value_counts(dropna=False, normalize=True).to_frame('normalize')\n).round(4)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:20.230165Z","iopub.execute_input":"2024-05-29T06:07:20.230615Z","iopub.status.idle":"2024-05-29T06:07:20.265466Z","shell.execute_reply.started":"2024-05-29T06:07:20.230583Z","shell.execute_reply":"2024-05-29T06:07:20.263662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def metrics(y_test, pred):\n    accuracy = accuracy_score(y_test, pred)\n    precision = precision_score(y_test, pred)\n    recall = recall_score(y_test, pred)\n    f1 = f1_score(y_test, pred)\n    roc_auc = roc_auc_score(y_test, pred, average='macro')\n    \n    print(f'accuracy(정확도) : {accuracy:.4f} \\nprecision(정밀도) : {precision:.4f} \\nrecall(재현율) : {recall:.4f} \\nf1 : {f1:.4f} \\nroc_auc : {roc_auc:.4f}')\n    \ndef modeling(model, x_train, x_test, y_train, y_test):\n    model.fit(x_train, y_train)\n    pred = model.predict(x_test)\n    metrics(y_test, pred)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:24.806721Z","iopub.execute_input":"2024-05-29T06:07:24.807240Z","iopub.status.idle":"2024-05-29T06:07:24.816873Z","shell.execute_reply.started":"2024-05-29T06:07:24.807199Z","shell.execute_reply":"2024-05-29T06:07:24.815486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_data = df.drop(columns=['Class'])\ny_data = df['Class']\n\nX_train, X_val, y_train, y_val = train_test_split(X_data, y_data, test_size=0.2, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:33.540351Z","iopub.execute_input":"2024-05-29T06:07:33.541342Z","iopub.status.idle":"2024-05-29T06:07:33.630023Z","shell.execute_reply.started":"2024-05-29T06:07:33.541302Z","shell.execute_reply":"2024-05-29T06:07:33.628808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lr = LogisticRegression()\n# modeling(lr, X_train, X_val, y_train, y_val)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgbm = LGBMClassifier(n_estimator=1000, num_leaves=64, n_jobs=-1, boost_from_average=False)\nmodeling(lgbm, X_train, X_val, y_train, y_val)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:07:38.002551Z","iopub.execute_input":"2024-05-29T06:07:38.002919Z","iopub.status.idle":"2024-05-29T06:07:44.324108Z","shell.execute_reply.started":"2024-05-29T06:07:38.002892Z","shell.execute_reply":"2024-05-29T06:07:44.322818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = lgbm.predict(df_submit)\ndf_submit['pred'] = pd.DataFrame(pred)\ndf_submit[['id','pred']].to_csv('submit.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T06:08:26.385393Z","iopub.execute_input":"2024-05-29T06:08:26.385814Z","iopub.status.idle":"2024-05-29T06:08:27.222122Z","shell.execute_reply.started":"2024-05-29T06:08:26.385783Z","shell.execute_reply":"2024-05-29T06:08:27.220690Z"},"trusted":true},"execution_count":null,"outputs":[]}]}