{"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":7602123,"sourceType":"competition"}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import polars as pl\nimport numpy as np\nimport pandas as pd\nimport lightgbm as lgb\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import roc_auc_score \n\nimport polars.selectors as cs\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport missingno as mn\nimport warnings\n\nwarnings.filterwarnings('ignore')\n\ndataPath = \"/kaggle/input/home-credit-credit-risk-model-stability/\"","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:57:54.831053Z","iopub.execute_input":"2024-02-23T01:57:54.832434Z","iopub.status.idle":"2024-02-23T01:57:57.155886Z","shell.execute_reply.started":"2024-02-23T01:57:54.832349Z","shell.execute_reply":"2024-02-23T01:57:57.154677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_table_dtypes(df: pl.DataFrame) -> pl.DataFrame:\n    # implement here all desired dtypes for tables\n    # the following is just an example\n    for col in df.columns:\n        # last letter of column name will help you determine the type\n        if col[-1] in (\"P\", \"A\"):\n            df = df.with_columns(pl.col(col).cast(pl.Float64).alias(col))\n    return df\n","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:57:57.157636Z","iopub.execute_input":"2024-02-23T01:57:57.157960Z","iopub.status.idle":"2024-02-23T01:57:57.165163Z","shell.execute_reply.started":"2024-02-23T01:57:57.157933Z","shell.execute_reply":"2024-02-23T01:57:57.163445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_def = pl.read_csv(dataPath + \"feature_definitions.csv\")\n\ndef get_feature_definitions(columns):\n    return pl.DataFrame({'Variable': columns}).join(\n        feature_def,\n        on = 'Variable',\n        how = 'left',\n    )","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:57:57.167150Z","iopub.execute_input":"2024-02-23T01:57:57.167550Z","iopub.status.idle":"2024-02-23T01:57:57.181649Z","shell.execute_reply.started":"2024-02-23T01:57:57.167514Z","shell.execute_reply":"2024-02-23T01:57:57.180841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# basetable\ntrain_basetable = pl.read_csv(dataPath + \"csv_files/train/train_base.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:57:57.184615Z","iopub.execute_input":"2024-02-23T01:57:57.185347Z","iopub.status.idle":"2024-02-23T01:57:57.416164Z","shell.execute_reply.started":"2024-02-23T01:57:57.185304Z","shell.execute_reply":"2024-02-23T01:57:57.415226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# static_0, static_cb_0\ntrain_static = pl.concat(\n    [\n        pl.read_csv(dataPath + \"csv_files/train/train_static_0_0.csv\").pipe(set_table_dtypes),\n        pl.read_csv(dataPath + \"csv_files/train/train_static_0_1.csv\").pipe(set_table_dtypes),\n    ],\n    how=\"vertical_relaxed\",\n)\ntrain_static_cb = pl.read_csv(dataPath + \"csv_files/train/train_static_cb_0.csv\").pipe(set_table_dtypes)","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:57:57.417617Z","iopub.execute_input":"2024-02-23T01:57:57.418689Z","iopub.status.idle":"2024-02-23T01:58:07.411856Z","shell.execute_reply.started":"2024-02-23T01:57:57.418654Z","shell.execute_reply":"2024-02-23T01:58:07.410678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## static_0","metadata":{}},{"cell_type":"markdown","source":"### `A`","metadata":{}},{"cell_type":"code","source":"# cols_with_a : A로 끝나는 칼럼들\ncols_with_a = [col for col in train_static.columns if col[-1] == 'A']\n\nwith pl.Config() as cfg:\n    cfg.set_fmt_str_lengths(200)\n    cfg.set_tbl_rows(-1)\n    display(get_feature_definitions(cols_with_a))","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:07.413485Z","iopub.execute_input":"2024-02-23T01:58:07.413970Z","iopub.status.idle":"2024-02-23T01:58:07.430028Z","shell.execute_reply.started":"2024-02-23T01:58:07.413926Z","shell.execute_reply":"2024-02-23T01:58:07.428782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static = train_basetable.join(train_static, on='case_id', how='left').to_pandas()","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:07.431714Z","iopub.execute_input":"2024-02-23T01:58:07.432178Z","iopub.status.idle":"2024-02-23T01:58:11.309476Z","shell.execute_reply.started":"2024-02-23T01:58:07.432139Z","shell.execute_reply":"2024-02-23T01:58:11.308232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# target에 따른 분포나 값을 보고자 하기 때문에 target 칼럼을 선택\n# A로 끝나는 칼럼들에 대해서 보고자 하기 때문에 cols_with_a\n\ndf_train_static_A = df_train_static[['target'] + cols_with_a]\ndf_train_static_A.head()","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:11.311035Z","iopub.execute_input":"2024-02-23T01:58:11.311427Z","iopub.status.idle":"2024-02-23T01:58:11.474155Z","shell.execute_reply.started":"2024-02-23T01:58:11.311386Z","shell.execute_reply":"2024-02-23T01:58:11.472855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# null_table_a : 각 칼럼들에 대해서 결측치의 비율을 나타냄\nnull_table_a = df_train_static_A.isnull().mean() * 100\n\nfor column, value in null_table_a.items():\n    print(f\"{column:35} {value:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:11.475866Z","iopub.execute_input":"2024-02-23T01:58:11.476223Z","iopub.status.idle":"2024-02-23T01:58:11.561854Z","shell.execute_reply.started":"2024-02-23T01:58:11.476193Z","shell.execute_reply":"2024-02-23T01:58:11.560675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 각 feature와 target 간의 상관계수를 히트맵으로 표현\nplt.figure(figsize=(14, 14))\ncorr = df_train_static_A.corr()\nsns.heatmap(corr, vmin=-1, vmax=1, annot=True, cmap='coolwarm', annot_kws={'size': 6})\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:11.566203Z","iopub.execute_input":"2024-02-23T01:58:11.566562Z","iopub.status.idle":"2024-02-23T01:58:18.154536Z","shell.execute_reply.started":"2024-02-23T01:58:11.566532Z","shell.execute_reply":"2024-02-23T01:58:18.153656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in df_train_static_A.columns[1:]:  \n    plt.figure(figsize=(14, 6)) \n    sns.kdeplot(data=df_train_static_A[df_train_static_A['target'] == 0], x=col, shade=True, label='Target 0')\n    sns.kdeplot(data=df_train_static_A[df_train_static_A['target'] == 1], x=col, shade=True, label='Target 1')\n    plt.title(f\"KDE of {col} by Target Value\")  \n    plt.legend() \n    plt.show()  \n","metadata":{"execution":{"iopub.status.busy":"2024-02-23T01:58:18.155510Z","iopub.execute_input":"2024-02-23T01:58:18.155878Z","iopub.status.idle":"2024-02-23T02:00:45.362883Z","shell.execute_reply.started":"2024-02-23T01:58:18.155850Z","shell.execute_reply":"2024-02-23T02:00:45.361532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static_A.groupby('target').std()","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:45.364004Z","iopub.execute_input":"2024-02-23T02:00:45.364475Z","iopub.status.idle":"2024-02-23T02:00:45.839060Z","shell.execute_reply.started":"2024-02-23T02:00:45.364438Z","shell.execute_reply":"2024-02-23T02:00:45.837909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### `D`","metadata":{}},{"cell_type":"markdown","source":"`date_decision` - This refers to the date when a decision was made regarding the approval of the loan.","metadata":{}},{"cell_type":"code","source":"# cols_with_d : D로 끝나는 칼럼들\ncols_with_d = [col for col in train_static.columns if col[-1] == 'D']\n\nwith pl.Config() as cfg:\n    cfg.set_fmt_str_lengths(200)\n    cfg.set_tbl_rows(-1)\n    display(get_feature_definitions(cols_with_d))","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:45.840830Z","iopub.execute_input":"2024-02-23T02:00:45.841534Z","iopub.status.idle":"2024-02-23T02:00:45.853517Z","shell.execute_reply.started":"2024-02-23T02:00:45.841492Z","shell.execute_reply":"2024-02-23T02:00:45.852566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static_D = df_train_static[['case_id', 'target', 'date_decision'] + cols_with_d]\ndf_train_static_D[df_train_static_D.target == 1]","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:45.855389Z","iopub.execute_input":"2024-02-23T02:00:45.855808Z","iopub.status.idle":"2024-02-23T02:00:46.384635Z","shell.execute_reply.started":"2024-02-23T02:00:45.855764Z","shell.execute_reply":"2024-02-23T02:00:46.383492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static_D[df_train_static_D.target == 0]","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:46.385969Z","iopub.execute_input":"2024-02-23T02:00:46.386315Z","iopub.status.idle":"2024-02-23T02:00:46.853079Z","shell.execute_reply.started":"2024-02-23T02:00:46.386286Z","shell.execute_reply":"2024-02-23T02:00:46.851835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# null_table_d : 각 칼럼들에 대해서 결측치의 비율을 나타냄\nnull_table_d = df_train_static_D.isnull().mean() * 100\n\nfor column, value in null_table_d.items():\n    print(f\"{column:35} {value:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:46.854406Z","iopub.execute_input":"2024-02-23T02:00:46.854741Z","iopub.status.idle":"2024-02-23T02:00:48.239185Z","shell.execute_reply.started":"2024-02-23T02:00:46.854714Z","shell.execute_reply":"2024-02-23T02:00:48.237855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df_train_static_D[df_train_static_D['lastapprdate_640D'].notnull() & df_train_static_D['lastrejectdate_50D'].notnull()]\ndf[['case_id', 'target', 'date_decision', 'lastapprdate_640D', 'lastrejectdate_50D']][df['target'] == 1]","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:48.240547Z","iopub.execute_input":"2024-02-23T02:00:48.240915Z","iopub.status.idle":"2024-02-23T02:00:48.717843Z","shell.execute_reply.started":"2024-02-23T02:00:48.240886Z","shell.execute_reply":"2024-02-23T02:00:48.716627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"`datelastinstal40dpd`\n- 40일 이상 연체된 할부금의 마지막 지급일로부터 대출 관련 결정이 내려진 날까지의 경과일이 채무 불이행 여부에 영향을 줄까?","metadata":{}},{"cell_type":"code","source":"# df_datelastinstal40dpd : 40일 이상 연체된 마지막 할부 날짜와 target 간의 연관성이 있는지 확인 \n\n# 40일 이상 연체된 마지막 할부 날짜에 대한 기록이 없는 경우는 drop\ndf_datelastinstal40dpd = df_train_static_D[['case_id', 'target', 'date_decision' ,'datelastinstal40dpd_247D']].dropna()\n\n# 날짜 칼럼의 데이터 타입을 datetime으로 변환\ndf_datelastinstal40dpd['date_decision'] = pd.to_datetime(df_datelastinstal40dpd['date_decision'])\ndf_datelastinstal40dpd['datelastinstal40dpd_247D'] = pd.to_datetime(df_datelastinstal40dpd['datelastinstal40dpd_247D'])\n\n# date_decision과 datelastinstal40dpd_247D 사이의 날짜 차이를 계산\ndf_datelastinstal40dpd['date_difference'] = (df_datelastinstal40dpd['date_decision'] - df_datelastinstal40dpd['datelastinstal40dpd_247D']).dt.days\n\ndf_datelastinstal40dpd","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:48.719360Z","iopub.execute_input":"2024-02-23T02:00:48.720688Z","iopub.status.idle":"2024-02-23T02:00:49.089366Z","shell.execute_reply.started":"2024-02-23T02:00:48.720646Z","shell.execute_reply":"2024-02-23T02:00:49.088108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(14, 6)) \nsns.kdeplot(data=df_datelastinstal40dpd[df_datelastinstal40dpd['target'] == 0], x='date_difference', shade=True, label='Target 0')\nsns.kdeplot(data=df_datelastinstal40dpd[df_datelastinstal40dpd['target'] == 1], x='date_difference', shade=True, label='Target 1')\nplt.legend() \nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:49.091335Z","iopub.execute_input":"2024-02-23T02:00:49.091787Z","iopub.status.idle":"2024-02-23T02:00:49.940386Z","shell.execute_reply.started":"2024-02-23T02:00:49.091747Z","shell.execute_reply":"2024-02-23T02:00:49.939042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"`lastdelinqdate_224D`\n- 마지막으로 지급한 날짜가 대출 관련 결정이 내려진 날과 가까울수록 지불 능력이 있어 채무 불이행이 적지 않을까?","metadata":{}},{"cell_type":"code","source":"# 마지막 연체 발생 날짜에 대한 기록이 없는 경우는 drop\ndf_lastdelinqdate = df_train_static_D[['case_id', 'target', 'date_decision' ,'lastdelinqdate_224D']].dropna()\n\n# 날짜 칼럼의 데이터 타입을 datetime으로 변환\ndf_lastdelinqdate['date_decision'] = pd.to_datetime(df_lastdelinqdate['date_decision'])\ndf_lastdelinqdate['lastdelinqdate_224D'] = pd.to_datetime(df_lastdelinqdate['lastdelinqdate_224D'])\n\n# date_decision과 datelastinstal40dpd_247D 사이의 날짜 차이를 계산\ndf_lastdelinqdate['date_difference'] = (df_lastdelinqdate['date_decision'] - df_lastdelinqdate['lastdelinqdate_224D']).dt.days\n\ndf_lastdelinqdate","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:49.942068Z","iopub.execute_input":"2024-02-23T02:00:49.942431Z","iopub.status.idle":"2024-02-23T02:00:50.565229Z","shell.execute_reply.started":"2024-02-23T02:00:49.942400Z","shell.execute_reply":"2024-02-23T02:00:50.564065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(14, 6)) \nsns.kdeplot(data=df_lastdelinqdate[df_lastdelinqdate['target'] == 0], x='date_difference', shade=True, label='Target 0')\nsns.kdeplot(data=df_lastdelinqdate[df_lastdelinqdate['target'] == 1], x='date_difference', shade=True, label='Target 1')\nplt.legend() \nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:50.566379Z","iopub.execute_input":"2024-02-23T02:00:50.566749Z","iopub.status.idle":"2024-02-23T02:00:53.424802Z","shell.execute_reply.started":"2024-02-23T02:00:50.566721Z","shell.execute_reply":"2024-02-23T02:00:53.423623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in cols_with_d:\n    # 마지막 연체 발생 날짜에 대한 기록이 없는 경우는 drop\n    df = df_train_static_D[['case_id', 'target', 'date_decision' ,col]].dropna()\n\n    # 날짜 칼럼의 데이터 타입을 datetime으로 변환\n    df['date_decision'] = pd.to_datetime(df['date_decision'])\n    df[col] = pd.to_datetime(df[col])\n\n    # date_decision과 datelastinstal40dpd_247D 사이의 날짜 차이를 계산\n    df['date_difference'] = (df['date_decision'] - df[col]).dt.days\n\n    plt.figure(figsize=(14, 6)) \n    sns.kdeplot(data=df[df['target'] == 0], x='date_difference', shade=True, label='Target 0')\n    sns.kdeplot(data=df[df['target'] == 1], x='date_difference', shade=True, label='Target 1')\n    plt.title(f'date_decision - {col}')\n    plt.legend() \n    plt.show() \n    ","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:00:53.426184Z","iopub.execute_input":"2024-02-23T02:00:53.426562Z","iopub.status.idle":"2024-02-23T02:01:48.072900Z","shell.execute_reply.started":"2024-02-23T02:00:53.426532Z","shell.execute_reply":"2024-02-23T02:01:48.071523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### `P`","metadata":{"execution":{"iopub.status.busy":"2024-02-22T06:55:20.448749Z","iopub.execute_input":"2024-02-22T06:55:20.449162Z","iopub.status.idle":"2024-02-22T06:55:20.453977Z","shell.execute_reply.started":"2024-02-22T06:55:20.449132Z","shell.execute_reply":"2024-02-22T06:55:20.452971Z"}}},{"cell_type":"code","source":"# cols_with_p : P로 끝나는 칼럼들\ncols_with_p = [col for col in train_static.columns if col[-1] == 'P']\n\nwith pl.Config() as cfg:\n    cfg.set_fmt_str_lengths(200)\n    cfg.set_tbl_rows(-1)\n    display(get_feature_definitions(cols_with_p))","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:07:40.466679Z","iopub.execute_input":"2024-02-23T02:07:40.467096Z","iopub.status.idle":"2024-02-23T02:07:40.479666Z","shell.execute_reply.started":"2024-02-23T02:07:40.467039Z","shell.execute_reply":"2024-02-23T02:07:40.478311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static_P = df_train_static[['case_id', 'target', 'date_decision'] + cols_with_p]\ndf_train_static_P[df_train_static_P.target == 1]","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:07:40.480813Z","iopub.execute_input":"2024-02-23T02:07:40.481195Z","iopub.status.idle":"2024-02-23T02:07:40.683994Z","shell.execute_reply.started":"2024-02-23T02:07:40.481163Z","shell.execute_reply":"2024-02-23T02:07:40.682786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_static_P[df_train_static_P.target == 0]","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:07:40.686396Z","iopub.execute_input":"2024-02-23T02:07:40.686798Z","iopub.status.idle":"2024-02-23T02:07:41.241866Z","shell.execute_reply.started":"2024-02-23T02:07:40.686768Z","shell.execute_reply":"2024-02-23T02:07:41.240616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# null_table_p : 각 칼럼들에 대해서 결측치의 비율을 나타냄\nnull_table_p = df_train_static_P.isnull().mean() * 100\n\nfor column, value in null_table_p.items():\n    print(f\"{column:35} {value:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:07:41.243448Z","iopub.execute_input":"2024-02-23T02:07:41.243843Z","iopub.status.idle":"2024-02-23T02:07:41.462250Z","shell.execute_reply.started":"2024-02-23T02:07:41.243812Z","shell.execute_reply":"2024-02-23T02:07:41.461003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 로그 변환 전 그래프만 보고 싶은 경우\n\n# for col in cols_with_p:  \n#     plt.figure(figsize=(14, 6))\n#     sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 0], x=col, shade=True, label='Target 0')\n#     sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 1], x=col, shade=True, label='Target 1')\n#     plt.title(f\"KDE of {col} by Target Value\")  \n#     plt.legend() \n#     plt.show()  ","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:08:06.007749Z","iopub.execute_input":"2024-02-23T02:08:06.008143Z","iopub.status.idle":"2024-02-23T02:08:06.014194Z","shell.execute_reply.started":"2024-02-23T02:08:06.008114Z","shell.execute_reply":"2024-02-23T02:08:06.012620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in cols_with_p:\n    # 로그 변환 전후를 나란히 보기 위해 subplots 사용\n    fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(28, 6)) \n\n    # 왼쪽 그래프: 로그 변환 전\n    sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 0], x=col, shade=True, label='Target 0', ax=axs[0])\n    sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 1], x=col, shade=True, label='Target 1', ax=axs[0])\n    axs[0].set_title(f\"KDE of {col} by Target Value (Before Log Transformation)\")\n    axs[0].legend()\n\n    # 로그 변환\n    # 로그 변환 전에 0 또는 음수 값이 있는지 확인하고, 필요하다면 처리\n    df_train_static_P[col] = np.where(df_train_static_P[col] <= 0, np.nan, df_train_static_P[col]) # 음수 또는 0을 NaN으로 대체\n    df_train_static_P[col] = np.log(df_train_static_P[col].dropna()) # NaN 값 제외하고 로그 변환\n\n    # 오른쪽 그래프: 로그 변환 후\n    sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 0], x=col, shade=True, label='Target 0', ax=axs[1])\n    sns.kdeplot(data=df_train_static_P[df_train_static_P['target'] == 1], x=col, shade=True, label='Target 1', ax=axs[1])\n    axs[1].set_title(f\"KDE of {col} by Target Value (After Log Transformation)\")\n    axs[1].legend()\n\n    plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-02-23T02:08:10.493616Z","iopub.execute_input":"2024-02-23T02:08:10.494021Z","iopub.status.idle":"2024-02-23T02:10:49.297225Z","shell.execute_reply.started":"2024-02-23T02:08:10.493993Z","shell.execute_reply":"2024-02-23T02:10:49.295949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}