{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":20604,"databundleVersionId":1357052,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<h1><center>OSIC Pulmonary Fibrosis Progression 대회</center></h1>\n<h1><center>데이터 분석</center></h1>","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n#import os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n#    for filename in filenames:\n#        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-29T05:04:59.592324Z","iopub.execute_input":"2024-01-29T05:04:59.592786Z","iopub.status.idle":"2024-01-29T05:04:59.901228Z","shell.execute_reply.started":"2024-01-29T05:04:59.592753Z","shell.execute_reply":"2024-01-29T05:04:59.899851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. 서론\n## 1.1 폐섬유증이란?\n- 폐섬유증 폐 조직이 손상되고 상처가 생길때 발생하는 질환임\n- 폐가 두꺼워지고 뻣뻣해져서 폐가 정상적인 작동이 힘들게 됨\n\n## 1.2 폐섬유증 OSIC 대회는 무엇을 하는 대회 일까요?\n- 이번 대회에서는 폐 CT 촬영을 통해 환자의 폐 기능 저하 정도를 예측함\n- 호흡하는 공기의 양을 측정하는 스피로미터(spirometer)의 출력을 기준으로 폐 기능을 측정\n- 이미지와 메타 데이터 및 FVC를 ML/DL에 활용할 예정\n\n## 1.3 우리는 무엇을 해야할까요?\n- 폐 CT 촬영을 기반으로 기능 저하 정도를 관측함\n- 각 환자의 최종 세 가지 FVC 측정값과 예측값에 대한 신뢰값 예측","metadata":{"execution":{"iopub.status.busy":"2024-01-27T23:53:57.633909Z","iopub.execute_input":"2024-01-27T23:53:57.634405Z","iopub.status.idle":"2024-01-27T23:53:57.643363Z","shell.execute_reply.started":"2024-01-27T23:53:57.634355Z","shell.execute_reply":"2024-01-27T23:53:57.641991Z"}}},{"cell_type":"markdown","source":"# 2. 주요 라이브러리 설정","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nimport plotly.express as px\nfrom plotly.offline import init_notebook_mode\ninit_notebook_mode()\n\nimport cufflinks\ncufflinks.set_config_file(world_readable=True, theme='pearl', offline=True)\n\nfrom colorama import Fore, Back, Style\n\nsns.set(style='whitegrid')\nplt.style.use('fivethirtyeight')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:03.399191Z","iopub.execute_input":"2024-01-29T05:05:03.400121Z","iopub.status.idle":"2024-01-29T05:05:04.515744Z","shell.execute_reply.started":"2024-01-29T05:05:03.400080Z","shell.execute_reply":"2024-01-29T05:05:04.514613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. 데이터 확인","metadata":{}},{"cell_type":"markdown","source":"## Train.csv 와 Test.csv 확인","metadata":{}},{"cell_type":"code","source":"import os\nos.listdir('/kaggle/input/osic-pulmonary-fibrosis-progression')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:17.580477Z","iopub.execute_input":"2024-01-29T05:05:17.581230Z","iopub.status.idle":"2024-01-29T05:05:17.588383Z","shell.execute_reply.started":"2024-01-29T05:05:17.581198Z","shell.execute_reply":"2024-01-29T05:05:17.587333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/osic-pulmonary-fibrosis-progression/train.csv')\ntest_df = pd.read_csv('/kaggle/input/osic-pulmonary-fibrosis-progression/test.csv')\n\ndisplay(train_df.head(5))\n\nprint(Fore.YELLOW + 'Training data shape: ', Style.RESET_ALL, train_df.shape)\n\nprint()\nprint()\n\ndisplay(test_df.head(5))\n\nprint(Fore.BLUE + 'Test data shape: ', Style.RESET_ALL, test_df.shape)","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:28.756662Z","iopub.execute_input":"2024-01-29T05:05:28.757272Z","iopub.status.idle":"2024-01-29T05:05:28.788425Z","shell.execute_reply.started":"2024-01-29T05:05:28.757242Z","shell.execute_reply":"2024-01-29T05:05:28.786856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. 데이터 분석 - Basic EDA","metadata":{}},{"cell_type":"markdown","source":"## info() 확인","metadata":{}},{"cell_type":"code","source":"print(Fore.YELLOW + '학습 데이터 셋 Train Set !!', Style.RESET_ALL)\nprint()\n\nprint(train_df.info())\n\nprint()\nprint('-------------')\nprint()\n\nprint(Fore.BLUE + '테스트 데이터 셋 Test Set !!', Style.RESET_ALL)\nprint()\nprint(test_df.info())","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:46.410140Z","iopub.execute_input":"2024-01-29T05:05:46.410494Z","iopub.status.idle":"2024-01-29T05:05:46.431353Z","shell.execute_reply.started":"2024-01-29T05:05:46.410464Z","shell.execute_reply":"2024-01-29T05:05:46.430103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 비어있는 값 확인","metadata":{}},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:51.911409Z","iopub.execute_input":"2024-01-29T05:05:51.911785Z","iopub.status.idle":"2024-01-29T05:05:51.920975Z","shell.execute_reply.started":"2024-01-29T05:05:51.911754Z","shell.execute_reply":"2024-01-29T05:05:51.919791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:52.870446Z","iopub.execute_input":"2024-01-29T05:05:52.871033Z","iopub.status.idle":"2024-01-29T05:05:52.879566Z","shell.execute_reply.started":"2024-01-29T05:05:52.870978Z","shell.execute_reply":"2024-01-29T05:05:52.877826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 환자수 확인","metadata":{}},{"cell_type":"code","source":"print(Fore.YELLOW + 'Train - The total patient ids are', Style.RESET_ALL, train_df['Patient'].count(), Fore.YELLOW + 'from those the unique ids are', Style.RESET_ALL, train_df['Patient'].value_counts().shape[0], '.')\nprint(Fore.BLUE + 'Test - The total patient ids are', Style.RESET_ALL, test_df['Patient'].count(), Fore.BLUE + 'from those the unique ids are', Style.RESET_ALL, test_df['Patient'].value_counts().shape[0], '.')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:55.174119Z","iopub.execute_input":"2024-01-29T05:05:55.174447Z","iopub.status.idle":"2024-01-29T05:05:55.184525Z","shell.execute_reply.started":"2024-01-29T05:05:55.174421Z","shell.execute_reply":"2024-01-29T05:05:55.182786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_patient_ids = set(train_df['Patient'].unique())\ntest_patient_ids = set(test_df['Patient'].unique())\n\ntrain_patient_ids.intersection(test_patient_ids)","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:56.286432Z","iopub.execute_input":"2024-01-29T05:05:56.286847Z","iopub.status.idle":"2024-01-29T05:05:56.296827Z","shell.execute_reply.started":"2024-01-29T05:05:56.286813Z","shell.execute_reply":"2024-01-29T05:05:56.295237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Test set에 있는 5명의 환자들은 Train set에서도 똑같이 존재함","metadata":{}},{"cell_type":"markdown","source":"## Row 중복 확인","metadata":{}},{"cell_type":"code","source":"print('Train max duplicated :', train_df['Patient'].value_counts().max())\nprint('Test max duplicated :', test_df['Patient'].value_counts().max())","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:05:58.750898Z","iopub.execute_input":"2024-01-29T05:05:58.751320Z","iopub.status.idle":"2024-01-29T05:05:58.760675Z","shell.execute_reply.started":"2024-01-29T05:05:58.751290Z","shell.execute_reply":"2024-01-29T05:05:58.758845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 5. 분석 및 시각화","metadata":{}},{"cell_type":"markdown","source":"## 개별 환자 데이터 프레임 만들기","metadata":{}},{"cell_type":"code","source":"patient_df = train_df[['Patient', 'Age', 'Sex', 'SmokingStatus']].drop_duplicates()\npatient_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:00.501883Z","iopub.execute_input":"2024-01-29T05:06:00.502279Z","iopub.status.idle":"2024-01-29T05:06:00.517628Z","shell.execute_reply.started":"2024-01-29T05:06:00.502249Z","shell.execute_reply":"2024-01-29T05:06:00.516170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## SmokingStatus 분석","metadata":{}},{"cell_type":"code","source":"patient_df['SmokingStatus'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:03.422788Z","iopub.execute_input":"2024-01-29T05:06:03.423398Z","iopub.status.idle":"2024-01-29T05:06:03.433012Z","shell.execute_reply.started":"2024-01-29T05:06:03.423366Z","shell.execute_reply":"2024-01-29T05:06:03.431604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_df['SmokingStatus'].value_counts().iplot(kind='bar', yTitle='Counts', linecolor='black', opacity=0.7, color='blue', theme='pearl', bargap=0.5, gridcolor='white', title='Distribution of the SmokingStatus column in the Unique Patient Set')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:04.240647Z","iopub.execute_input":"2024-01-29T05:06:04.241070Z","iopub.status.idle":"2024-01-29T05:06:04.422367Z","shell.execute_reply.started":"2024-01-29T05:06:04.241031Z","shell.execute_reply":"2024-01-29T05:06:04.420901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 주(Weeks) 분석","metadata":{}},{"cell_type":"code","source":"train_df['Weeks'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:07.175082Z","iopub.execute_input":"2024-01-29T05:06:07.175426Z","iopub.status.idle":"2024-01-29T05:06:07.187369Z","shell.execute_reply.started":"2024-01-29T05:06:07.175399Z","shell.execute_reply":"2024-01-29T05:06:07.185665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Weeks'].value_counts().iplot(kind='barh', xTitle='Counts(Weeks)', linecolor='black', opacity=0.7, color='#FB8072', theme='pearl', bargap=0.2, gridcolor='white', title='Distribution of the Weeks in the training set')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:08.174281Z","iopub.execute_input":"2024-01-29T05:06:08.174664Z","iopub.status.idle":"2024-01-29T05:06:08.221267Z","shell.execute_reply.started":"2024-01-29T05:06:08.174632Z","shell.execute_reply":"2024-01-29T05:06:08.220532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Weeks'].iplot(kind='hist', xTitle='Weeks', yTitle='Counts', linecolor='black', opacity=0.7, color='#FB8072', theme='pearl', bargap=0.2, gridcolor='white', title='Distribution of the Weeks in the training set')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:09.343570Z","iopub.execute_input":"2024-01-29T05:06:09.344306Z","iopub.status.idle":"2024-01-29T05:06:09.399921Z","shell.execute_reply.started":"2024-01-29T05:06:09.344261Z","shell.execute_reply":"2024-01-29T05:06:09.399011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Weeks에 음수 값이 있음\n\n- Weeks는 기준 CT를 중심으로 전/후임","metadata":{}},{"cell_type":"markdown","source":"### 주(Weeks)별 연령(Age) 분포","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(train_df, x='Weeks', y='Age', color='Sex')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:12.310278Z","iopub.execute_input":"2024-01-29T05:06:12.310832Z","iopub.status.idle":"2024-01-29T05:06:12.404162Z","shell.execute_reply.started":"2024-01-29T05:06:12.310799Z","shell.execute_reply":"2024-01-29T05:06:12.402428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## FVC - The Forced Vital Capacity 분석","metadata":{}},{"cell_type":"markdown","source":" Forced Vital Capacity(FVC, 강제 폐활량)은 폐의 산소 수용성을 나타냄\n \n - 폐의 수용량(단위는 ml)","metadata":{}},{"cell_type":"code","source":"train_df['FVC'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:15.126034Z","iopub.execute_input":"2024-01-29T05:06:15.126401Z","iopub.status.idle":"2024-01-29T05:06:15.135115Z","shell.execute_reply.started":"2024-01-29T05:06:15.126368Z","shell.execute_reply":"2024-01-29T05:06:15.134037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['FVC'].iplot(kind='hist', xTitle='Lung Capacity(ml)', linecolor='black', opacity=0.8, color='#FB8072', bargap=0.5, gridcolor='white', title='Distribution of the FVC in the training set')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:15.998477Z","iopub.execute_input":"2024-01-29T05:06:15.998866Z","iopub.status.idle":"2024-01-29T05:06:16.058131Z","shell.execute_reply.started":"2024-01-29T05:06:15.998832Z","shell.execute_reply":"2024-01-29T05:06:16.056857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### FVC vs Percent","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(train_df, x='FVC', y='Percent', color='Age')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:18.462440Z","iopub.execute_input":"2024-01-29T05:06:18.462809Z","iopub.status.idle":"2024-01-29T05:06:18.523032Z","shell.execute_reply.started":"2024-01-29T05:06:18.462780Z","shell.execute_reply":"2024-01-29T05:06:18.521825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### FVC vs Age(나이)","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(train_df, x='FVC', y='Age', color='Sex')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:25.022884Z","iopub.execute_input":"2024-01-29T05:06:25.023278Z","iopub.status.idle":"2024-01-29T05:06:25.083934Z","shell.execute_reply.started":"2024-01-29T05:06:25.023247Z","shell.execute_reply":"2024-01-29T05:06:25.082550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### FVC vs 주(Weeks)","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(train_df, x='FVC', y='Weeks', color='SmokingStatus')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:27.046424Z","iopub.execute_input":"2024-01-29T05:06:27.047052Z","iopub.status.idle":"2024-01-29T05:06:27.107491Z","shell.execute_reply.started":"2024-01-29T05:06:27.047016Z","shell.execute_reply":"2024-01-29T05:06:27.106155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 환자 별 FVC vs 주(Weeks)","metadata":{}},{"cell_type":"code","source":"patient = train_df[train_df['Patient'] == 'ID00228637202259965313869']\nfig = px.line(patient, x='Weeks', y='FVC', color='SmokingStatus')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:28.709563Z","iopub.execute_input":"2024-01-29T05:06:28.709927Z","iopub.status.idle":"2024-01-29T05:06:28.765133Z","shell.execute_reply.started":"2024-01-29T05:06:28.709895Z","shell.execute_reply":"2024-01-29T05:06:28.764293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Percent 분석","metadata":{}},{"cell_type":"code","source":"train_df['Percent'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:30.952120Z","iopub.execute_input":"2024-01-29T05:06:30.952521Z","iopub.status.idle":"2024-01-29T05:06:30.963343Z","shell.execute_reply.started":"2024-01-29T05:06:30.952492Z","shell.execute_reply":"2024-01-29T05:06:30.961796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Percent'].iplot(kind='hist', bins=30, color='blue', xTitle='Percent distribution', yTitle='Count')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:32.032847Z","iopub.execute_input":"2024-01-29T05:06:32.033227Z","iopub.status.idle":"2024-01-29T05:06:32.095385Z","shell.execute_reply.started":"2024-01-29T05:06:32.033196Z","shell.execute_reply":"2024-01-29T05:06:32.094366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Percent vs SmokingStatus","metadata":{}},{"cell_type":"code","source":"fig = px.violin(train_df, y='Percent', x='SmokingStatus', box=True, color='Sex', points='all', hover_data=train_df.columns)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:34.406021Z","iopub.execute_input":"2024-01-29T05:06:34.406381Z","iopub.status.idle":"2024-01-29T05:06:34.506857Z","shell.execute_reply.started":"2024-01-29T05:06:34.406352Z","shell.execute_reply":"2024-01-29T05:06:34.505879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\nax = sns.violinplot(x=train_df['SmokingStatus'], y=train_df['Percent'], palette='Reds')\nax.set_xlabel(xlabel='Smoking Habit', fontsize=15)\nax.set_ylabel(ylabel='Percent', fontsize=15)\nax.set_title(label='Distribution of Smoking Status Over Percentage', fontsize=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:36.532194Z","iopub.execute_input":"2024-01-29T05:06:36.532627Z","iopub.status.idle":"2024-01-29T05:06:36.881440Z","shell.execute_reply.started":"2024-01-29T05:06:36.532587Z","shell.execute_reply":"2024-01-29T05:06:36.880055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(train_df, x='Age', y='Percent', color='SmokingStatus')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:38.302149Z","iopub.execute_input":"2024-01-29T05:06:38.303261Z","iopub.status.idle":"2024-01-29T05:06:38.364722Z","shell.execute_reply.started":"2024-01-29T05:06:38.303226Z","shell.execute_reply":"2024-01-29T05:06:38.363799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 연령(Age) 분석","metadata":{}},{"cell_type":"code","source":"patient_df['Age'].iplot(kind='hist', bins=30, color='red', xTitle='Ages of distribution', yTitle='Count')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:40.568140Z","iopub.execute_input":"2024-01-29T05:06:40.568552Z","iopub.status.idle":"2024-01-29T05:06:40.616939Z","shell.execute_reply.started":"2024-01-29T05:06:40.568519Z","shell.execute_reply":"2024-01-29T05:06:40.615440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 연령 별 흡연상태 분포","metadata":{}},{"cell_type":"code","source":"patient_df['SmokingStatus'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:42.473814Z","iopub.execute_input":"2024-01-29T05:06:42.474555Z","iopub.status.idle":"2024-01-29T05:06:42.481626Z","shell.execute_reply.started":"2024-01-29T05:06:42.474524Z","shell.execute_reply":"2024-01-29T05:06:42.480719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\n\nsns.kdeplot(patient_df[patient_df['SmokingStatus'] == 'Ex-smoker']['Age'], label='Ex-smoker', fill=True)\nsns.kdeplot(patient_df[patient_df['SmokingStatus'] == 'Never smoked']['Age'], label='Never smoked', fill=True)\nsns.kdeplot(patient_df[patient_df['SmokingStatus'] == 'Currently smokes']['Age'], label='Currently smokes', fill=True)\n\nplt.xlabel('Age (years)')\nplt.ylabel('Density')\nplt.title('Distribution of Ages')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:43.471686Z","iopub.execute_input":"2024-01-29T05:06:43.472075Z","iopub.status.idle":"2024-01-29T05:06:43.858146Z","shell.execute_reply.started":"2024-01-29T05:06:43.472049Z","shell.execute_reply":"2024-01-29T05:06:43.857287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\nax = sns.violinplot(x=patient_df['SmokingStatus'], y=patient_df['Age'], palette='Reds')\nax.set_xlabel(xlabel='Smoking habit', fontsize=15)\nax.set_ylabel(ylabel='Age', fontsize=15)\nax.set_title(label='Distribution of Smokers over Age', fontsize=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:45.294401Z","iopub.execute_input":"2024-01-29T05:06:45.295327Z","iopub.status.idle":"2024-01-29T05:06:45.587756Z","shell.execute_reply.started":"2024-01-29T05:06:45.295295Z","shell.execute_reply":"2024-01-29T05:06:45.586633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 성별과 연령 분포","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\n\nsns.kdeplot(patient_df[patient_df['Sex'] == 'Male']['Age'], label='Male', fill=True)\nsns.kdeplot(patient_df[patient_df['Sex'] == 'Female']['Age'], label='Female', fill=True)\n\nplt.xlabel('Age (years)')\nplt.ylabel('Density')\nplt.title('Distribution of Ages')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:47.637881Z","iopub.execute_input":"2024-01-29T05:06:47.638265Z","iopub.status.idle":"2024-01-29T05:06:48.063415Z","shell.execute_reply.started":"2024-01-29T05:06:47.638236Z","shell.execute_reply":"2024-01-29T05:06:48.062041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 성별(Gender) 분석","metadata":{}},{"cell_type":"code","source":"patient_df['Sex'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:50.638514Z","iopub.execute_input":"2024-01-29T05:06:50.638880Z","iopub.status.idle":"2024-01-29T05:06:50.646643Z","shell.execute_reply.started":"2024-01-29T05:06:50.638853Z","shell.execute_reply":"2024-01-29T05:06:50.645787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_df['Sex'].value_counts().iplot(kind='bar', yTitle='Count', linecolor='black', opacity=0.7, color='blue', theme='pearl', bargap=0.8, gridcolor='white', title='Distribution of the Sex column in Patient Dataframe')","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:06:51.381451Z","iopub.execute_input":"2024-01-29T05:06:51.382086Z","iopub.status.idle":"2024-01-29T05:06:51.426344Z","shell.execute_reply.started":"2024-01-29T05:06:51.382055Z","shell.execute_reply":"2024-01-29T05:06:51.425294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 성별 vs SmokingStatus","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\nax = sns.countplot(data=patient_df, x='SmokingStatus', hue='Sex')\n\nfor p in ax.patches:\n    ax.annotate(format(p.get_height(), ','),\n                (p.get_x() + p.get_width() / 2.0, p.get_height()),\n                ha='center', va='center', xytext=(0, 4), textcoords='offset points')\n\nplt.title('Gender split by SmokingStatus', fontsize=16)\nsns.despine(left=True, bottom=True)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:07:14.215326Z","iopub.execute_input":"2024-01-29T05:07:14.215908Z","iopub.status.idle":"2024-01-29T05:07:14.502887Z","shell.execute_reply.started":"2024-01-29T05:07:14.215876Z","shell.execute_reply":"2024-01-29T05:07:14.501333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.box(patient_df, x='Sex', y='Age', points='all')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:07:18.330152Z","iopub.execute_input":"2024-01-29T05:07:18.330504Z","iopub.status.idle":"2024-01-29T05:07:18.390783Z","shell.execute_reply.started":"2024-01-29T05:07:18.330474Z","shell.execute_reply":"2024-01-29T05:07:18.389529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 6. Train.csv의 Heatmap","metadata":{}},{"cell_type":"code","source":"corr=train_df[['Weeks', 'FVC', 'Percent', 'Age']].corr()\nmask=np.triu(np.ones_like(corr, dtype=bool))\n\nfig, ax=plt.subplots(figsize =(9, 8))\nsns.heatmap(corr, ax=ax, cmap='RdYlBu_r', linewidths=0.5, mask=mask)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-29T05:07:21.759647Z","iopub.execute_input":"2024-01-29T05:07:21.760172Z","iopub.status.idle":"2024-01-29T05:07:22.196607Z","shell.execute_reply.started":"2024-01-29T05:07:21.760140Z","shell.execute_reply":"2024-01-29T05:07:22.195353Z"},"trusted":true},"execution_count":null,"outputs":[]}]}