{"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-28T13:41:19.552862Z","iopub.execute_input":"2024-05-28T13:41:19.553203Z","iopub.status.idle":"2024-05-28T13:41:20.736086Z","shell.execute_reply.started":"2024-05-28T13:41:19.553175Z","shell.execute_reply":"2024-05-28T13:41:20.735083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\nfrom xgboost import XGBClassifier\nfrom sklearn.metrics import roc_auc_score","metadata":{"execution":{"iopub.status.busy":"2024-05-28T13:59:44.003416Z","iopub.execute_input":"2024-05-28T13:59:44.003898Z","iopub.status.idle":"2024-05-28T13:59:44.010523Z","shell.execute_reply.started":"2024-05-28T13:59:44.003865Z","shell.execute_reply":"2024-05-28T13:59:44.008995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/train.csv')\nX_submission = pd.read_csv('/kaggle/input/big-data-analytics-certification-kr-2024-2/test.csv')\n\nx_train = X.drop(columns=['Class'])\ny_train = X['Class']\n\n","metadata":{"execution":{"iopub.status.busy":"2024-05-28T14:04:27.700028Z","iopub.execute_input":"2024-05-28T14:04:27.700476Z","iopub.status.idle":"2024-05-28T14:04:30.508460Z","shell.execute_reply.started":"2024-05-28T14:04:27.700444Z","shell.execute_reply":"2024-05-28T14:04:30.506939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_scores(model, xtrain, xtest, ytrain, ytest):\n    A = model.score(xtrain, ytrain)\n    B = model.score(xtest, ytest)\n    ypred = model.predict_proba(xtest)[:,1]\n    C = roc_auc_score(ytest, ypred)\n    return '{:.4f} {:.4f} {:.4f}'.format(A, B, C)\n\ndef make_models(xtrain, xtest, ytrain, ytest):\n    model1 = LogisticRegression(max_iter=5000).fit(xtrain, ytrain)\n    print('model1', get_scores(model1, xtrain, xtest, ytrain, ytest))\n    \n    for k in range(9,10):\n        model2 = KNeighborsClassifier(k).fit(xtrain, ytrain)\n        print('model2', k, get_scores(model2, xtrain, xtest, ytrain, ytest))\n        \n    model3 = DecisionTreeClassifier(random_state=0).fit(xtrain, ytrain)\n    print('model3', get_scores(model3, xtrain, xtest, ytrain, ytest))\n    for d in range(3,6):\n        model3 = DecisionTreeClassifier(max_depth = d, random_state=0).fit(xtrain, ytrain)\n        print('model3', d, get_scores(model3, xtrain, xtest, ytrain, ytest))\n        \n    model4 = RandomForestClassifier(random_state=0).fit(xtrain, ytrain)\n    print('model4', get_scores(model4, xtrain, xtest, ytrain, ytest))\n    for d in range(3,6):\n        model4 = RandomForestClassifier(500, max_depth = d, random_state=0).fit(xtrain, ytrain)\n        print('model4', d, get_scores(model4, xtrain, xtest, ytrain, ytest))\n        \n    model5 = XGBClassifier().fit(xtrain, ytrain)\n    print('model5', get_scores(model5, xtrain, xtest, ytrain, ytest))","metadata":{"execution":{"iopub.status.busy":"2024-05-28T14:34:22.204317Z","iopub.execute_input":"2024-05-28T14:34:22.204753Z","iopub.status.idle":"2024-05-28T14:34:22.216726Z","shell.execute_reply.started":"2024-05-28T14:34:22.204722Z","shell.execute_reply":"2024-05-28T14:34:22.215148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xtrain, xtest, ytrain, ytest = train_test_split(x_train, y_train,\n                                                test_size=0.3,\n                                                stratify=y_train,\n                                                random_state=0)\n\nmodel = RandomForestClassifier(500, max_depth = 5, random_state=0).fit(xtrain, ytrain)\n\npred = model.predict_proba(X_submission)[:,1]\nsubmission = pd.DataFrame({'id': X_submission['id'], 'class':pred})\n\n#print(submission.head())","metadata":{"execution":{"iopub.status.busy":"2024-05-28T14:52:16.815261Z","iopub.execute_input":"2024-05-28T14:52:16.815742Z","iopub.status.idle":"2024-05-28T14:56:01.981690Z","shell.execute_reply.started":"2024-05-28T14:52:16.815701Z","shell.execute_reply":"2024-05-28T14:56:01.980265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{},"execution_count":null,"outputs":[]}]}