{"cells":[{"metadata":{},"cell_type":"markdown","source":"# About the Competition\nImagine one day, your breathing became consistently labored and shallow. Months later you were finally diagnosed with pulmonary fibrosis, a disorder with no known cause and no known cure, created by scarring of the lungs. If that happened to you, you would want to know your prognosis. That’s where a troubling disease becomes frightening for the patient: outcomes can range from long-term stability to rapid deterioration, but doctors aren’t easily able to tell where an individual may fall on that spectrum. Your help, and data science, may be able to aid in this prediction, which would dramatically help both patients and clinicians.\n\nCurrent methods make fibrotic lung diseases difficult to treat, even with access to a chest CT scan. In addition, the wide range of varied prognoses create issues organizing clinical trials. Finally, patients suffer extreme anxiety—in addition to fibrosis-related symptoms—from the disease’s opaque path of progression.\n\nOpen Source Imaging Consortium (OSIC) is a not-for-profit, co-operative effort between academia, industry and philanthropy. The group enables rapid advances in the fight against Idiopathic Pulmonary Fibrosis (IPF), fibrosing interstitial lung diseases (ILDs), and other respiratory diseases, including emphysematous conditions. Its mission is to bring together radiologists, clinicians and computational scientists from around the world to improve imaging-based treatments.\n\nIn this competition, you’ll predict a patient’s severity of decline in lung function based on a CT scan of their lungs. You’ll determine lung function based on output from a spirometer, which measures the volume of air inhaled and exhaled. The challenge is to use machine learning techniques to make a prediction with the image, metadata, and baseline FVC as input.\n\nIf successful, patients and their families would better understand their prognosis when they are first diagnosed with this incurable lung disease. Improved severity detection would also positively impact treatment trial design and accelerate the clinical development of novel treatments.\n\n## Note\n* There are 5 people in the test, in the train - 309.8 times more.\n* The largest amount of patient data is 10 in the train, and in the test - 1.\n* In the training sample, there are patients aged 49-88, and the test sample contains 3 patients at the age of 73 years and one patient each at 68 and 72 years.\n* There are no patients currently smokers in the test.\n* The training set contains data for weeks -5 through 133.\n* Largest amount of data between 6 and 18 weeks.\n* The test sample provides data only for 0, 6, 15 and 17 weeks","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\n\n# Visualisation libraries\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nsns.set()\nfrom plotly.offline import init_notebook_mode, iplot \nimport plotly.graph_objs as go\nimport plotly.offline as py\nimport pycountry\npy.init_notebook_mode(connected=True)\nimport folium \nfrom folium import plugins\n\nimport pydicom\n\n# Graphics in retina format \n%config InlineBackend.figure_format = 'retina' \n\n# Increase the default plot size and set the color scheme\nplt.rcParams['figure.figsize'] = 8, 5\n#plt.rcParams['image.cmap'] = 'viridis'\n\n# palette of colors to be used for plots\ncolors = [\"steelblue\",\"dodgerblue\",\"lightskyblue\",\"powderblue\",\"cyan\",\"deepskyblue\",\"cyan\",\"darkturquoise\",\"paleturquoise\",\"turquoise\"]\n\n\n# Disable warnings in Anaconda\nimport warnings\nwarnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"# Helper functions\n\ndef return_count(data,question_part):\n    \"\"\"Counts occurences of each value in a given column\"\"\"\n    counts_df = data[question_part].value_counts().to_frame()\n    return counts_df\n\ndef return_percentage(data,question_part):\n    \"\"\"Calculates percent of each value in a given column\"\"\"\n    total = data[question_part].count()\n    counts_df= data[question_part].value_counts().to_frame()\n    percentage_df = (counts_df*100)/total\n    return percentage_df\n\n\n    \ndef plot_graph(data,question,title,x_axis_title,y_axis_title):\n    \"\"\" plots a percentage bar graph\"\"\"\n    df = return_percentage(data,question)\n    \n    trace1 = go.Bar(\n                    x = df.index,\n                    y = df[question],\n                    #orientation='h',\n                    marker = dict(color='dodgerblue',\n                                 line=dict(color='black',width=1)),\n                    text = df.index)\n    data = [trace1]\n    layout = go.Layout(barmode = \"group\",title=title,width=800, height=500,\n                       xaxis=dict(type='category',categoryorder='array',categoryarray=salary_order,title=y_axis_title),\n                       yaxis= dict(title=x_axis_title))\n                       \n    fig = go.Figure(data = data, layout = layout)\n    iplot(fig)    \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"basepath = '../input/osic-pulmonary-fibrosis-progression/'","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_info = pd.read_csv(basepath + 'train.csv')\ntrain_info.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_info = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/test.csv')\ntest_info.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_info.shape[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_info.shape[0] / test_info.shape[0]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"There are 5 people in the test, in the train - 309.8 times more.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# What does the data give us?\n## 1. Patient","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_info.Patient.value_counts().max()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_info.Patient.value_counts().max()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The largest amount of patient data is 10 in the train, and in the test - 1.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"## 2. Gender","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1,2,figsize=(20,5))\nsns.countplot(train_info.Sex, palette=\"Reds_r\", ax=ax[0]);\nax[0].set_xlabel(\"\")\nax[0].set_title(\"Gender counts in train\");\n\nsns.countplot(test_info.Sex, palette=\"Blues_r\", ax=ax[1]);\nax[1].set_xlabel(\"\")\nax[1].set_title(\"Gender counts in test\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* There are more men than women in the training sample, and only men in the test sample.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"## 3. Age","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1,2,figsize=(20,5))\n\nsns.countplot(train_info.Age, color=\"orangered\", ax=ax[0]);\nlabels = ax[0].get_xticklabels();\nax[0].set_xticklabels(labels, rotation=90);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Age distribution in train\");\n\nsns.countplot(test_info.Age, color=\"lightseagreen\", ax=ax[1]);\nlabels = ax[1].get_xticklabels();\nax[1].set_xticklabels(labels, rotation=90);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Age distribution in test\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* In the training sample, there are patients aged 49-88, and the test sample contains 3 patients at the age of 73 years and one patient each at 68 and 72 years.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"## 4. Smoking status","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1,2,figsize=(20,5))\n\nsns.countplot(train_info.SmokingStatus, color=\"orangered\", ax=ax[0]);\nlabels = ax[0].get_xticklabels();\nax[0].set_xticklabels(labels, rotation=90);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Smoking status distribution in train\");\n\nsns.countplot(test_info.SmokingStatus, color=\"lightseagreen\", ax=ax[1]);\nlabels = ax[1].get_xticklabels();\nax[1].set_xticklabels(labels, rotation=90);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Smoking status distribution in test\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* There are no patients currently smokers in the test.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"## 5. Week","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,1,figsize=(20,10))\n\nsns.countplot(train_info.Weeks, color=\"orangered\", ax=ax[0]);\nlabels = ax[0].get_xticklabels();\nax[0].set_xticklabels(labels, rotation=90);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Weeks distribution in train\");\n\nsns.countplot(test_info.Weeks, color=\"lightseagreen\", ax=ax[1]);\nlabels = ax[1].get_xticklabels();\nax[1].set_xticklabels(labels, rotation=90);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"\\nWeeks distribution in test\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* The training set contains data for weeks -5 through 133.\n* Largest amount of data between 6 and 18 weeks.\n* The test sample provides data only for 0, 6, 15 and 17 weeks","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"## 6. Age & Gender","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1,2,figsize=(20,5))\n\nsns.countplot(train_info.loc[train_info.Sex == 'Male'].Age, color=\"orangered\", ax=ax[0]);\nlabels = ax[0].get_xticklabels();\nax[0].set_xticklabels(labels, rotation=90);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Distribution of men by age in train\");\n\nsns.countplot(train_info.loc[train_info.Sex == 'Female'].Age, color=\"lightseagreen\", ax=ax[1]);\nlabels = ax[1].get_xticklabels();\nax[1].set_xticklabels(labels, rotation=90);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Distribution of women by age in train\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# What does the dicom-data give us?","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"pydicom.__version__","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's see what's in the training folder.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"example_folders = os.listdir(basepath + \"train/\")[:2]\nexample_folders","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"example_files = os.listdir(basepath + \"train/\" + 'ID00060637202187965290703')[0:2]\nexample_files","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_paths = np.array([])\nfolders = os.listdir(basepath + \"train/\")\nfor folder in folders:\n    files = os.listdir(basepath + \"train/\" + folder)\n    for file in files:\n        train_paths = np.append(train_paths, [basepath + \"train/\" + folder + '/' + file])\ntrain_paths[:4]","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"#https://www.kaggle.com/schlerp/getting-to-know-dicom-and-the-data\ndef show_dcm_info(file_path):\n    dataset = pydicom.dcmread(file_path)\n    \n    print(\"Filename.....................:\", file_path)\n    print()\n\n    pat_name = dataset.PatientName\n    display_name = pat_name.family_name + \", \" + pat_name.given_name\n    print(\"Patient's name...............:\", display_name)\n    print(\"Patient id...................:\", dataset.PatientID)\n    print(\"Manufacturer.................:\", dataset.Manufacturer)\n    print(\"Manufacturer's Model Name....:\", dataset.ManufacturerModelName)\n    print(\"Slice Location...............:\", dataset.SliceLocation)\n   \n    \n    \n    if 'PixelData' in dataset:\n        rows = int(dataset.Rows)\n        cols = int(dataset.Columns)\n        print(\"Image size...................: {rows:d} x {cols:d}, {size:d} bytes\".format(\n            rows=rows, cols=cols, size=len(dataset.PixelData)))\n        if 'PixelSpacing' in dataset:\n            print(\"Pixel spacing................:\", dataset.PixelSpacing)\n            \ndef plot_pixel_array(dataset, figsize=(5,5)):\n    plt.figure(figsize=figsize)\n    plt.grid(False)\n    plt.imshow(dataset.pixel_array, 'gray')\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"show_dcm_info(train_paths[75])\n\nexample_dcm = pydicom.dcmread(train_paths[75])\nplot_pixel_array(example_dcm)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"# source: https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/154658\n\ndef extract_DICOM_attributes(dicom_file_paths):\n    df = pd.DataFrame()\n    for dicom_file_path in dicom_file_paths:\n        dicom_file_dataset = pydicom.read_file(dicom_file_path)\n        patient_name = dicom_file_dataset.PatientID\n        manufacturer = dicom_file_dataset.Manufacturer\n        manufacturer_model_name = dicom_file_dataset.ManufacturerModelName \n        modality = dicom_file_dataset.Modality\n        body_part_examined = dicom_file_dataset.BodyPartExamined\n        photometric_interpretation = dicom_file_dataset.PhotometricInterpretation\n        rows = dicom_file_dataset.Rows\n        columns = dicom_file_dataset.Columns\n\n        df = df.append(pd.DataFrame({'patient_name' : patient_name,\n                                     'manufacturer' : manufacturer,\n                                     'manufacturer_model_name' : manufacturer_model_name,\n                                     'modality': modality,\n                                     'body_part_examined': body_part_examined,\n                                     'photometric_interpretation': photometric_interpretation,\n                                     'path': dicom_file_path,\n                                     'rows': rows, \n                                     'columns': columns}, index=[0]), ignore_index=True)\n    return df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_dcm_info = extract_DICOM_attributes(train_paths)\ntrain_dcm_info.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(len(train_dcm_info))\ncolumns = ['patient_name', 'manufacturer', 'manufacturer_model_name', 'modality', 'body_part_examined', 'photometric_interpretation',\n                                'rows', 'columns']\ntrain_dcm_copy = train_dcm_info[columns].copy()\ntrain_dcm_no_dubl = train_dcm_copy.drop_duplicates(subset=columns)\nprint(len(train_dcm_no_dubl) )","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* 176 patients have a total of 33026 images.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_dcm_no_dubl.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(20,5))\n\nsns.countplot(train_dcm_no_dubl.manufacturer, color=\"c\", ax=ax);\nlabels = ax.get_xticklabels();\nax.set_xticklabels(labels, rotation=90);\nax.set_xlabel(\"\");\nax.set_title(\"Distribution of manufacturer in train\");\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* The most popular manufacturer is Siemens.","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,1,figsize=(15,10))\n\nsns.countplot(train_dcm_no_dubl.rows, color=\"orangered\", ax=ax[0]);\nlabels = ax[0].get_xticklabels();\nax[0].set_xticklabels(labels, rotation=90);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Distribution of manufacturer in train\");\n\nsns.countplot(train_dcm_no_dubl['columns'], color=\"lightseagreen\", ax=ax[1]);\nlabels = ax[1].get_xticklabels();\nax[1].set_xticklabels(labels, rotation=90);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Distribution of manufacturer in train\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* It turns out that our images are not all square, but also have different sizes.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# FVC & Percent","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,1,figsize=(15,10))\n\nsns.distplot(train_info.FVC, color=\"g\", ax=ax[0]);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Distribution of FVC in train\");\n\nsns.distplot(train_info.Percent, color=\"r\", ax=ax[1]);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Distribution of Percent in train\");","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"percent_100 = train_info.FVC / train_info.Percent * 100\npercent_100.mean()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* On average, to have 100 percent, you need to have ≈ 3495 of FVC.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_info['Percent 100%'] = train_info.FVC / train_info.Percent * 100\ntrain_group_sex = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','Sex']].groupby(['Sex']).mean()\ntrain_group_sex","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* Men on average have a large FVC.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_group_weeks = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','Weeks']].groupby(['Weeks']).mean()\ntrain_group_weeks['Weeks'] = train_group_weeks.index\ntrain_group_weeks.head()","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,1,figsize=(15,17))\n\nsns.regplot(\"Weeks\", \"FVC\", data=train_group_weeks, truncate=False,\n                  color=\"c\", order=3, ax=ax[0])\nax[0].set_title(\"Distribution of average FVC by weeks in train\");\n\nsns.regplot(\"Weeks\", \"Percent\", data=train_group_weeks, truncate=False,\n                  color=\"m\", order=3, ax=ax[1]);\nax[1].set_title(\"Distribution of average Percent by weeks in train\");\n\nsns.regplot(\"Weeks\", \"Percent 100%\", data=train_group_weeks,truncate=False,\n                  color=\"k\", order=2, ax=ax[2])\nax[2].set_title(\"Distribution of average Percent 100% by weeks in train\");","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"train_group_age = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','Age']].groupby(['Age']).mean()\ntrain_group_age['Age'] = train_group_age.index\ntrain_group_age.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,1,figsize=(15,17))\n\nsns.regplot(\"Age\", \"FVC\", data=train_group_age, truncate=False,\n                  color=\"r\", order=4, ax=ax[0])\nax[0].set_title(\"Distribution of average FVC by age in train\");\n\nsns.regplot(\"Age\", \"Percent\", data=train_group_age, truncate=False,\n                  color=\"g\", order=4, ax=ax[1]);\nax[1].set_title(\"Distribution of average Percent by age in train\");\n\nsns.regplot(\"Age\", \"Percent 100%\", data=train_group_age,truncate=False,\n                  color=\"b\", order=3, ax=ax[2])\nax[2].set_title(\"Distribution of average Percent 100% by age in train\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"📎 **Resume:**\n* FVC grows with age and then falls.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_group_smoking = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','SmokingStatus']].groupby(['SmokingStatus']).mean()\ntrain_group_smoking['SmokingStatus'] = train_group_smoking.index\ntrain_group_smoking","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,1,figsize=(15,17))\n\nsns.barplot(data = train_group_smoking, x = 'SmokingStatus', y =\"FVC\", ax=ax[0])\nax[0].set_title(\"Distribution of average FVC by SmokingStatus in train\");\n\nsns.barplot(data = train_group_smoking, x = 'SmokingStatus', y =\"Percent\", ax=ax[1])\nax[1].set_title(\"Distribution of average Percent by SmokingStatus in train\");\n\nsns.barplot(data = train_group_smoking, x = 'SmokingStatus', y =\"Percent 100%\", ax=ax[2])\nax[2].set_title(\"Distribution of average Percent 100% by SmokingStatus in train\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Strange, smokers have the largest FVC. What is the reason for this?","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"def get_tuble(arr, ind):\n    ans = np.array([])\n    for element in arr:\n        ans = np.append(ans, element[ind])\n    return ans","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"train_group_smoking_sex = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','SmokingStatus', 'Sex']].groupby(['SmokingStatus', 'Sex']).mean()\ntrain_group_smoking_sex['SmokingStatus'] = get_tuble(train_group_smoking_sex.index, 0)\ntrain_group_smoking_sex['Sex'] = get_tuble(train_group_smoking_sex.index, 1)\ntrain_group_smoking_sex","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,1,figsize=(15,17))\n\nsns.barplot(data = train_group_smoking_sex, x = 'SmokingStatus', y =\"FVC\", ax=ax[0], hue='Sex')\nax[0].set_title(\"Distribution of average FVC by SmokingStatus  and gender in train\");\n\nsns.barplot(data = train_group_smoking_sex, x = 'SmokingStatus', y =\"Percent\", ax=ax[1], hue='Sex')\nax[1].set_title(\"Distribution of average Percent by SmokingStatus and gender in train\");\n\nsns.barplot(data = train_group_smoking_sex, x = 'SmokingStatus', y =\"Percent 100%\", ax=ax[2], hue='Sex' )\nax[2].set_title(\"Distribution of average Percent 100% by SmokingStatus and gender in train\");","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"train_group_smoking_age = train_info.loc[:, ['FVC', 'Percent', 'Percent 100%','SmokingStatus', 'Age']].groupby(['SmokingStatus', 'Age']).mean()\ntrain_group_smoking_age['SmokingStatus'] = get_tuble(train_group_smoking_age.index, 0)\ntrain_group_smoking_age['Age'] = get_tuble(train_group_smoking_age.index, 1)\ntrain_group_smoking_age.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.pairplot(train_group_smoking_age, hue=\"SmokingStatus\", palette=\"husl\")","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}