{"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":88400,"databundleVersionId":10121331,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import 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","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:37:04.694638Z","iopub.execute_input":"2024-11-12T05:37:04.695141Z","iopub.status.idle":"2024-11-12T05:37:05.160221Z","shell.execute_reply.started":"2024-11-12T05:37:04.695099Z","shell.execute_reply":"2024-11-12T05:37:05.158969Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/train.csv\") \ntest = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/test.csv\")\nsubmission = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/sample_submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:37:05.162250Z","iopub.execute_input":"2024-11-12T05:37:05.162798Z","iopub.status.idle":"2024-11-12T05:37:09.534764Z","shell.execute_reply.started":"2024-11-12T05:37:05.162756Z","shell.execute_reply":"2024-11-12T05:37:09.533791Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"conda install -c conda-forge imbalanced-learn","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:37:09.536085Z","iopub.execute_input":"2024-11-12T05:37:09.536422Z","iopub.status.idle":"2024-11-12T05:39:04.118457Z","shell.execute_reply.started":"2024-11-12T05:37:09.536386Z","shell.execute_reply":"2024-11-12T05:39:04.117088Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n\ntrain.head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.121691Z","iopub.execute_input":"2024-11-12T05:39:04.122161Z","iopub.status.idle":"2024-11-12T05:39:04.171866Z","shell.execute_reply.started":"2024-11-12T05:39:04.122114Z","shell.execute_reply":"2024-11-12T05:39:04.170406Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.173312Z","iopub.execute_input":"2024-11-12T05:39:04.173681Z","iopub.status.idle":"2024-11-12T05:39:04.223358Z","shell.execute_reply.started":"2024-11-12T05:39:04.173643Z","shell.execute_reply":"2024-11-12T05:39:04.222087Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.224705Z","iopub.execute_input":"2024-11-12T05:39:04.225088Z","iopub.status.idle":"2024-11-12T05:39:04.244654Z","shell.execute_reply.started":"2024-11-12T05:39:04.225049Z","shell.execute_reply":"2024-11-12T05:39:04.243511Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.246061Z","iopub.execute_input":"2024-11-12T05:39:04.246475Z","iopub.status.idle":"2024-11-12T05:39:04.253781Z","shell.execute_reply.started":"2024-11-12T05:39:04.246434Z","shell.execute_reply":"2024-11-12T05:39:04.252494Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.255443Z","iopub.execute_input":"2024-11-12T05:39:04.255812Z","iopub.status.idle":"2024-11-12T05:39:04.571281Z","shell.execute_reply.started":"2024-11-12T05:39:04.255774Z","shell.execute_reply":"2024-11-12T05:39:04.570215Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Class'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.572628Z","iopub.execute_input":"2024-11-12T05:39:04.572989Z","iopub.status.idle":"2024-11-12T05:39:04.584736Z","shell.execute_reply.started":"2024-11-12T05:39:04.572952Z","shell.execute_reply":"2024-11-12T05:39:04.583505Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[train['Class']==1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.588179Z","iopub.execute_input":"2024-11-12T05:39:04.588563Z","iopub.status.idle":"2024-11-12T05:39:04.624519Z","shell.execute_reply.started":"2024-11-12T05:39:04.588525Z","shell.execute_reply":"2024-11-12T05:39:04.623379Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.626134Z","iopub.execute_input":"2024-11-12T05:39:04.626620Z","iopub.status.idle":"2024-11-12T05:39:04.976225Z","shell.execute_reply.started":"2024-11-12T05:39:04.626558Z","shell.execute_reply":"2024-11-12T05:39:04.975100Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.scatterplot(data=train,x='Time',y='Amount',hue='Class')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:39:04.977535Z","iopub.execute_input":"2024-11-12T05:39:04.977996Z","iopub.status.idle":"2024-11-12T05:39:14.944548Z","shell.execute_reply.started":"2024-11-12T05:39:04.977959Z","shell.execute_reply":"2024-11-12T05:39:14.943326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train['Class'].value_counts())\nfraud_cnt=train[train['Class']==1].Class.count()\ntotal_cnt=train.Class.count()\nprint('fraud 비율은 {0:2f}'.format((fraud_cnt/total_cnt)))\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T06:00:39.239496Z","iopub.execute_input":"2024-11-12T06:00:39.240613Z","iopub.status.idle":"2024-11-12T06:00:39.259669Z","shell.execute_reply.started":"2024-11-12T06:00:39.240526Z","shell.execute_reply":"2024-11-12T06:00:39.258141Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[['V1','V2','V3']].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T06:13:58.789257Z","iopub.execute_input":"2024-11-12T06:13:58.789747Z","iopub.status.idle":"2024-11-12T06:13:59.020570Z","shell.execute_reply.started":"2024-11-12T06:13:58.789704Z","shell.execute_reply":"2024-11-12T06:13:59.019418Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# from sklearn.ensemble import GradientBoostingClassifier\n# import time\n# import warnings\n# warnings.filterwarnings('ignore')\n\n\n# X_train = train.drop(['id', 'Class'], axis=1)\n# y_train = train['Class']\n\n# X_test = test.drop(['id'], axis=1)\n# y_test=test['Class']\n\n# start_time=time.time()\n\n# gb_clf=GradientBoostingClassifier(random_state=0)\n# gb_clf.fit(X_train,y_train)\n# gb_pred=gb_clf.predict(X_test)\n# gb_accuracy=accuracy_score(y_test,gb_pred)\n\n# print('GBM 정확도:{0:.4f}'.format(gb_accuracy))\n# print('GBM 수행시간:{0:.1f}'.format(time.time()-start_time))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T07:14:35.674409Z","iopub.execute_input":"2024-11-12T07:14:35.675056Z","iopub.status.idle":"2024-11-12T07:14:35.681773Z","shell.execute_reply.started":"2024-11-12T07:14:35.674994Z","shell.execute_reply":"2024-11-12T07:14:35.680415Z"}},"outputs":[],"execution_count":null}]}