{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Zero week\nIn  [my previous notebooke](https://www.kaggle.com/ladanova/osic-pulmonary-fibrosis-progression-eda) I researched all weeks now I only want to research zero week.\nBecause there is a CT scan in week 0 competition."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":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# Disable warnings in Anaconda\nimport warnings\nwarnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"basepath = '../input/osic-pulmonary-fibrosis-progression/'","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# What does the data give us?"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_info = pd.read_csv(basepath + 'train.csv')\ntrain_info.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Zero week \nLet's select the data of the zero week."},{"metadata":{"trusted":true},"cell_type":"code","source":"train_0 = train_info.loc[train_info.Weeks == 0]\ntrain_0.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"len(train_0)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"We have 18 measurement data."},{"metadata":{},"cell_type":"markdown","source":"### 1. Gender"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,5))\nsns.countplot(train_0.Sex, palette=\"Reds_r\", ax=ax);\nax.set_xlabel(\"\")\nax.set_title(\"Gender counts in train on  the zero week \");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* There are 5 times more men than women."},{"metadata":{},"cell_type":"markdown","source":"### 2. Age "},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,5))\n\nsns.countplot(train_0.Age, color=\"orangered\", ax=ax);\nlabels = ax.get_xticklabels();\nax.set_xticklabels(labels, rotation=90);\nax.set_xlabel(\"\");\nax.set_title(\"Age distribution in train on the zero week\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* Respondents aged 53 to 76."},{"metadata":{},"cell_type":"markdown","source":"### 3. Smoking status "},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,5))\n\nsns.countplot(train_0.SmokingStatus, color=\"orangered\", ax=ax);\nlabels = ax.get_xticklabels();\nax.set_xticklabels(labels, rotation=90);\nax.set_xlabel(\"\");\nax.set_title(\"Smoking status distribution in train on the zero week\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* The largest number of ex-smokers."},{"metadata":{},"cell_type":"markdown","source":"### 4. FVC & Percent"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,1,figsize=(15,10))\n\nsns.distplot(train_0.FVC, color=\"g\", ax=ax[0]);\nax[0].set_xlabel(\"\");\nax[0].set_title(\"Distribution of FVC in train on the zero week\");\n\nsns.distplot(train_0.Percent, color=\"r\", ax=ax[1]);\nax[1].set_xlabel(\"\");\nax[1].set_title(\"Distribution of Percent in train on the zero week\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* The distribution of FVC and percentages is normal."},{"metadata":{"trusted":true},"cell_type":"code","source":"percent_100 = train_0.FVC / train_0.Percent * 100\npercent_100.mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_0['Percent 100%'] = train_0.FVC / train_0.Percent * 100\ntrain_group_sex = train_0.loc[:, ['FVC', 'Percent', 'Percent 100%','Sex']].groupby(['Sex']).mean()\ntrain_group_sex","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* Men have a higher FVC than women and therefore a FVC of 100% will be higher."},{"metadata":{"trusted":true},"cell_type":"code","source":"train_group_age = train_0.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=3, ax=ax[0])\nax[0].set_title(\"Distribution of average FVC by age in train on  the zero week\");\n\nsns.regplot(\"Age\", \"Percent\", data=train_group_age, truncate=False,\n                  color=\"g\", order=3, ax=ax[1]);\nax[1].set_title(\"Distribution of average Percent by age in train on  the zero week\");\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 on  the zero week\");","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_group_smoking = train_0.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":{"trusted":true,"_kg_hide-input":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 on  the zero week\");\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 on  the zero week\");\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 on  the zero week\");","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* Forced vital capacity is lowest in never smokers. Consequently, the percentage is also lower than the norm."},{"metadata":{"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":{"trusted":true},"cell_type":"code","source":"train_group_smoking_sex = train_0.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":{"trusted":true,"_kg_hide-input":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 on  the zero week\");\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 on  the zero week\");\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 on  the zero week\");","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_group_smoking_age = train_0.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)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_0_sex = pd.get_dummies(train_0.Sex, prefix='Sex')\ntrain_0_smoking= pd.get_dummies(train_0.SmokingStatus, prefix='SmokingStatus')\ntrain_0 = pd.concat([train_0, train_0_sex, train_0_smoking], axis = 1)\ntrain_0.head()","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"corrMatrix = train_0.iloc[:, 2:].corr()\nsns.heatmap(corrMatrix, annot=True)","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}