{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"\nimport pandas as pd\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nimport plotly.express as px\nimport pydicom\n\nimport warnings\nwarnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_data = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/train.csv')\ntest_data = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/test.csv')\n\ntrain_data.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"\n*    **Patient** - a unique Id for each patient (also the name of the patient's DICOM folder)\n*    **Weeks** - the relative number of weeks pre/post the baseline CT (may be negative)\n*    **FVC** - the recorded lung capacity in ml (Forced vital capacity)\n*    **Percent** - a computed field which approximates the patient's FVC as a percent of the typical FVC for a person of similar characteristics\n*    **Age** - Age of person\n*    **Sex** - Sex of person (Male/Female)\n*    **SmokingStatus** - Whether the patient is a smoker/non-smoker/ex-smoker\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":">  # Explore the data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"print(train_data.shape)\nprint('----------------------------')\n\n#null values in test & train data\nprint(train_data.isnull().sum())\nprint('----------------------------')\nprint(test_data.isnull().sum())\nprint('----------------------------')\n\n#data type of each column\nprint(train_data.dtypes)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### No Missing Data\n### 1549 rows AND 7 columns","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"> # **Total  unique patient id's**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#total unique id's of the patients as from shape we know total id's are 1549\ntrain_data['Patient'].nunique()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"> # Visualizing Training data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,2, figsize=(15,7))\nplt.subplots_adjust(bottom=0, right=1, top=1)\n\nax[0,0].set_title('Total No.', color='red', fontsize = 15)\nsns.countplot('Sex', data= train_data, palette='Blues', ax= ax[0,0] )\n\nax[1,0].set_title('Smoking Status', color='red', fontsize = 15)\nsns.countplot('SmokingStatus', data=train_data, palette='Blues', ax=ax[1,0])\n\nax[1,1].set_title('Smoking status by Sex', color='red', fontsize = 15)\nsns.countplot('Sex', data=train_data, hue='SmokingStatus', palette = 'Blues', ax=ax[1,1])\n\n#gender percentage\ncount = [train_data['Sex'].value_counts().values]\nlabels = ['male', 'female']\nexplode = (0.1,0)\n\nax[0,1].set_title('Percentage of male and female', color='red', fontsize = 15)\nax[0,1].pie(count, labels=labels,\n       explode = explode, \n       shadow= True,  \n       autopct='%1.1f%%')\nax[0,1].axis('equal') \nplt.show()\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"raw","source":"From the visualization we can see that \n1. gender class is imbalanced male count is higher then female\n2. Ex-smoker are heigher AND currently smoking people are very less\n3. male has Ex-smokers higher then other 2 catogeries and female has Never-smoked higher then other 2 catogeries\n\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"> ## No. of images per  unique patient","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"id_count = pd.DataFrame(train_data['Patient'].value_counts())\nid_count['id'] =id_count.index\nid_count.columns= ['count','id']\n\nfig = px.bar(id_count, x='id',y ='count',color='count')\nfig.update_xaxes(showticklabels=False)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"> # Distribution of the data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1,4, figsize =(23,3))\nplt.subplots_adjust(bottom=0, right=1, top=1)\n\nax[0].set_title('Age', color='red', fontsize = 15)\nsns.distplot(train_data['Age'],  color=\"r\", ax=ax[0])\n\nax[1].set_title('Weeks', color='red', fontsize = 15)\nsns.distplot(train_data['Weeks'],  color=\"g\", ax=ax[1])\n\nax[2].set_title('Percent', color='red', fontsize = 15)\nsns.distplot(train_data['Percent'],  color=\"c\", ax=ax[2])\n\nax[3].set_title('FVC', color='red', fontsize = 15)\nsns.distplot(train_data['FVC'],  color=\"b\", ax=ax[3])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*  Age is Normal distribution.\n*  Weeks is right skewed  distribution.\n*  Percent is also right skewed distrivution.\n*  FVC is also  little right skewed","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"> # Age & Smoking Status","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.histogram(train_data, x='Age', color='SmokingStatus', marginal=\"violin\",color_discrete_map={'Ex-smoker':'#393E46','Never smoked':'#7c7c79','Currently smokes':'#04d6cb'})\nfig.update_traces(marker_line_color='cyan',marker_line_width=1.5, opacity=0.85)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"> # Age & Gender","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.histogram(train_data, x='Age', color='Sex',marginal=\"violin\", color_discrete_map={'Male':'#393E46','Female':'#04d6cb'})\nfig.update_traces(marker_line_color='black',marker_line_width=1.5, opacity=0.85)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1. > # EXPLORING FVC\n>      Normal values in healthy males aged 20-60 range from 3500 to 4500 ml, and normal values for females aged 20-60 range from 2500 to 3500 ml.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.histogram(train_data, x='FVC', color='Sex', title='FVC by Gender', marginal=\"violin\", color_discrete_map={'Male':'#393E46','Female':'#04d6cb'})\nfig.update_traces(marker_line_color='black',marker_line_width=1.5, opacity=0.85)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.histogram(train_data, x='FVC', color='SmokingStatus', marginal=\"violin\",color_discrete_map={'Ex-smoker':'#393E46','Never smoked':'#7c7c79','Currently smokes':'#04d6cb'})\n#fig.update_traces(marker_line_color='black',marker_line_width=1.5, opacity=0.85)\nfig.update_layout(title='FVC by Smoking Status')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"> ## Visualizing images","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"img_path = \"../input/osic-pulmonary-fibrosis-progression/train/ID00027637202179689871102/125.dcm\"\nimg = pydicom.dcmread(img_path)\nfig, ax = plt.subplots(1,3, figsize=(20,10))\nax[0].imshow(img.pixel_array,cmap='nipy_spectral')\nax[1].imshow(img.pixel_array,cmap='hot')\nax[2].imshow(img.pixel_array,cmap=plt.cm.bone)\n\nplt.show()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}