{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport pydicom\nimport cv2\nimport numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport altair as alt\nimport seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"df_train = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/train.csv')\nsample_sub = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/sample_submission.csv')\ntest = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/test.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# learning about the data."},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Function below gives us all the details about the number of Patients, smoking status, percent group of the patients, Sex,etc.\n\ndef general_info(df):\n    info = dict()\n    info['patients'] = df['Patient'].nunique()\n    info['Male'] = df['Patient'][df.Sex == 'Male'].nunique()\n    info['Female'] = df['Patient'][df.Sex == 'Female'].nunique()\n    info['Ex-smoker'] = df['Patient'][df.SmokingStatus == 'Ex-smoker'].nunique()\n    info['Ex-smoker-male'] = df['Patient'].loc[(df['SmokingStatus'] == 'Ex-smoker') & (df['Sex'] == 'Male')].nunique()\n    info['Ex-smoker-female'] = df['Patient'].loc[(df['SmokingStatus'] == 'Ex-smoker') & (df['Sex'] == 'Female')].nunique()\n    info['Never smoked'] = df['Patient'][df.SmokingStatus == 'Never smoked'].nunique()\n    info['Never smoked-male'] = df['Patient'].loc[(df['SmokingStatus'] == 'Never smoked') & (df['Sex'] == 'Male')].nunique()\n    info['Never smoked-female'] = df['Patient'].loc[(df['SmokingStatus'] == 'Never smoked') & (df['Sex'] == 'Female')].nunique()\n    info['Currently smokes'] = df['Patient'][df.SmokingStatus == 'Currently smokes'].nunique()\n    info['Currently smokes-male'] = df['Patient'].loc[(df['SmokingStatus'] == 'Currently smokes') & (df['Sex'] == 'Male')].nunique()\n    info['Currently smokes-female'] = df['Patient'].loc[(df['SmokingStatus'] == 'Currently smokes') & (df['Sex'] == 'Female')].nunique()\n    info['null_values'] = df.isna().sum()\n\n    return info\ngeneral_info(df_train)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualizations"},{"metadata":{"trusted":true},"cell_type":"code","source":"base = alt.Chart(df_train.groupby('Patient').head(1)).mark_bar(size=8).encode(\n            alt.X('Age', title='Age of patients'),\n            alt.Y('count(Patient)', title='Number of Patents'),\n            tooltip = ['Patient', 'Age', 'Sex', 'SmokingStatus']\n            ).properties(\n            width=400,\n            height=300\n            ).interactive()\n\nalt.concat(\n    base.encode(color='Sex:N'),\n    base.encode(color='SmokingStatus:N'))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The graph above shows the number of patients and in a particular age group.**\nIf you move the cursor on the graph you will see the details on each patient."},{"metadata":{"trusted":true},"cell_type":"code","source":"base = alt.Chart(df_train.groupby('Patient').head(1)).mark_circle(size=100).encode(\n    x = 'Age:O',\n    y = 'FVC:Q',\n    color = 'Sex',\n    tooltip = ['Patient', 'FVC', 'Sex', 'SmokingStatus']\n    ).properties(\n        width=400,\n        height=300\n    ).interactive()\n\nalt.concat(\n    base.encode(color='Sex:N'),\n    base.encode(color='SmokingStatus:N'))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The Graph**\n*below Shows the relation between different ages and their FVC.Moving the cursor on the graph will show the details\nThe Graph Shows the relation between different ages and their FVC with different smoking status and Sex.*"},{"metadata":{"trusted":true},"cell_type":"code","source":"brush = alt.selection_interval()  # selection of type \"interval\"\n\nchart = alt.Chart(df_train.groupby('Patient').head(1)).mark_circle(size=80).encode(\nx = 'Age:O',\ncolor = alt.condition(brush,'Sex:N', alt.value('lightgray')),\n    tooltip = ['Age', 'Percent', 'FVC', 'Sex']\n).properties(\n    width=320,\n    height=300\n).add_selection(\n    brush\n)\n\nchart.encode(y='FVC:Q') | chart.encode(y='Percent:Q')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The Graph above shows the relation between FVC and Percent for Patients of different ages.**\nTo see the relation between FVC and Percent just move the cursor on the FVC graph then click and select an area, as a result you will see highlighted area in the other graph. "},{"metadata":{"trusted":true},"cell_type":"code","source":"chart = alt.Chart(df_train.groupby('Patient').head(1)).mark_circle(size=80).encode(\nx = 'Age:O',\ncolor = alt.condition(brush,'SmokingStatus:N', alt.value('lightgray')),\n    tooltip = ['Age','Percent', 'FVC', 'Sex']\n).properties(\n    width=320,\n    height=300\n).add_selection(\n    brush\n)\n\nchart.encode(y='FVC:Q') | chart.encode(y='Percent:Q')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"\n**The Graph above shows the relation between FVC and Percent for Patients of different ages for different smoking status. To see the relation between FVC and Percent just move the cursor on the FVC graph then click and select an area, as a result you will see highlighted area in the other graph.**"}],"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}