{"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":50160,"databundleVersionId":7921029,"sourceType":"competition"}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Install & Import Package & Read","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"!pip install googletrans==3.1.0a0 --upgrade --quiet","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-03-16T03:28:31.558991Z","iopub.execute_input":"2024-03-16T03:28:31.559425Z","iopub.status.idle":"2024-03-16T03:28:55.483874Z","shell.execute_reply.started":"2024-03-16T03:28:31.559388Z","shell.execute_reply":"2024-03-16T03:28:55.482106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from googletrans import Translator\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport polars as pl\nimport gc\nimport warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-16T03:28:59.488304Z","iopub.execute_input":"2024-03-16T03:28:59.488737Z","iopub.status.idle":"2024-03-16T03:29:01.334459Z","shell.execute_reply.started":"2024-03-16T03:28:59.488701Z","shell.execute_reply":"2024-03-16T03:29:01.333563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.float_format', lambda x: '%.2f' % x)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:29.039235Z","iopub.execute_input":"2024-03-16T03:29:29.039820Z","iopub.status.idle":"2024-03-16T03:29:29.048674Z","shell.execute_reply.started":"2024-03-16T03:29:29.039787Z","shell.execute_reply":"2024-03-16T03:29:29.046481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base = pd.read_csv(\"/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_base.csv\")\ndf = pd.read_csv(\"/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_deposit_1.csv\")\nfd = pd.read_csv(\"/kaggle/input/home-credit-credit-risk-model-stability/feature_definitions.csv\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-16T03:29:30.602962Z","iopub.execute_input":"2024-03-16T03:29:30.604297Z","iopub.status.idle":"2024-03-16T03:29:32.333808Z","shell.execute_reply.started":"2024-03-16T03:29:30.604249Z","shell.execute_reply":"2024-03-16T03:29:32.332199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp = fd.loc[fd['Variable'].isin(list(df.columns))]\ntranslator = Translator()\ntmp[\"Description_ko\"] = tmp[\"Description\"].map(lambda x: translator.translate(x, src=\"en\", dest=\"ko\").text)\ntmp['fea_type'] = tmp['Variable'].apply(lambda x: x[-1])","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-03-16T03:29:32.336095Z","iopub.execute_input":"2024-03-16T03:29:32.336494Z","iopub.status.idle":"2024-03-16T03:29:32.540353Z","shell.execute_reply.started":"2024-03-16T03:29:32.336462Z","shell.execute_reply":"2024-03-16T03:29:32.539068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.542203Z","iopub.execute_input":"2024-03-16T03:29:32.543118Z","iopub.status.idle":"2024-03-16T03:29:32.563430Z","shell.execute_reply.started":"2024-03-16T03:29:32.543067Z","shell.execute_reply":"2024-03-16T03:29:32.562148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## We can see that `train_deposit_1` below:","metadata":{}},{"cell_type":"code","source":"df","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-16T03:29:32.565998Z","iopub.execute_input":"2024-03-16T03:29:32.566413Z","iopub.status.idle":"2024-03-16T03:29:32.586583Z","shell.execute_reply.started":"2024-03-16T03:29:32.566377Z","shell.execute_reply":"2024-03-16T03:29:32.585201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"shape of Depth_1: train_deposit_1 \", df.shape)\nprint(\"the unique case_id : \", len(set(df.case_id)))\nprint(\"all case_id in train_base are: \", len(train_base.case_id))\nprint(\"Only \",100*round(len(set(df.case_id))/len(train_base.case_id),3),\"%\", \"case_id in train_base have deposit_1 history records\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-16T03:29:32.588822Z","iopub.execute_input":"2024-03-16T03:29:32.589273Z","iopub.status.idle":"2024-03-16T03:29:32.666310Z","shell.execute_reply.started":"2024-03-16T03:29:32.589234Z","shell.execute_reply":"2024-03-16T03:29:32.664502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It'means if we build new features from `train_deposit_1` dataset, **93%** case_id in train_base will be NAN for all features !!!\n\n***\n\n## Description example : case_id = 1377353","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"df.loc[df['case_id'] == 1377353].sort_values(['num_group1'])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-16T03:29:32.668450Z","iopub.execute_input":"2024-03-16T03:29:32.668846Z","iopub.status.idle":"2024-03-16T03:29:32.694204Z","shell.execute_reply.started":"2024-03-16T03:29:32.668812Z","shell.execute_reply":"2024-03-16T03:29:32.693082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.696177Z","iopub.execute_input":"2024-03-16T03:29:32.696544Z","iopub.status.idle":"2024-03-16T03:29:32.754402Z","shell.execute_reply.started":"2024-03-16T03:29:32.696509Z","shell.execute_reply":"2024-03-16T03:29:32.752072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['case_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.757263Z","iopub.execute_input":"2024-03-16T03:29:32.757626Z","iopub.status.idle":"2024-03-16T03:29:32.786855Z","shell.execute_reply.started":"2024-03-16T03:29:32.757594Z","shell.execute_reply":"2024-03-16T03:29:32.785508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['amount_416A'].value_counts().sort_index().head(30)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.788772Z","iopub.execute_input":"2024-03-16T03:29:32.789253Z","iopub.status.idle":"2024-03-16T03:29:32.823011Z","shell.execute_reply.started":"2024-03-16T03:29:32.789209Z","shell.execute_reply":"2024-03-16T03:29:32.821706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['amount_416A'].value_counts().sort_index().tail(30)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.852539Z","iopub.execute_input":"2024-03-16T03:29:32.853058Z","iopub.status.idle":"2024-03-16T03:29:32.881769Z","shell.execute_reply.started":"2024-03-16T03:29:32.853018Z","shell.execute_reply":"2024-03-16T03:29:32.880324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['amount_416A'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:32.985494Z","iopub.execute_input":"2024-03-16T03:29:32.985921Z","iopub.status.idle":"2024-03-16T03:29:33.012515Z","shell.execute_reply.started":"2024-03-16T03:29:32.985887Z","shell.execute_reply":"2024-03-16T03:29:33.011221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# 1. case_id 별 계좌 수","metadata":{}},{"cell_type":"code","source":"# case_id 별 계좌 수를 데이터프레임으로 만듭니다.\naccount_counts_df = df['case_id'].value_counts().reset_index()\n\n# 칼럼 이름을 변경합니다.\naccount_counts_df.columns = ['case_id', 'account_count']\naccount_counts_df","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:33.478804Z","iopub.execute_input":"2024-03-16T03:29:33.479264Z","iopub.status.idle":"2024-03-16T03:29:33.510268Z","shell.execute_reply.started":"2024-03-16T03:29:33.479229Z","shell.execute_reply":"2024-03-16T03:29:33.509106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# 2. case_id 별 금액이 0인 계좌수","metadata":{}},{"cell_type":"code","source":"# 금액이 0인 계좌를 필터링하여 새로운 데이터프레임을 만듭니다.\nzero_amount_accounts = df[df['amount_416A'] == 0]\n\n# case_id 별로 그룹화하여 계좌 수를 구합니다.\nzero_amount_counts = zero_amount_accounts['case_id'].value_counts().reset_index()\n\n# 칼럼 이름을 변경합니다.\nzero_amount_counts.columns = ['case_id', 'zero_amount_account_count']\n\n# 결과를 출력합니다.\nzero_amount_counts","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:34.012215Z","iopub.execute_input":"2024-03-16T03:29:34.012599Z","iopub.status.idle":"2024-03-16T03:29:34.038522Z","shell.execute_reply.started":"2024-03-16T03:29:34.012571Z","shell.execute_reply":"2024-03-16T03:29:34.037530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# 3. case_id 별 만료일이 있는 계좌의 비율","metadata":{}},{"cell_type":"code","source":"# case_id 별로 contractenddate_991D 칼럼에 값이 있는 경우의 비율을 구합니다.\nnonnull_ratio = df.groupby('case_id')['contractenddate_991D'].apply(lambda x: x.notnull().sum() / len(x)).reset_index()\n\n# 칼럼 이름을 변경합니다.\nnonnull_ratio.columns = ['case_id', 'expired_account_ratio']\n\n# 결과를 출력합니다.\nnonnull_ratio","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:34.448219Z","iopub.execute_input":"2024-03-16T03:29:34.448709Z","iopub.status.idle":"2024-03-16T03:29:50.338239Z","shell.execute_reply.started":"2024-03-16T03:29:34.448675Z","shell.execute_reply":"2024-03-16T03:29:50.337103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# 4. case_id 별 총 예금 금액","metadata":{}},{"cell_type":"code","source":"# case_id 별로 amount_416A 칼럼의 값을 구합니다.\namount_by_case_id = df.groupby('case_id')['amount_416A'].sum().reset_index()\n\n# 결과를 출력합니다.\namount_by_case_id.columns = ['case_id', 'total_amount']\namount_by_case_id","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.340506Z","iopub.execute_input":"2024-03-16T03:29:50.341915Z","iopub.status.idle":"2024-03-16T03:29:50.373375Z","shell.execute_reply.started":"2024-03-16T03:29:50.341850Z","shell.execute_reply":"2024-03-16T03:29:50.372255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# merge","metadata":{}},{"cell_type":"code","source":"# account_counts_df와 zero_amount_counts를 왼쪽 머지하여 합칩니다.\nmerged_df = pd.merge(account_counts_df, zero_amount_counts, how='left', on='case_id')\n\n# 널값을 0으로 채워줍니다.\nmerged_df['zero_amount_account_count'] = merged_df['zero_amount_account_count'].fillna(0)\n\n# 결과를 출력합니다.\nmerged_df","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.374873Z","iopub.execute_input":"2024-03-16T03:29:50.375279Z","iopub.status.idle":"2024-03-16T03:29:50.425156Z","shell.execute_reply.started":"2024-03-16T03:29:50.375247Z","shell.execute_reply":"2024-03-16T03:29:50.423769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merged_df = pd.merge(merged_df, nonnull_ratio, how='left', on='case_id')\nmerged_df","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.428681Z","iopub.execute_input":"2024-03-16T03:29:50.429206Z","iopub.status.idle":"2024-03-16T03:29:50.479018Z","shell.execute_reply.started":"2024-03-16T03:29:50.429161Z","shell.execute_reply":"2024-03-16T03:29:50.477475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merged_df = pd.merge(merged_df, amount_by_case_id, how='left', on='case_id')\nmerged_df","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.480682Z","iopub.execute_input":"2024-03-16T03:29:50.481075Z","iopub.status.idle":"2024-03-16T03:29:50.531898Z","shell.execute_reply.started":"2024-03-16T03:29:50.481040Z","shell.execute_reply":"2024-03-16T03:29:50.530489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# train_base 와 결합하기","metadata":{}},{"cell_type":"code","source":"train_base","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.534221Z","iopub.execute_input":"2024-03-16T03:29:50.535089Z","iopub.status.idle":"2024-03-16T03:29:50.554559Z","shell.execute_reply.started":"2024-03-16T03:29:50.535035Z","shell.execute_reply":"2024-03-16T03:29:50.552643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1 = pd.merge(train_base, merged_df, how='inner', on='case_id')\ntrain_base_deposit_1","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.556594Z","iopub.execute_input":"2024-03-16T03:29:50.557186Z","iopub.status.idle":"2024-03-16T03:29:50.886139Z","shell.execute_reply.started":"2024-03-16T03:29:50.557146Z","shell.execute_reply":"2024-03-16T03:29:50.884918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_base_deposit_1 = pd.merge(train_base, merged_df, how='left', on='case_id')\n# train_base_deposit_1 = train_base_deposit_1.fillna(0)\n# train_base_deposit_1","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.887696Z","iopub.execute_input":"2024-03-16T03:29:50.888095Z","iopub.status.idle":"2024-03-16T03:29:50.894266Z","shell.execute_reply.started":"2024-03-16T03:29:50.888061Z","shell.execute_reply":"2024-03-16T03:29:50.892854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.896151Z","iopub.execute_input":"2024-03-16T03:29:50.896598Z","iopub.status.idle":"2024-03-16T03:29:50.928643Z","shell.execute_reply.started":"2024-03-16T03:29:50.896564Z","shell.execute_reply":"2024-03-16T03:29:50.927291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# account_count","metadata":{}},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==1]['account_count'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.934756Z","iopub.execute_input":"2024-03-16T03:29:50.935188Z","iopub.status.idle":"2024-03-16T03:29:50.950579Z","shell.execute_reply.started":"2024-03-16T03:29:50.935153Z","shell.execute_reply":"2024-03-16T03:29:50.948851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['account_count'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.952338Z","iopub.execute_input":"2024-03-16T03:29:50.952723Z","iopub.status.idle":"2024-03-16T03:29:50.975213Z","shell.execute_reply.started":"2024-03-16T03:29:50.952688Z","shell.execute_reply":"2024-03-16T03:29:50.973276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 계좌수가 9개 이상인 사람은 제외한 df만 가져오기","metadata":{"execution":{"iopub.status.busy":"2024-03-11T05:47:31.553756Z","iopub.execute_input":"2024-03-11T05:47:31.554162Z","iopub.status.idle":"2024-03-11T05:47:31.559420Z","shell.execute_reply.started":"2024-03-11T05:47:31.554132Z","shell.execute_reply":"2024-03-11T05:47:31.558524Z"}}},{"cell_type":"code","source":"df = train_base_deposit_1\ndf2 = df[df['account_count'] > 8]\ndf2['case_id'].unique()\na= df2['case_id'].unique().tolist()\ndf3=df[~df['case_id'].isin(a)]\ndf3","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:50.977472Z","iopub.execute_input":"2024-03-16T03:29:50.977892Z","iopub.status.idle":"2024-03-16T03:29:51.005848Z","shell.execute_reply.started":"2024-03-16T03:29:50.977857Z","shell.execute_reply":"2024-03-16T03:29:51.004783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 account_count 값의 분포\ncounts_target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['account_count'].value_counts().sort_index()\n# 타깃이 1일 때의 account_count 값의 분포\ncounts_target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['account_count'].value_counts().sort_index()\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.4, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.4, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of account_count for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('account_count')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:51.007490Z","iopub.execute_input":"2024-03-16T03:29:51.008283Z","iopub.status.idle":"2024-03-16T03:29:51.508481Z","shell.execute_reply.started":"2024-03-16T03:29:51.008242Z","shell.execute_reply":"2024-03-16T03:29:51.507161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 account_count 값의 분포\ncounts_target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['account_count'].value_counts().sort_index().head(8)\n# 타깃이 1일 때의 account_count 값의 분포\ncounts_target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['account_count'].value_counts().sort_index().head(8)\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.4, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.4, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of account_count for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('account_count')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:51.510242Z","iopub.execute_input":"2024-03-16T03:29:51.512334Z","iopub.status.idle":"2024-03-16T03:29:51.912495Z","shell.execute_reply.started":"2024-03-16T03:29:51.512279Z","shell.execute_reply":"2024-03-16T03:29:51.910819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# zero_amount_account_count","metadata":{}},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==1]['zero_amount_account_count'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:51.914617Z","iopub.execute_input":"2024-03-16T03:29:51.915929Z","iopub.status.idle":"2024-03-16T03:29:51.931362Z","shell.execute_reply.started":"2024-03-16T03:29:51.915871Z","shell.execute_reply":"2024-03-16T03:29:51.928774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['zero_amount_account_count'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:51.933911Z","iopub.execute_input":"2024-03-16T03:29:51.934583Z","iopub.status.idle":"2024-03-16T03:29:51.959867Z","shell.execute_reply.started":"2024-03-16T03:29:51.934524Z","shell.execute_reply":"2024-03-16T03:29:51.958401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 계좌에 들어있는 돈이 0 인 계좌수 => 8개 이상인 사람제외","metadata":{}},{"cell_type":"code","source":"df2 = df[df['zero_amount_account_count'] >= 8]\na=df2['case_id'].unique().tolist()\ndf3=df[~df['case_id'].isin(a)]\ndf3","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:51.965129Z","iopub.execute_input":"2024-03-16T03:29:51.965564Z","iopub.status.idle":"2024-03-16T03:29:51.998671Z","shell.execute_reply.started":"2024-03-16T03:29:51.965532Z","shell.execute_reply":"2024-03-16T03:29:51.997171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 zero_amount_account_count 값의 분포\ncounts_target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['zero_amount_account_count'].value_counts().sort_index()\n# 타깃이 1일 때의 zero_amount_account_count 값의 분포\ncounts_target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['zero_amount_account_count'].value_counts().sort_index()\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.4, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.4, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of zero_amount_account_count for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('zero_amount_account_count')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:52.001008Z","iopub.execute_input":"2024-03-16T03:29:52.001453Z","iopub.status.idle":"2024-03-16T03:29:52.635623Z","shell.execute_reply.started":"2024-03-16T03:29:52.001417Z","shell.execute_reply":"2024-03-16T03:29:52.634095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 zero_amount_account_count 값의 분포\ncounts_target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['zero_amount_account_count'].value_counts().sort_index().head(10)\n# 타깃이 1일 때의 zero_amount_account_count 값의 분포\ncounts_target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['zero_amount_account_count'].value_counts().sort_index().head(10)\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.4, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.4, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of zero_amount_account_count for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('zero_amount_account_count')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:52.637801Z","iopub.execute_input":"2024-03-16T03:29:52.640077Z","iopub.status.idle":"2024-03-16T03:29:52.998815Z","shell.execute_reply.started":"2024-03-16T03:29:52.640036Z","shell.execute_reply":"2024-03-16T03:29:52.997655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# expired_account_ratio","metadata":{}},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['expired_account_ratio'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.000538Z","iopub.execute_input":"2024-03-16T03:29:53.000998Z","iopub.status.idle":"2024-03-16T03:29:53.022393Z","shell.execute_reply.started":"2024-03-16T03:29:53.000956Z","shell.execute_reply":"2024-03-16T03:29:53.020897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==1]['expired_account_ratio'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.026120Z","iopub.execute_input":"2024-03-16T03:29:53.026659Z","iopub.status.idle":"2024-03-16T03:29:53.040824Z","shell.execute_reply.started":"2024-03-16T03:29:53.026614Z","shell.execute_reply":"2024-03-16T03:29:53.039006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counts_target_0","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.042735Z","iopub.execute_input":"2024-03-16T03:29:53.043365Z","iopub.status.idle":"2024-03-16T03:29:53.054051Z","shell.execute_reply.started":"2024-03-16T03:29:53.043322Z","shell.execute_reply":"2024-03-16T03:29:53.052527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counts_target_0_log","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.055778Z","iopub.execute_input":"2024-03-16T03:29:53.056258Z","iopub.status.idle":"2024-03-16T03:29:53.069431Z","shell.execute_reply.started":"2024-03-16T03:29:53.056216Z","shell.execute_reply":"2024-03-16T03:29:53.067833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1['expired_account_ratio']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.073378Z","iopub.execute_input":"2024-03-16T03:29:53.073912Z","iopub.status.idle":"2024-03-16T03:29:53.086125Z","shell.execute_reply.started":"2024-03-16T03:29:53.073858Z","shell.execute_reply":"2024-03-16T03:29:53.084523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==1]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.088109Z","iopub.execute_input":"2024-03-16T03:29:53.088767Z","iopub.status.idle":"2024-03-16T03:29:53.105468Z","shell.execute_reply.started":"2024-03-16T03:29:53.088728Z","shell.execute_reply":"2024-03-16T03:29:53.103920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==1].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.107212Z","iopub.execute_input":"2024-03-16T03:29:53.108079Z","iopub.status.idle":"2024-03-16T03:29:53.119921Z","shell.execute_reply.started":"2024-03-16T03:29:53.108035Z","shell.execute_reply":"2024-03-16T03:29:53.119130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==0].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.120915Z","iopub.execute_input":"2024-03-16T03:29:53.121236Z","iopub.status.idle":"2024-03-16T03:29:53.134878Z","shell.execute_reply.started":"2024-03-16T03:29:53.121207Z","shell.execute_reply":"2024-03-16T03:29:53.133778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 expired_account_ratio 값의 분포\ncounts_target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['expired_account_ratio'].value_counts().sort_index()\n# 타깃이 1일 때의 expired_account_ratio 값의 분포\ncounts_target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['expired_account_ratio'].value_counts().sort_index()\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.01, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.01, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of expired_account_ratio for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('expired_account_ratio')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.146121Z","iopub.execute_input":"2024-03-16T03:29:53.147081Z","iopub.status.idle":"2024-03-16T03:29:53.544306Z","shell.execute_reply.started":"2024-03-16T03:29:53.147044Z","shell.execute_reply":"2024-03-16T03:29:53.543120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"target0 = train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==0].value_counts()\ntarget1 = train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==1].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.545598Z","iopub.execute_input":"2024-03-16T03:29:53.545913Z","iopub.status.idle":"2024-03-16T03:29:53.557860Z","shell.execute_reply.started":"2024-03-16T03:29:53.545884Z","shell.execute_reply":"2024-03-16T03:29:53.556324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target1.index","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.559910Z","iopub.execute_input":"2024-03-16T03:29:53.560407Z","iopub.status.idle":"2024-03-16T03:29:53.569920Z","shell.execute_reply.started":"2024-03-16T03:29:53.560365Z","shell.execute_reply":"2024-03-16T03:29:53.568410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target0[target0.index.isin(target1.index)]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.571822Z","iopub.execute_input":"2024-03-16T03:29:53.572252Z","iopub.status.idle":"2024-03-16T03:29:53.585240Z","shell.execute_reply.started":"2024-03-16T03:29:53.572204Z","shell.execute_reply":"2024-03-16T03:29:53.584196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\ntarget0 = train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==0].value_counts()\ntarget1 = train_base_deposit_1['expired_account_ratio'][train_base_deposit_1['target']==1].value_counts()\n\n# 타깃이 0일 때의 expired_account_ratio 값의 분포\ncounts_target_0 = target0[target0.index.isin(target1.index)]\n# 타깃이 1일 때의 expired_account_ratio 값의 분포\ncounts_target_1 = target1\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.01, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.01, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of expired_account_ratio for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('expired_account_ratio')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.586320Z","iopub.execute_input":"2024-03-16T03:29:53.586814Z","iopub.status.idle":"2024-03-16T03:29:53.913636Z","shell.execute_reply.started":"2024-03-16T03:29:53.586778Z","shell.execute_reply":"2024-03-16T03:29:53.912400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{"execution":{"iopub.status.busy":"2024-03-11T04:09:32.905977Z","iopub.execute_input":"2024-03-11T04:09:32.906470Z","iopub.status.idle":"2024-03-11T04:09:32.914589Z","shell.execute_reply.started":"2024-03-11T04:09:32.906434Z","shell.execute_reply":"2024-03-11T04:09:32.913118Z"}}},{"cell_type":"markdown","source":"## 계좌 만기일이 있는 계좌의 비율 => x축의 값 => 타깃 1과 관련 없는 비율 제외","metadata":{}},{"cell_type":"code","source":"a= df[df['target']==1]['expired_account_ratio'].unique()\ndf2=df[df['expired_account_ratio'].isin(a)]\ndf2","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.915474Z","iopub.execute_input":"2024-03-16T03:29:53.915895Z","iopub.status.idle":"2024-03-16T03:29:53.951648Z","shell.execute_reply.started":"2024-03-16T03:29:53.915859Z","shell.execute_reply":"2024-03-16T03:29:53.950128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 타깃이 0일 때의 expired_account_ratio 값의 분포\ncounts_target_0 = df2[df2['target'] == 0]['expired_account_ratio'].value_counts().sort_index()\n# 타깃이 1일 때의 expired_account_ratio 값의 분포\ncounts_target_1 = df2[df2['target'] == 1]['expired_account_ratio'].value_counts().sort_index()\n\n# 로그 변환\ncounts_target_0_log = np.log(counts_target_0)\ncounts_target_1_log = np.log(counts_target_1)\n\n# 막대 그래프 그리기\nplt.figure(figsize=(10, 6))\n\n# 타깃이 0일 때의 그래프 그리기\nplt.bar(counts_target_0.index , counts_target_0_log, width=0.01, color='skyblue', label='Target 0')\n# 타깃이 1일 때의 그래프 그리기\nplt.bar(counts_target_1.index , counts_target_1_log, width=0.01, color='orange', label='Target 1')\n\n# 그래프 제목 설정\nplt.title('Counts of expired_account_ratio for Target 0 and Target 1 (log scale)')\n\n# x축 레이블 설정\nplt.xlabel('expired_account_ratio')\n\n# y축 레이블 설정\nplt.ylabel('Log Count')\n\n# 범례 표시\nplt.legend()\n\n# 그래프 표시\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:53.953874Z","iopub.execute_input":"2024-03-16T03:29:53.954394Z","iopub.status.idle":"2024-03-16T03:29:54.346790Z","shell.execute_reply.started":"2024-03-16T03:29:53.954350Z","shell.execute_reply":"2024-03-16T03:29:54.345581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"markdown","source":"# total_amount","metadata":{}},{"cell_type":"code","source":"train_base_deposit_1","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.348389Z","iopub.execute_input":"2024-03-16T03:29:54.348741Z","iopub.status.idle":"2024-03-16T03:29:54.366972Z","shell.execute_reply.started":"2024-03-16T03:29:54.348710Z","shell.execute_reply":"2024-03-16T03:29:54.365679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"duplicated_cases = train_base_deposit_1[train_base_deposit_1.duplicated(subset=['case_id'])]\nduplicated_cases","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.369180Z","iopub.execute_input":"2024-03-16T03:29:54.369620Z","iopub.status.idle":"2024-03-16T03:29:54.390990Z","shell.execute_reply.started":"2024-03-16T03:29:54.369579Z","shell.execute_reply":"2024-03-16T03:29:54.389848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.393994Z","iopub.execute_input":"2024-03-16T03:29:54.394405Z","iopub.status.idle":"2024-03-16T03:29:54.424289Z","shell.execute_reply.started":"2024-03-16T03:29:54.394372Z","shell.execute_reply":"2024-03-16T03:29:54.422290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==1]['total_amount']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.426275Z","iopub.execute_input":"2024-03-16T03:29:54.426782Z","iopub.status.idle":"2024-03-16T03:29:54.440675Z","shell.execute_reply.started":"2024-03-16T03:29:54.426738Z","shell.execute_reply":"2024-03-16T03:29:54.439286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['total_amount']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.442677Z","iopub.execute_input":"2024-03-16T03:29:54.443497Z","iopub.status.idle":"2024-03-16T03:29:54.463746Z","shell.execute_reply.started":"2024-03-16T03:29:54.443453Z","shell.execute_reply":"2024-03-16T03:29:54.462262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==1]['total_amount'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.465817Z","iopub.execute_input":"2024-03-16T03:29:54.466324Z","iopub.status.idle":"2024-03-16T03:29:54.481886Z","shell.execute_reply.started":"2024-03-16T03:29:54.466283Z","shell.execute_reply":"2024-03-16T03:29:54.480719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['total_amount'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.483312Z","iopub.execute_input":"2024-03-16T03:29:54.483638Z","iopub.status.idle":"2024-03-16T03:29:54.509257Z","shell.execute_reply.started":"2024-03-16T03:29:54.483610Z","shell.execute_reply":"2024-03-16T03:29:54.507827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_deposit_1[train_base_deposit_1['target']==0]['total_amount'].value_counts().sort_index().head(30)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.510790Z","iopub.execute_input":"2024-03-16T03:29:54.511991Z","iopub.status.idle":"2024-03-16T03:29:54.542168Z","shell.execute_reply.started":"2024-03-16T03:29:54.511930Z","shell.execute_reply":"2024-03-16T03:29:54.540650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['total_amount']\ntarget_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['total_amount']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.543879Z","iopub.execute_input":"2024-03-16T03:29:54.544226Z","iopub.status.idle":"2024-03-16T03:29:54.559405Z","shell.execute_reply.started":"2024-03-16T03:29:54.544197Z","shell.execute_reply":"2024-03-16T03:29:54.557911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.561426Z","iopub.execute_input":"2024-03-16T03:29:54.561764Z","iopub.status.idle":"2024-03-16T03:29:54.570981Z","shell.execute_reply.started":"2024-03-16T03:29:54.561735Z","shell.execute_reply":"2024-03-16T03:29:54.570030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.572112Z","iopub.execute_input":"2024-03-16T03:29:54.572447Z","iopub.status.idle":"2024-03-16T03:29:54.588476Z","shell.execute_reply.started":"2024-03-16T03:29:54.572417Z","shell.execute_reply":"2024-03-16T03:29:54.587353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 상자 그림(Box plot)\nplt.figure(figsize=(10, 6))\nplt.boxplot([target_0, target_1], labels=['Target 0', 'Target 1'])\nplt.title('Box plot of Total Amount by Target')\nplt.xlabel('Target')\nplt.ylabel('Total Amount')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.590297Z","iopub.execute_input":"2024-03-16T03:29:54.590719Z","iopub.status.idle":"2024-03-16T03:29:54.921644Z","shell.execute_reply.started":"2024-03-16T03:29:54.590675Z","shell.execute_reply":"2024-03-16T03:29:54.920137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 대출 상환 여부에 따라 데이터 분리\ntarget_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['total_amount']\ntarget_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['total_amount']\n\n# 대출 상환 여부가 0인 경우의 예금 총 금액의 히스토그램 시각화\nplt.figure(figsize=(10, 6))\nplt.hist(target_0, bins=50, color='blue', alpha=0.7)\nplt.title('Histogram of Total Amount for Target 0')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.show()\n\n# 대출 상환 여부가 1인 경우의 예금 총 금액의 히스토그램 시각화\nplt.figure(figsize=(10, 6))\nplt.hist(target_1, bins=50, color='red', alpha=0.7)\nplt.title('Histogram of Total Amount for Target 1')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:54.923965Z","iopub.execute_input":"2024-03-16T03:29:54.924396Z","iopub.status.idle":"2024-03-16T03:29:55.751786Z","shell.execute_reply.started":"2024-03-16T03:29:54.924360Z","shell.execute_reply":"2024-03-16T03:29:55.750205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0 = train_base_deposit_1[train_base_deposit_1['target']==0]['total_amount']\ntarget_1 = train_base_deposit_1[train_base_deposit_1['target']==1]['total_amount']\n\nnp.percentile(target_0, np.arange(0, 101, 25))\nnp.percentile(target_1, np.arange(0, 101, 25))\n","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.753655Z","iopub.execute_input":"2024-03-16T03:29:55.754093Z","iopub.status.idle":"2024-03-16T03:29:55.780671Z","shell.execute_reply.started":"2024-03-16T03:29:55.754059Z","shell.execute_reply":"2024-03-16T03:29:55.779288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.percentile(target_1, np.arange(0, 101, 25))","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.782459Z","iopub.execute_input":"2024-03-16T03:29:55.783369Z","iopub.status.idle":"2024-03-16T03:29:55.794869Z","shell.execute_reply.started":"2024-03-16T03:29:55.783324Z","shell.execute_reply":"2024-03-16T03:29:55.793241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.arange(0, 101, 25)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.796822Z","iopub.execute_input":"2024-03-16T03:29:55.797323Z","iopub.status.idle":"2024-03-16T03:29:55.810704Z","shell.execute_reply.started":"2024-03-16T03:29:55.797287Z","shell.execute_reply":"2024-03-16T03:29:55.809036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1.quantile(q=[0.25,0.5])","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.812116Z","iopub.execute_input":"2024-03-16T03:29:55.812480Z","iopub.status.idle":"2024-03-16T03:29:55.829926Z","shell.execute_reply.started":"2024-03-16T03:29:55.812451Z","shell.execute_reply":"2024-03-16T03:29:55.828244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.percentile(target_0, np.arange(0, 101, 25))","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.832042Z","iopub.execute_input":"2024-03-16T03:29:55.832513Z","iopub.status.idle":"2024-03-16T03:29:55.847670Z","shell.execute_reply.started":"2024-03-16T03:29:55.832452Z","shell.execute_reply":"2024-03-16T03:29:55.845841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.percentile(target_1, np.arange(0, 101, 25))","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.849168Z","iopub.execute_input":"2024-03-16T03:29:55.849789Z","iopub.status.idle":"2024-03-16T03:29:55.860494Z","shell.execute_reply.started":"2024-03-16T03:29:55.849741Z","shell.execute_reply":"2024-03-16T03:29:55.858882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# 대출 상환 여부에 따라 데이터 분리\ntarget_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['total_amount']\ntarget_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['total_amount']\n\n# 각 대출 상환 여부(TARGET) 그룹에서의 예금 총 금액의 분위수 계산\nquantiles_0 = np.percentile(target_0, np.arange(0, 101, 25))\nquantiles_1 = np.percentile(target_1, np.arange(0, 101, 25))\n\n# 분위수별로 예금 총 금액의 분포 시각화\nplt.figure(figsize=(10, 6))\nplt.plot(np.arange(0, 101, 25), quantiles_0, marker='o', linestyle='-', color='blue', label='Target 0')\nplt.plot(np.arange(0, 101, 25), quantiles_1, marker='o', linestyle='-', color='red', label='Target 1')\nplt.title('Quantiles of Total Amount by Target')\nplt.xlabel('Percentile')\nplt.ylabel('Total Amount')\nplt.legend()\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:55.861926Z","iopub.execute_input":"2024-03-16T03:29:55.862409Z","iopub.status.idle":"2024-03-16T03:29:56.272613Z","shell.execute_reply.started":"2024-03-16T03:29:55.862360Z","shell.execute_reply":"2024-03-16T03:29:56.271088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.set_printoptions(suppress=True)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.274296Z","iopub.execute_input":"2024-03-16T03:29:56.274732Z","iopub.status.idle":"2024-03-16T03:29:56.280901Z","shell.execute_reply.started":"2024-03-16T03:29:56.274695Z","shell.execute_reply":"2024-03-16T03:29:56.279396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0 = train_base_deposit_1[train_base_deposit_1['target'] == 0]['total_amount'].sort_values().reset_index(drop=True)\ntarget_0","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.283210Z","iopub.execute_input":"2024-03-16T03:29:56.283731Z","iopub.status.idle":"2024-03-16T03:29:56.322429Z","shell.execute_reply.started":"2024-03-16T03:29:56.283692Z","shell.execute_reply":"2024-03-16T03:29:56.321023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 음수 값 개수 확인\nnegative_values_count = len(target_0[target_0 < 0])\nprint(\"음수 값 개수:\", negative_values_count)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.324227Z","iopub.execute_input":"2024-03-16T03:29:56.325084Z","iopub.status.idle":"2024-03-16T03:29:56.332539Z","shell.execute_reply.started":"2024-03-16T03:29:56.325037Z","shell.execute_reply":"2024-03-16T03:29:56.331448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0= target_0[target_0 >= 0]\ntarget_0","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.334616Z","iopub.execute_input":"2024-03-16T03:29:56.335072Z","iopub.status.idle":"2024-03-16T03:29:56.351649Z","shell.execute_reply.started":"2024-03-16T03:29:56.335036Z","shell.execute_reply":"2024-03-16T03:29:56.350046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1 = train_base_deposit_1[train_base_deposit_1['target'] == 1]['total_amount'].sort_values().reset_index(drop=True)\ntarget_1","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.353586Z","iopub.execute_input":"2024-03-16T03:29:56.354006Z","iopub.status.idle":"2024-03-16T03:29:56.367916Z","shell.execute_reply.started":"2024-03-16T03:29:56.353971Z","shell.execute_reply":"2024-03-16T03:29:56.366680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 대출을 갚는 고객과 갚지 않는 고객의 '계좌 총 금액' 통계적 특성 계산\nmean_total_amount_target_0 = target_0.mean()\nmedian_total_amount_target_0 = target_0.median()\nstd_total_amount_target_0 = target_0.std()\n\nmean_total_amount_target_1 = target_1.mean()\nmedian_total_amount_target_1 = target_1.median()\nstd_total_amount_target_1 = target_1.std()\n\n# 결과 출력\nprint(\"대출을 갚는 고객의 '계좌 총 금액' 통계적 특성:\")\nprint(\"평균:\", mean_total_amount_target_0)\nprint(\"중앙값:\", median_total_amount_target_0)\nprint(\"표준편차:\", std_total_amount_target_0)\nprint(\"\\n\")\n\nprint(\"대출을 갚지 않는 고객의 '계좌 총 금액' 통계적 특성:\")\nprint(\"평균:\", mean_total_amount_target_1)\nprint(\"중앙값:\", median_total_amount_target_1)\nprint(\"표준편차:\", std_total_amount_target_1)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.369360Z","iopub.execute_input":"2024-03-16T03:29:56.370925Z","iopub.status.idle":"2024-03-16T03:29:56.384770Z","shell.execute_reply.started":"2024-03-16T03:29:56.370806Z","shell.execute_reply":"2024-03-16T03:29:56.383741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\n# 시각화\nplt.figure(figsize=(10, 6))\n\nsns.boxplot(x='target', y='total_amount', data=train_base_deposit_1)\nplt.title('Total Amount by Target')\nplt.xlabel('Target')\nplt.ylabel('Total Amount')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.386252Z","iopub.execute_input":"2024-03-16T03:29:56.387319Z","iopub.status.idle":"2024-03-16T03:29:56.749311Z","shell.execute_reply.started":"2024-03-16T03:29:56.387270Z","shell.execute_reply":"2024-03-16T03:29:56.748346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['total_amount']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.750572Z","iopub.execute_input":"2024-03-16T03:29:56.751438Z","iopub.status.idle":"2024-03-16T03:29:56.761434Z","shell.execute_reply.started":"2024-03-16T03:29:56.751402Z","shell.execute_reply":"2024-03-16T03:29:56.759852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_amount = train_base_deposit_1['total_amount'][train_base_deposit_1['total_amount'] >= 0] ;total_amount","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.763371Z","iopub.execute_input":"2024-03-16T03:29:56.764374Z","iopub.status.idle":"2024-03-16T03:29:56.778241Z","shell.execute_reply.started":"2024-03-16T03:29:56.764312Z","shell.execute_reply":"2024-03-16T03:29:56.776569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\n# 전체 데이터를 4분위로 나누기\nquantiles = np.percentile(total_amount, [25, 50, 75])  # 25%, 50%, 75% 분위수 계산\n\n\n# 각 분위에 속한 데이터를 나누고 대출을 갚는 고객과 갚지 않는 고객으로 나누기\ntarget_0_by_quantile = []\ntarget_1_by_quantile = []\n\nfor i in range(len(quantiles) + 1):\n    if i == 0: \n        subset = total_amount[total_amount <= quantiles[i]]\n    elif i == len(quantiles):\n        subset = total_amount[total_amount > quantiles[i - 1]]\n    else:\n        subset = total_amount[(total_amount > quantiles[i - 1]) & (total_amount <= quantiles[i])]\n        \n    target_0_by_quantile.append(subset[train_base_deposit_1['target'] == 0])\n    target_1_by_quantile.append(subset[train_base_deposit_1['target'] == 1])\n    \n# 각 분위에 대해 대출을 갚는 고객과 갚지 않는 고객 간의 차이 계산\nfor i in range(len(quantiles) + 1):\n    mean_target_0 = target_0_by_quantile[i].mean()\n    mean_target_1 = target_1_by_quantile[i].mean()\n    median_target_0 = target_0_by_quantile[i].median()\n    median_target_1 = target_1_by_quantile[i].median()\n    std_target_0 = target_0_by_quantile[i].std()\n    std_target_1 = target_1_by_quantile[i].std()\n    \n    print(f\"분위 {i+1}:\")\n    print(f\"대출을 갚는 고객의 '계좌 총 금액' 통계적 특성:\")\n    print(f\"평균: {mean_target_0}, 중앙값: {median_target_0}, 표준편차: {std_target_0}\")\n    print()\n    print(f\"대출을 갚지 않는 고객의 '계좌 총 금액' 통계적 특성:\")\n    print(f\"평균: {mean_target_1}, 중앙값: {median_target_1}, 표준편차: {std_target_1}\")\n    print()\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.780361Z","iopub.execute_input":"2024-03-16T03:29:56.781423Z","iopub.status.idle":"2024-03-16T03:29:56.830269Z","shell.execute_reply.started":"2024-03-16T03:29:56.781379Z","shell.execute_reply":"2024-03-16T03:29:56.828759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[0]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.832110Z","iopub.execute_input":"2024-03-16T03:29:56.832498Z","iopub.status.idle":"2024-03-16T03:29:56.843300Z","shell.execute_reply.started":"2024-03-16T03:29:56.832466Z","shell.execute_reply":"2024-03-16T03:29:56.841746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[1]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.845147Z","iopub.execute_input":"2024-03-16T03:29:56.845581Z","iopub.status.idle":"2024-03-16T03:29:56.856521Z","shell.execute_reply.started":"2024-03-16T03:29:56.845525Z","shell.execute_reply":"2024-03-16T03:29:56.855012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[2]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.858342Z","iopub.execute_input":"2024-03-16T03:29:56.858844Z","iopub.status.idle":"2024-03-16T03:29:56.873445Z","shell.execute_reply.started":"2024-03-16T03:29:56.858803Z","shell.execute_reply":"2024-03-16T03:29:56.870912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[3]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.877623Z","iopub.execute_input":"2024-03-16T03:29:56.877971Z","iopub.status.idle":"2024-03-16T03:29:56.887876Z","shell.execute_reply.started":"2024-03-16T03:29:56.877928Z","shell.execute_reply":"2024-03-16T03:29:56.886337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['total_amount'] > target_1_by_quantile[3].max()]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.890063Z","iopub.execute_input":"2024-03-16T03:29:56.890486Z","iopub.status.idle":"2024-03-16T03:29:56.912524Z","shell.execute_reply.started":"2024-03-16T03:29:56.890452Z","shell.execute_reply":"2024-03-16T03:29:56.911350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['total_amount'] <= target_1_by_quantile[3].max()]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.914111Z","iopub.execute_input":"2024-03-16T03:29:56.914987Z","iopub.status.idle":"2024-03-16T03:29:56.948571Z","shell.execute_reply.started":"2024-03-16T03:29:56.914918Z","shell.execute_reply":"2024-03-16T03:29:56.946972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기\nplt.figure(figsize=(8, 6))\nplt.hist(target_0_by_quantile[3], bins=30, color='red', alpha=0.7)\nplt.title('Distribution of Total Amount for Target 0 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:56.950377Z","iopub.execute_input":"2024-03-16T03:29:56.951249Z","iopub.status.idle":"2024-03-16T03:29:57.333851Z","shell.execute_reply.started":"2024-03-16T03:29:56.951212Z","shell.execute_reply":"2024-03-16T03:29:57.332479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(8, 6))\nplt.hist(target_0_by_quantile[3], bins=30, color='red', alpha=0.7)\nplt.title('Distribution of Total Amount for Target 0 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency (log scale)')\nplt.yscale('log')  # y축 스케일을 로그로 설정\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:57.335443Z","iopub.execute_input":"2024-03-16T03:29:57.335815Z","iopub.status.idle":"2024-03-16T03:29:58.492322Z","shell.execute_reply.started":"2024-03-16T03:29:57.335783Z","shell.execute_reply":"2024-03-16T03:29:58.491041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_range, y_range = plt.xlim(), plt.ylim()\nprint(x_range, y_range)","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:58.494001Z","iopub.execute_input":"2024-03-16T03:29:58.495273Z","iopub.status.idle":"2024-03-16T03:29:58.746288Z","shell.execute_reply.started":"2024-03-16T03:29:58.495218Z","shell.execute_reply":"2024-03-16T03:29:58.745134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(10, 6))\n\n# 두 데이터셋의 범위 구하기\nmin_value = 700000#min(target_1_by_quantile[3]); min_value\nmax_value = max(target_0_by_quantile[3]); max_value\n\n# target_0_by_quantile[3] 히스토그램 그리기\nplt.subplot(1, 2, 1)\nplt.hist(target_0_by_quantile[3], bins=30, color='blue', alpha=0.7, range=(min_value, max_value))\nplt.title('Distribution of Total Amount for Target 0 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.grid(True)\n\n# target_1_by_quantile[3] 히스토그램 그리기\nplt.subplot(1, 2, 2)\nplt.hist(target_1_by_quantile[3], bins=30, color='red', alpha=0.7,range=(min_value, max_value))\nplt.title('Distribution of Total Amount for Target 1 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.grid(True)\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:58.748043Z","iopub.execute_input":"2024-03-16T03:29:58.748411Z","iopub.status.idle":"2024-03-16T03:29:59.547595Z","shell.execute_reply.started":"2024-03-16T03:29:58.748380Z","shell.execute_reply":"2024-03-16T03:29:59.546063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기\nplt.figure(figsize=(8, 6))\nplt.hist(target_1_by_quantile[3], bins=30, color='red', alpha=0.7)\nplt.title('Distribution of Total Amount for Target 1 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.549131Z","iopub.execute_input":"2024-03-16T03:29:59.549481Z","iopub.status.idle":"2024-03-16T03:29:59.881776Z","shell.execute_reply.started":"2024-03-16T03:29:59.549451Z","shell.execute_reply":"2024-03-16T03:29:59.880270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0_by_quantile[2].min()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.883291Z","iopub.execute_input":"2024-03-16T03:29:59.883639Z","iopub.status.idle":"2024-03-16T03:29:59.893447Z","shell.execute_reply.started":"2024-03-16T03:29:59.883609Z","shell.execute_reply":"2024-03-16T03:29:59.891726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0_by_quantile[3].max()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.895436Z","iopub.execute_input":"2024-03-16T03:29:59.895790Z","iopub.status.idle":"2024-03-16T03:29:59.906210Z","shell.execute_reply.started":"2024-03-16T03:29:59.895762Z","shell.execute_reply":"2024-03-16T03:29:59.904512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[3].min()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.907851Z","iopub.execute_input":"2024-03-16T03:29:59.908362Z","iopub.status.idle":"2024-03-16T03:29:59.923705Z","shell.execute_reply.started":"2024-03-16T03:29:59.908325Z","shell.execute_reply":"2024-03-16T03:29:59.922394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_by_quantile[3].max()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.925183Z","iopub.execute_input":"2024-03-16T03:29:59.925573Z","iopub.status.idle":"2024-03-16T03:29:59.937723Z","shell.execute_reply.started":"2024-03-16T03:29:59.925539Z","shell.execute_reply":"2024-03-16T03:29:59.936407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(8, 6))\nplt.hist(target_0_by_quantile[3], bins=30, color='red', alpha=0.7)\nplt.title('Distribution of Total Amount for Target 0 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency (log scale)')\nplt.yscale('log')  # y축 스케일을 로그로 설정\nplt.grid(True)\nplt.show()\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(8, 6))\nplt.hist(target_1_by_quantile[3], bins=30, color='red', alpha=0.7)\nplt.title('Distribution of Total Amount for Target 1 (4th Quantile)')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency (log scale)')\nplt.yscale('log')  # y축 스케일을 로그로 설정\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:29:59.939605Z","iopub.execute_input":"2024-03-16T03:29:59.942342Z","iopub.status.idle":"2024-03-16T03:30:01.580757Z","shell.execute_reply.started":"2024-03-16T03:29:59.942290Z","shell.execute_reply":"2024-03-16T03:30:01.579443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기\nplt.figure(figsize=(10, 6))\n\nfor i in range(len(quantiles) + 1):\n    plt.subplot(2, 2, i+1)\n    plt.hist(target_0_by_quantile[i], bins=30, alpha=0.5, color='blue', label='Repaid')\n    plt.hist(target_1_by_quantile[i], bins=30, alpha=0.5, color='red', label='Not Repaid')\n    plt.title(f'Quantile {i+1}')\n    plt.xlabel('Total Amount')\n    plt.ylabel('Frequency')\n    plt.legend()\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:01.582608Z","iopub.execute_input":"2024-03-16T03:30:01.583020Z","iopub.status.idle":"2024-03-16T03:30:03.575562Z","shell.execute_reply.started":"2024-03-16T03:30:01.582987Z","shell.execute_reply":"2024-03-16T03:30:03.573841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(10, 6))\n\nfor i in range(len(quantiles) + 1):\n    plt.subplot(2, 2, i+1)\n    plt.hist(target_0_by_quantile[i], bins=30, alpha=0.5, color='blue', label='Repaid')\n    plt.hist(target_1_by_quantile[i], bins=30, alpha=0.5, color='red', label='Not Repaid')\n    plt.title(f'Quantile {i+1}')\n    plt.xlabel('Total Amount')\n    plt.ylabel('Frequency (log scale)')\n    plt.yscale('log')  # y축 스케일을 로그로 설정\n    plt.legend()\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:03.589838Z","iopub.execute_input":"2024-03-16T03:30:03.590379Z","iopub.status.idle":"2024-03-16T03:30:07.418405Z","shell.execute_reply.started":"2024-03-16T03:30:03.590227Z","shell.execute_reply":"2024-03-16T03:30:07.416869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = train_base_deposit_1\ndf[df['total_amount'] >= quantiles[2]]","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.419863Z","iopub.execute_input":"2024-03-16T03:30:07.420271Z","iopub.status.idle":"2024-03-16T03:30:07.445907Z","shell.execute_reply.started":"2024-03-16T03:30:07.420230Z","shell.execute_reply":"2024-03-16T03:30:07.444738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_total_amount_q4 = df[df['total_amount'] >= quantiles[2]]\ndf_total_amount_q4","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.447873Z","iopub.execute_input":"2024-03-16T03:30:07.449239Z","iopub.status.idle":"2024-03-16T03:30:07.472404Z","shell.execute_reply.started":"2024-03-16T03:30:07.449190Z","shell.execute_reply":"2024-03-16T03:30:07.470619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 'target' 별 'total_amount' 데이터 추출\ntarget_0_total_amount_q4 = df_total_amount_q4[df_total_amount_q4['target'] == 0]['total_amount']\ntarget_1_total_amount_q4 = df_total_amount_q4[df_total_amount_q4['target'] == 1]['total_amount']","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.474050Z","iopub.execute_input":"2024-03-16T03:30:07.474398Z","iopub.status.idle":"2024-03-16T03:30:07.484412Z","shell.execute_reply.started":"2024-03-16T03:30:07.474369Z","shell.execute_reply":"2024-03-16T03:30:07.482872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0_total_amount_q4","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.485857Z","iopub.execute_input":"2024-03-16T03:30:07.487680Z","iopub.status.idle":"2024-03-16T03:30:07.500550Z","shell.execute_reply.started":"2024-03-16T03:30:07.487638Z","shell.execute_reply":"2024-03-16T03:30:07.499052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_total_amount_q4","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.502236Z","iopub.execute_input":"2024-03-16T03:30:07.503705Z","iopub.status.idle":"2024-03-16T03:30:07.516731Z","shell.execute_reply.started":"2024-03-16T03:30:07.503658Z","shell.execute_reply":"2024-03-16T03:30:07.515111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_0_total_amount_q4.sort_values()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.520033Z","iopub.execute_input":"2024-03-16T03:30:07.520594Z","iopub.status.idle":"2024-03-16T03:30:07.538544Z","shell.execute_reply.started":"2024-03-16T03:30:07.520560Z","shell.execute_reply":"2024-03-16T03:30:07.537397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_total_amount_q4.sort_values()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.539845Z","iopub.execute_input":"2024-03-16T03:30:07.540999Z","iopub.status.idle":"2024-03-16T03:30:07.550659Z","shell.execute_reply.started":"2024-03-16T03:30:07.540929Z","shell.execute_reply":"2024-03-16T03:30:07.549619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(10, 6))\n\nplt.hist(target_0_total_amount_q4, bins=30, alpha=0.5, color='blue', label='Repaid')\nplt.hist(target_1_total_amount_q4, bins=30, alpha=0.5, color='red', label='Not Repaid')\nplt.title(f'Quantile')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency')\nplt.legend()\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:07.552515Z","iopub.execute_input":"2024-03-16T03:30:07.553603Z","iopub.status.idle":"2024-03-16T03:30:08.135012Z","shell.execute_reply.started":"2024-03-16T03:30:07.553568Z","shell.execute_reply":"2024-03-16T03:30:08.133781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# 히스토그램 그리기 (로그 스케일)\nplt.figure(figsize=(10, 6))\n\nplt.hist(target_0_total_amount_q4, bins=30, alpha=0.5, color='blue', label='Repaid')\nplt.hist(target_1_total_amount_q4, bins=30, alpha=0.5, color='red', label='Not Repaid')\nplt.title(f'Quantile')\nplt.xlabel('Total Amount')\nplt.ylabel('Frequency (log scale)')\nplt.yscale('log')  # y축 스케일을 로그로 설정\nplt.legend()\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:08.136520Z","iopub.execute_input":"2024-03-16T03:30:08.136887Z","iopub.status.idle":"2024-03-16T03:30:09.286143Z","shell.execute_reply.started":"2024-03-16T03:30:08.136856Z","shell.execute_reply":"2024-03-16T03:30:09.284465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_1_total_amount_q4.max()","metadata":{"execution":{"iopub.status.busy":"2024-03-16T03:30:09.288189Z","iopub.execute_input":"2024-03-16T03:30:09.289093Z","iopub.status.idle":"2024-03-16T03:30:09.298697Z","shell.execute_reply.started":"2024-03-16T03:30:09.289033Z","shell.execute_reply":"2024-03-16T03:30:09.297339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}