{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport matplotlib.pyplot as plt\nplt.style.use(\"seaborn-whitegrid\")\n\nimport seaborn as sns\n\nfrom collections import Counter\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(\"../input/osic-pulmonary-fibrosis-progression/train.csv\")\ntest_df = pd.read_csv(\"../input/osic-pulmonary-fibrosis-progression/test.csv\")\ntest_Patient = test_df[\"Patient\"]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.isna().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[\"Sex\"] = [1 if i == \"Male\" else 0 for i in train_df[\"Sex\"]]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nlabelEncoder_Y=LabelEncoder()\ntrain_df.iloc[:,6]=labelEncoder_Y.fit_transform(train_df.iloc[:,6].values)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def plot_hist(variable):\n    plt.figure(figsize = (9,3))\n    plt.hist(train_df[variable], bins = 50)\n    plt.xlabel(variable)\n    plt.ylabel(\"Frequency\")\n    plt.title(\"{} distribution with hist\".format(variable))\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"numericVar = [\"Age\", \"Sex\",\"SmokingStatus\",\"Percent\",\"FVC\"]\nfor n in numericVar:\n    plot_hist(n)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"\n\n# Basic Data Analysis\n1. SmokingStatus vs FVC\n2. Sex vs FVC\n3. Age vs FVC\n4. Percent vs FVC\n","execution_count":null},{"metadata":{},"cell_type":"raw","source":"train_df.columns","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# SmokingStatus vs FVC\ntrain_df[[\"SmokingStatus\",\"FVC\"]].groupby([\"SmokingStatus\"], as_index = False).mean().sort_values(by=\"FVC\",ascending = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Sex vs FVC\ntrain_df[[\"Sex\",\"FVC\"]].groupby([\"Sex\"], as_index = False).mean().sort_values(by=\"FVC\",ascending = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Age vs FVC\ntrain_df[[\"Age\",\"FVC\"]].groupby([\"Age\"], as_index = False).mean().sort_values(by=\"FVC\",ascending = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Percent vs FVC\ntrain_df[[\"Percent\",\"FVC\"]].groupby([\"Percent\"], as_index = False).mean().sort_values(by=\"FVC\",ascending = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_len = len(train_df)\ntrain_df = pd.concat([train_df,test_df],axis = 0).reset_index(drop = True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualization","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"list1 = [\"Age\", \"Sex\", \"SmokingStatus\", \"FVC\",\"Percent\"]\nsns.heatmap(train_df[list1].corr(), annot = True, fmt = \".2f\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Sex - FVC","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"g = sns.factorplot(x = \"Sex\", y = \"FVC\", data = train_df, kind = \"bar\", size = 6)\ng.set_ylabels(\"FVC Probability\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Age - FVC","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"g = sns.factorplot(x = \"Age\", y = \"FVC\", data = train_df, kind = \"bar\", size = 7)\ng.set_ylabels(\"FVC Probability\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Smoking Status - FVC","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"g = sns.factorplot(x = \"SmokingStatus\", y = \"FVC\", data = train_df, kind = \"bar\", size = 6)\ng.set_ylabels(\"FVC Probability\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"g = sns.FacetGrid(train_df, col = \"Sex\", row = \"SmokingStatus\", size = 2)\ng.map(plt.hist, \"Age\", bins = 20)\ng.add_legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.factorplot(x = \"Sex\", y = \"Age\", data = train_df, kind = \"box\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.factorplot(x = \"Sex\", y = \"Age\", hue = \"SmokingStatus\",data = train_df, kind = \"box\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[\"SmokingStatus\"] = train_df[\"SmokingStatus\"].astype(\"category\")\ntrain_df = pd.get_dummies(train_df, columns= [\"SmokingStatus\"])\ntrain_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[\"Sex\"] = train_df[\"Sex\"].astype(\"category\")\ntrain_df = pd.get_dummies(train_df, columns=[\"Sex\"])\ntrain_df.head()","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}