{"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_minor":4,"nbformat":4,"cells":[{"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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-15T16:52:14.978095Z","iopub.execute_input":"2022-11-15T16:52:14.978572Z","iopub.status.idle":"2022-11-15T16:52:15.523234Z","shell.execute_reply.started":"2022-11-15T16:52:14.978537Z","shell.execute_reply":"2022-11-15T16:52:15.521994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nimport plotly.express as px\nimport plotly.graph_objs as go\n\nimport pydicom\nimport glob\nimport imageio\nfrom IPython.display import Image","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:13:30.052396Z","iopub.execute_input":"2022-11-15T16:13:30.052826Z","iopub.status.idle":"2022-11-15T16:13:30.061370Z","shell.execute_reply.started":"2022-11-15T16:13:30.052790Z","shell.execute_reply":"2022-11-15T16:13:30.060122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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')","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:13:37.334283Z","iopub.execute_input":"2022-11-15T16:13:37.334693Z","iopub.status.idle":"2022-11-15T16:13:37.363695Z","shell.execute_reply.started":"2022-11-15T16:13:37.334660Z","shell.execute_reply":"2022-11-15T16:13:37.362685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:13:42.541449Z","iopub.execute_input":"2022-11-15T16:13:42.541860Z","iopub.status.idle":"2022-11-15T16:13:42.574830Z","shell.execute_reply.started":"2022-11-15T16:13:42.541827Z","shell.execute_reply":"2022-11-15T16:13:42.573470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:13:52.734831Z","iopub.execute_input":"2022-11-15T16:13:52.735432Z","iopub.status.idle":"2022-11-15T16:13:52.763564Z","shell.execute_reply.started":"2022-11-15T16:13:52.735386Z","shell.execute_reply":"2022-11-15T16:13:52.762351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().mean()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:01.296016Z","iopub.execute_input":"2022-11-15T16:14:01.296440Z","iopub.status.idle":"2022-11-15T16:14:01.310370Z","shell.execute_reply.started":"2022-11-15T16:14:01.296407Z","shell.execute_reply":"2022-11-15T16:14:01.308983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age'].hist(bins=50)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:09.096750Z","iopub.execute_input":"2022-11-15T16:14:09.097697Z","iopub.status.idle":"2022-11-15T16:14:09.455984Z","shell.execute_reply.started":"2022-11-15T16:14:09.097641Z","shell.execute_reply":"2022-11-15T16:14:09.454098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:15.480653Z","iopub.execute_input":"2022-11-15T16:14:15.481146Z","iopub.status.idle":"2022-11-15T16:14:15.496815Z","shell.execute_reply.started":"2022-11-15T16:14:15.481109Z","shell.execute_reply":"2022-11-15T16:14:15.495234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('Age')['Weeks'].agg(['count','mean','median'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:23.018213Z","iopub.execute_input":"2022-11-15T16:14:23.019721Z","iopub.status.idle":"2022-11-15T16:14:23.045823Z","shell.execute_reply.started":"2022-11-15T16:14:23.019669Z","shell.execute_reply":"2022-11-15T16:14:23.044847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('Age')['Weeks'].median().plot()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:32.024933Z","iopub.execute_input":"2022-11-15T16:14:32.025407Z","iopub.status.idle":"2022-11-15T16:14:32.243509Z","shell.execute_reply.started":"2022-11-15T16:14:32.025370Z","shell.execute_reply":"2022-11-15T16:14:32.242239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:38.114533Z","iopub.execute_input":"2022-11-15T16:14:38.114977Z","iopub.status.idle":"2022-11-15T16:14:38.128318Z","shell.execute_reply.started":"2022-11-15T16:14:38.114940Z","shell.execute_reply":"2022-11-15T16:14:38.127107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age_pred_mean'] = train_df['Age'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:44.346265Z","iopub.execute_input":"2022-11-15T16:14:44.346751Z","iopub.status.idle":"2022-11-15T16:14:44.354123Z","shell.execute_reply.started":"2022-11-15T16:14:44.346710Z","shell.execute_reply":"2022-11-15T16:14:44.352821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:48.205430Z","iopub.execute_input":"2022-11-15T16:14:48.205990Z","iopub.status.idle":"2022-11-15T16:14:48.228773Z","shell.execute_reply.started":"2022-11-15T16:14:48.205942Z","shell.execute_reply":"2022-11-15T16:14:48.227268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['err'] = train_df['Age'] - train_df['Age_pred_mean']","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:54.360885Z","iopub.execute_input":"2022-11-15T16:14:54.361374Z","iopub.status.idle":"2022-11-15T16:14:54.369390Z","shell.execute_reply.started":"2022-11-15T16:14:54.361335Z","shell.execute_reply":"2022-11-15T16:14:54.367895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:14:58.789029Z","iopub.execute_input":"2022-11-15T16:14:58.789968Z","iopub.status.idle":"2022-11-15T16:14:58.814697Z","shell.execute_reply.started":"2022-11-15T16:14:58.789917Z","shell.execute_reply":"2022-11-15T16:14:58.813220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['err_abs'] = abs(train_df['err'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:07.875381Z","iopub.execute_input":"2022-11-15T16:15:07.876273Z","iopub.status.idle":"2022-11-15T16:15:07.884052Z","shell.execute_reply.started":"2022-11-15T16:15:07.876219Z","shell.execute_reply":"2022-11-15T16:15:07.882919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['err_abs'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:12.612786Z","iopub.execute_input":"2022-11-15T16:15:12.613274Z","iopub.status.idle":"2022-11-15T16:15:12.624367Z","shell.execute_reply.started":"2022-11-15T16:15:12.613232Z","shell.execute_reply":"2022-11-15T16:15:12.622752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['err_abs_pct'] = train_df['err_abs'] / train_df['Age']","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:17.922440Z","iopub.execute_input":"2022-11-15T16:15:17.922936Z","iopub.status.idle":"2022-11-15T16:15:17.930358Z","shell.execute_reply.started":"2022-11-15T16:15:17.922880Z","shell.execute_reply":"2022-11-15T16:15:17.928721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['err_abs_pct'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:23.786863Z","iopub.execute_input":"2022-11-15T16:15:23.787378Z","iopub.status.idle":"2022-11-15T16:15:23.795926Z","shell.execute_reply.started":"2022-11-15T16:15:23.787340Z","shell.execute_reply":"2022-11-15T16:15:23.794991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age_pred_median'] = train_df['Age'].median()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:29.274223Z","iopub.execute_input":"2022-11-15T16:15:29.274703Z","iopub.status.idle":"2022-11-15T16:15:29.283151Z","shell.execute_reply.started":"2022-11-15T16:15:29.274666Z","shell.execute_reply":"2022-11-15T16:15:29.281755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:32.611341Z","iopub.execute_input":"2022-11-15T16:15:32.612171Z","iopub.status.idle":"2022-11-15T16:15:32.639847Z","shell.execute_reply.started":"2022-11-15T16:15:32.612131Z","shell.execute_reply":"2022-11-15T16:15:32.638343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error, mean_absolute_percentage_error","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:41.751440Z","iopub.execute_input":"2022-11-15T16:15:41.751857Z","iopub.status.idle":"2022-11-15T16:15:42.111055Z","shell.execute_reply.started":"2022-11-15T16:15:41.751813Z","shell.execute_reply":"2022-11-15T16:15:42.109768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_error(train_df['Age'],train_df['Age_pred_mean'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:46.848060Z","iopub.execute_input":"2022-11-15T16:15:46.849639Z","iopub.status.idle":"2022-11-15T16:15:46.858448Z","shell.execute_reply.started":"2022-11-15T16:15:46.849589Z","shell.execute_reply":"2022-11-15T16:15:46.857306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_percentage_error(train_df['Age'],train_df['Age_pred_mean'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:50.968252Z","iopub.execute_input":"2022-11-15T16:15:50.968760Z","iopub.status.idle":"2022-11-15T16:15:50.978329Z","shell.execute_reply.started":"2022-11-15T16:15:50.968720Z","shell.execute_reply":"2022-11-15T16:15:50.977014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_error(train_df['Age'],train_df['Age_pred_median'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:15:55.577519Z","iopub.execute_input":"2022-11-15T16:15:55.577991Z","iopub.status.idle":"2022-11-15T16:15:55.587705Z","shell.execute_reply.started":"2022-11-15T16:15:55.577952Z","shell.execute_reply":"2022-11-15T16:15:55.586676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_percentage_error(train_df['Age'],train_df['Age_pred_median'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:03.012093Z","iopub.execute_input":"2022-11-15T16:16:03.012590Z","iopub.status.idle":"2022-11-15T16:16:03.021938Z","shell.execute_reply.started":"2022-11-15T16:16:03.012549Z","shell.execute_reply":"2022-11-15T16:16:03.020975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:10.027886Z","iopub.execute_input":"2022-11-15T16:16:10.029299Z","iopub.status.idle":"2022-11-15T16:16:10.044484Z","shell.execute_reply.started":"2022-11-15T16:16:10.029250Z","shell.execute_reply":"2022-11-15T16:16:10.043119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['Age_pred_median'] = train_df['Age'].median()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:16.238543Z","iopub.execute_input":"2022-11-15T16:16:16.239274Z","iopub.status.idle":"2022-11-15T16:16:16.248051Z","shell.execute_reply.started":"2022-11-15T16:16:16.239219Z","shell.execute_reply":"2022-11-15T16:16:16.246936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:20.717611Z","iopub.execute_input":"2022-11-15T16:16:20.718105Z","iopub.status.idle":"2022-11-15T16:16:20.734419Z","shell.execute_reply.started":"2022-11-15T16:16:20.718069Z","shell.execute_reply":"2022-11-15T16:16:20.733249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_error(test_df['Age'],test_df['Age_pred_median'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:26.210924Z","iopub.execute_input":"2022-11-15T16:16:26.211347Z","iopub.status.idle":"2022-11-15T16:16:26.224188Z","shell.execute_reply.started":"2022-11-15T16:16:26.211314Z","shell.execute_reply":"2022-11-15T16:16:26.222839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_absolute_percentage_error(test_df['Age'],test_df['Age_pred_median'])","metadata":{"execution":{"iopub.status.busy":"2022-11-15T16:16:31.180595Z","iopub.execute_input":"2022-11-15T16:16:31.181085Z","iopub.status.idle":"2022-11-15T16:16:31.189475Z","shell.execute_reply.started":"2022-11-15T16:16:31.181048Z","shell.execute_reply":"2022-11-15T16:16:31.188442Z"},"trusted":true},"execution_count":null,"outputs":[]}]}