{"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":"6dff72ff-ea2f-46fd-aec3-754ca2a6e87e","_cell_guid":"e01757ec-d3f5-466e-9b9c-fa0fc2033663","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:07:31.645373Z","iopub.execute_input":"2023-01-09T20:07:31.645846Z","iopub.status.idle":"2023-01-09T20:07:32.181055Z","shell.execute_reply.started":"2023-01-09T20:07:31.645809Z","shell.execute_reply":"2023-01-09T20:07:32.178930Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory = '/kaggle/input/osic-pulmonary-fibrosis-progression'\ntrain_df = pd.read_csv(directory + '/train.csv')\ntest_df = pd.read_csv(directory + '/test.csv')\n\nIMAGE_PATH = \"../input/osic-pulmonary-fibrosis-progressiont/\"","metadata":{"_uuid":"60357591-b57c-488e-8364-33c17c4708fb","_cell_guid":"932c8399-d6a9-4a36-afcf-fbd76954538c","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:07:45.276124Z","iopub.execute_input":"2023-01-09T20:07:45.277100Z","iopub.status.idle":"2023-01-09T20:07:45.300544Z","shell.execute_reply.started":"2023-01-09T20:07:45.277064Z","shell.execute_reply":"2023-01-09T20:07:45.299050Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"_uuid":"5fcfbcd3-81ad-41ae-b76b-ba881ddf1cf9","_cell_guid":"5e9dd54e-3b0c-4aae-b23d-4d12806fee9e","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:07:47.426082Z","iopub.execute_input":"2023-01-09T20:07:47.426504Z","iopub.status.idle":"2023-01-09T20:07:47.443123Z","shell.execute_reply.started":"2023-01-09T20:07:47.426469Z","shell.execute_reply":"2023-01-09T20:07:47.441588Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['Patient'].nunique()","metadata":{"_uuid":"24d99f47-2553-425f-b04d-299812745ba8","_cell_guid":"bd21740f-bc96-4027-8085-a0816d62ed42","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:46:31.889445Z","iopub.execute_input":"2023-01-09T17:46:31.890877Z","iopub.status.idle":"2023-01-09T17:46:31.910421Z","shell.execute_reply.started":"2023-01-09T17:46:31.890718Z","shell.execute_reply":"2023-01-09T17:46:31.907205Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"_uuid":"c95cce98-f9be-497b-bee0-eee0eb0a31cc","_cell_guid":"babcba6c-5075-4aaa-bbca-c5b5b9a73cbf","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:28.171301Z","iopub.execute_input":"2023-01-09T20:08:28.171710Z","iopub.status.idle":"2023-01-09T20:08:28.198709Z","shell.execute_reply.started":"2023-01-09T20:08:28.171660Z","shell.execute_reply":"2023-01-09T20:08:28.196752Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Patient'].nunique()","metadata":{"_uuid":"42f04456-94e4-49b7-9479-c4dc93de0ddf","_cell_guid":"b7e13c68-5963-4e15-a8e1-0e88f30b8a56","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:30.730907Z","iopub.execute_input":"2023-01-09T20:08:30.731313Z","iopub.status.idle":"2023-01-09T20:08:30.755446Z","shell.execute_reply.started":"2023-01-09T20:08:30.731284Z","shell.execute_reply":"2023-01-09T20:08:30.752830Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().mean()","metadata":{"_uuid":"02f3f4ae-c79d-48fb-9cbc-728c1b566c5c","_cell_guid":"c225d333-f452-4072-aba6-6f3959718d1b","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:32.718863Z","iopub.execute_input":"2023-01-09T20:08:32.719404Z","iopub.status.idle":"2023-01-09T20:08:32.731841Z","shell.execute_reply.started":"2023-01-09T20:08:32.719360Z","shell.execute_reply":"2023-01-09T20:08:32.730276Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/sample_submission.csv')\nsample_submission","metadata":{"_uuid":"d3327959-b7f3-4e77-b35f-e1f436706ef7","_cell_guid":"14bc0c2f-aac1-4f30-be54-e29970da4fc9","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:34.429537Z","iopub.execute_input":"2023-01-09T20:08:34.429940Z","iopub.status.idle":"2023-01-09T20:08:34.454232Z","shell.execute_reply.started":"2023-01-09T20:08:34.429911Z","shell.execute_reply":"2023-01-09T20:08:34.451400Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nlen(list(Path(directory+'/train/').rglob(\"*\")))","metadata":{"_uuid":"a1e5b149-5987-4e76-a1bc-8b0b1bcc8461","_cell_guid":"9b383f6d-df8e-4929-a9c6-b3cd3d5df4fb","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:37.458142Z","iopub.execute_input":"2023-01-09T20:08:37.458590Z","iopub.status.idle":"2023-01-09T20:08:38.336464Z","shell.execute_reply.started":"2023-01-09T20:08:37.458561Z","shell.execute_reply":"2023-01-09T20:08:38.334490Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nlen(list(Path(directory+'/test/').rglob(\"*\")))","metadata":{"_uuid":"9953bc10-7385-42c9-981b-8e3ce4519d8a","_cell_guid":"cb7fa83e-b4c5-4d0f-a75f-d0bcce4a6535","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:39.674513Z","iopub.execute_input":"2023-01-09T20:08:39.675569Z","iopub.status.idle":"2023-01-09T20:08:39.706077Z","shell.execute_reply.started":"2023-01-09T20:08:39.675497Z","shell.execute_reply":"2023-01-09T20:08:39.705074Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"_uuid":"bfb4e211-23b3-4534-9261-140879d7a134","_cell_guid":"99fa396d-182a-432d-a0a2-364cd34d0be2","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:08:41.788873Z","iopub.execute_input":"2023-01-09T20:08:41.789473Z","iopub.status.idle":"2023-01-09T20:08:41.796167Z","shell.execute_reply.started":"2023-01-09T20:08:41.789442Z","shell.execute_reply":"2023-01-09T20:08:41.794850Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Weeks'].hist(bins=80)","metadata":{"_uuid":"94795140-9a18-4851-bf77-120a7f5c2915","_cell_guid":"a6b55bc5-7244-415a-afdc-c6cd91f7b1de","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:06.577111Z","iopub.execute_input":"2023-01-09T17:47:06.577515Z","iopub.status.idle":"2023-01-09T17:47:07.028912Z","shell.execute_reply.started":"2023-01-09T17:47:06.577481Z","shell.execute_reply":"2023-01-09T17:47:07.027692Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Weeks'].describe()","metadata":{"_uuid":"a7e6b099-9422-4fa8-883e-68d45d5f99a2","_cell_guid":"c19122e0-91be-4f70-a3b9-debad7429e95","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:09.061404Z","iopub.execute_input":"2023-01-09T17:47:09.061854Z","iopub.status.idle":"2023-01-09T17:47:09.077491Z","shell.execute_reply.started":"2023-01-09T17:47:09.061819Z","shell.execute_reply":"2023-01-09T17:47:09.076490Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Age'].hist(bins=40)","metadata":{"_uuid":"25126aad-cb7c-4edd-b01f-5fba774b156b","_cell_guid":"591ad352-aac7-4c74-bfcd-ff85a8658179","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:10.952759Z","iopub.execute_input":"2023-01-09T17:47:10.953135Z","iopub.status.idle":"2023-01-09T17:47:11.275119Z","shell.execute_reply.started":"2023-01-09T17:47:10.953105Z","shell.execute_reply":"2023-01-09T17:47:11.273550Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Sex'].hist(bins=10)","metadata":{"_uuid":"79b9aae6-b2e1-44e0-9541-1b593ce4f375","_cell_guid":"78f9216d-882d-4f7c-a71a-e83d44591c9b","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:13.333172Z","iopub.execute_input":"2023-01-09T17:47:13.333568Z","iopub.status.idle":"2023-01-09T17:47:13.564346Z","shell.execute_reply.started":"2023-01-09T17:47:13.333538Z","shell.execute_reply":"2023-01-09T17:47:13.562973Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['SmokingStatus'].hist(bins=10)","metadata":{"_uuid":"efb85b7a-f984-4e6d-8ee1-62ca416a1ae2","_cell_guid":"3aee0665-2e5c-47f7-bc41-49ddacdab0cc","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:15.650867Z","iopub.execute_input":"2023-01-09T17:47:15.651422Z","iopub.status.idle":"2023-01-09T17:47:15.887821Z","shell.execute_reply.started":"2023-01-09T17:47:15.651380Z","shell.execute_reply":"2023-01-09T17:47:15.886398Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['SmokingStatus'].describe()","metadata":{"_uuid":"2d484bb8-d81b-4891-b6ff-c5f6b34c6ce2","_cell_guid":"075a0501-ab68-4cd8-a11e-17bffb4b8434","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:17.589999Z","iopub.execute_input":"2023-01-09T17:47:17.590567Z","iopub.status.idle":"2023-01-09T17:47:17.605937Z","shell.execute_reply.started":"2023-01-09T17:47:17.590526Z","shell.execute_reply":"2023-01-09T17:47:17.604726Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['FVC'].hist(bins=80)","metadata":{"_uuid":"9f8adcf9-3097-47c8-9cf7-e1197f9780a6","_cell_guid":"32935e35-69c3-41e5-bd23-3750358b5c2f","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:19.248040Z","iopub.execute_input":"2023-01-09T17:47:19.248984Z","iopub.status.idle":"2023-01-09T17:47:19.686359Z","shell.execute_reply.started":"2023-01-09T17:47:19.248930Z","shell.execute_reply":"2023-01-09T17:47:19.685177Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['FVC'].describe()","metadata":{"_uuid":"a2b0ac70-11e1-49b6-b432-5a42639a3311","_cell_guid":"b8a995e1-cef0-4210-b7e4-cafc00a56d6f","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:21.638383Z","iopub.execute_input":"2023-01-09T17:47:21.639819Z","iopub.status.idle":"2023-01-09T17:47:21.652041Z","shell.execute_reply.started":"2023-01-09T17:47:21.639751Z","shell.execute_reply":"2023-01-09T17:47:21.650697Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('SmokingStatus')['Age'].median().plot()","metadata":{"_uuid":"6e058106-c7e9-4209-a185-317fcf4f6f51","_cell_guid":"564e62e6-f522-44b7-82f3-0a51e88b4c8e","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:23.484718Z","iopub.execute_input":"2023-01-09T17:47:23.485166Z","iopub.status.idle":"2023-01-09T17:47:23.732000Z","shell.execute_reply.started":"2023-01-09T17:47:23.485131Z","shell.execute_reply":"2023-01-09T17:47:23.730701Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('SmokingStatus')['Age'].hist(bins=10,histtype='step')","metadata":{"_uuid":"1ae38789-5860-41de-9266-d04a4d41bf5d","_cell_guid":"c8da4fb6-0835-4001-ae36-768fd843d77c","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:26.183539Z","iopub.execute_input":"2023-01-09T17:47:26.184712Z","iopub.status.idle":"2023-01-09T17:47:26.379144Z","shell.execute_reply.started":"2023-01-09T17:47:26.184658Z","shell.execute_reply":"2023-01-09T17:47:26.377943Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('Sex')['Age'].hist(bins=10,histtype='step')","metadata":{"_uuid":"77ca7e88-1888-493d-b176-059c1e9ed4c4","_cell_guid":"92093476-5316-4a97-9b3e-949187fa5218","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:28.712105Z","iopub.execute_input":"2023-01-09T17:47:28.712554Z","iopub.status.idle":"2023-01-09T17:47:29.072706Z","shell.execute_reply.started":"2023-01-09T17:47:28.712518Z","shell.execute_reply":"2023-01-09T17:47:29.071204Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby('SmokingStatus')['Percent'].agg(['max','min']).plot()","metadata":{"_uuid":"b8c96c34-e093-4c68-af2e-f7a584a16831","_cell_guid":"24f50215-2544-40ff-889e-08b9a80d94f8","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:30.778499Z","iopub.execute_input":"2023-01-09T17:47:30.778923Z","iopub.status.idle":"2023-01-09T17:47:31.065047Z","shell.execute_reply.started":"2023-01-09T17:47:30.778889Z","shell.execute_reply":"2023-01-09T17:47:31.063955Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from typing import Dict\n\ndef extract_dicom_meta_data(filename: str) -> Dict:\n    # Load image\n    \n    image_data = pydicom.read_file(filename)\n    img=np.array(image_data.pixel_array).flatten()\n    row = {\n        'Patient': image_data.PatientID,\n        'body_part_examined': image_data.BodyPartExamined,\n        'image_position_patient': image_data.ImagePositionPatient,\n        'image_orientation_patient': image_data.ImageOrientationPatient,\n        'photometric_interpretation': image_data.PhotometricInterpretation,\n        'rows': image_data.Rows,\n        'columns': image_data.Columns,\n        'pixel_spacing': image_data.PixelSpacing,\n        'window_center': image_data.WindowCenter,\n        'window_width': image_data.WindowWidth,\n        'modality': image_data.Modality,\n        'StudyInstanceUID': image_data.StudyInstanceUID,\n        'SeriesInstanceUID': image_data.StudyInstanceUID,\n        'StudyID': image_data.StudyInstanceUID, \n        'SamplesPerPixel': image_data.SamplesPerPixel,\n        'BitsAllocated': image_data.BitsAllocated,\n        'BitsStored': image_data.BitsStored,\n        'HighBit': image_data.HighBit,\n        'PixelRepresentation': image_data.PixelRepresentation,\n        'RescaleIntercept': image_data.RescaleIntercept,\n        'RescaleSlope': image_data.RescaleSlope,\n        'img_min': np.min(img),\n        'img_max': np.max(img),\n        'img_mean': np.mean(img),\n        'img_std': np.std(img)}\n\n    return row","metadata":{"_uuid":"86c9a2f6-ccd3-4952-9b06-f6207ddc6e0f","_cell_guid":"92625331-80b5-45e4-83df-40839e3f1451","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:33.317001Z","iopub.execute_input":"2023-01-09T17:47:33.317817Z","iopub.status.idle":"2023-01-09T17:47:33.328826Z","shell.execute_reply.started":"2023-01-09T17:47:33.317764Z","shell.execute_reply":"2023-01-09T17:47:33.327621Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nimport tqdm \nimport pydicom\n\ntrain_image_path = '/kaggle/input/osic-pulmonary-fibrosis-progression/train'\ntrain_image_files = glob.glob(os.path.join(train_image_path, '*', '*.dcm'))\n\nmeta_data_df = []\nfor filename in tqdm.tqdm(train_image_files):\n    try:\n        meta_data_df.append(extract_dicom_meta_data(filename))\n    except Exception as e:\n        print(e)\n        continue","metadata":{"_uuid":"abf601e8-dcd2-433e-8cdd-2b0ead730022","_cell_guid":"2ba19770-b111-4093-8c44-18c7befc0242","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T17:47:36.106881Z","iopub.execute_input":"2023-01-09T17:47:36.107380Z","iopub.status.idle":"2023-01-09T18:00:00.238440Z","shell.execute_reply.started":"2023-01-09T17:47:36.107341Z","shell.execute_reply":"2023-01-09T18:00:00.236793Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta_data_df = pd.DataFrame.from_dict(meta_data_df)\nmeta_data_df","metadata":{"_uuid":"6502c535-565a-41e7-9d17-ba6cb222dc2d","_cell_guid":"ffed24c7-8baf-4c94-aad6-92146add5b27","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:00:21.768750Z","iopub.execute_input":"2023-01-09T18:00:21.769226Z","iopub.status.idle":"2023-01-09T18:00:22.257223Z","shell.execute_reply.started":"2023-01-09T18:00:21.769180Z","shell.execute_reply":"2023-01-09T18:00:22.255681Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(f\"/kaggle/input/osic-pulmonary-fibrosis-progression/train.csv\")\ntrain_df.drop_duplicates(keep=False, inplace=True, subset=['Patient','Weeks'])\ntest_df = pd.read_csv(f\"/kaggle/input/osic-pulmonary-fibrosis-progression/test.csv\")\nsub_df = pd.read_csv(f\"/kaggle/input/osic-pulmonary-fibrosis-progression/sample_submission.csv\")\nsub_df['Patient'] = sub_df['Patient_Week'].apply(lambda x:x.split('_')[0])\nsub_df['Weeks'] = sub_df['Patient_Week'].apply(lambda x: int(x.split('_')[-1]))\nsub_df = sub_df[['Patient','Weeks','Confidence','Patient_Week']]\nsub_df = sub_df.merge(sub_df.drop('Weeks', axis=1), on=\"Patient\")","metadata":{"_uuid":"d2e67e5b-d97e-4087-b018-a4a9f09b6571","_cell_guid":"0fbd4a09-fea4-4926-8373-824a3e2e9b53","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:04:35.966137Z","iopub.execute_input":"2023-01-09T18:04:35.966846Z","iopub.status.idle":"2023-01-09T18:04:36.013641Z","shell.execute_reply.started":"2023-01-09T18:04:35.966806Z","shell.execute_reply":"2023-01-09T18:04:36.012094Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head(),test_df.head()","metadata":{"_uuid":"3051dcfe-fb3f-48a3-85a4-8e1c6564fd77","_cell_guid":"8aff2acf-8a54-4c7d-a422-3f5403998b41","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:04:55.516856Z","iopub.execute_input":"2023-01-09T18:04:55.517427Z","iopub.status.idle":"2023-01-09T18:04:55.537578Z","shell.execute_reply.started":"2023-01-09T18:04:55.517389Z","shell.execute_reply":"2023-01-09T18:04:55.535992Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_pixel_array(dataset, figsize=(5,5)):\n    plt.figure(figsize=figsize)\n    plt.grid(False)\n    plt.imshow(dataset.pixel_array, cmap='gray') # cmap=plt.cm.bone)\n    plt.show()","metadata":{"_uuid":"a7391fd4-0c69-4f22-851d-98acdfd13078","_cell_guid":"ba5e1924-2fa7-4a76-8430-45b27d606858","collapsed":false,"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imdir = \"/kaggle/input/osic-pulmonary-fibrosis-progression/train/ID00123637202217151272140\"\nprint(\"total images for patient ID00123637202217151272140: \", len(os.listdir(imdir)))\nfig=plt.figure(figsize=(12, 12))\ncolumns = 4\nrows = 5\nimglist = os.listdir(imdir)\nfor i in range(1, columns*rows +1):\n    filename = imdir + \"/\" + str(i) + \".dcm\"\n    ds = pydicom.dcmread(filename)\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(ds.pixel_array, cmap='gray')\nplt.show()","metadata":{"_uuid":"79936c26-243d-4c48-8534-b4cd9aaedd60","_cell_guid":"766996ae-28a1-4a0e-ae14-91ecace5f55a","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:06:13.915704Z","iopub.execute_input":"2023-01-09T18:06:13.916203Z","iopub.status.idle":"2023-01-09T18:06:16.613702Z","shell.execute_reply.started":"2023-01-09T18:06:13.916167Z","shell.execute_reply":"2023-01-09T18:06:16.612397Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imdir = \"/kaggle/input/osic-pulmonary-fibrosis-progression/train/ID00123637202217151272140\"\nprint(\"total images for patient ID00123637202217151272140: \", len(os.listdir(imdir)))\nfig=plt.figure(figsize=(12, 12))\ncolumns = 4\nrows = 5\nimglist = os.listdir(imdir)\nfor i in range(1, columns*rows +1):\n    filename = imdir + \"/\" + str(i) + \".dcm\"\n    ds = pydicom.dcmread(filename)\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(ds.pixel_array, cmap='jet')\nplt.show()","metadata":{"_uuid":"60335c2b-da7a-4ad4-98d4-ef7f918b25d1","_cell_guid":"959260a3-67f9-4d7b-8f58-bfde5ffd7bd7","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:07:09.614962Z","iopub.execute_input":"2023-01-09T18:07:09.615425Z","iopub.status.idle":"2023-01-09T18:07:12.221266Z","shell.execute_reply.started":"2023-01-09T18:07:09.615387Z","shell.execute_reply":"2023-01-09T18:07:12.219769Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta_data_df.isna().sum()","metadata":{"_uuid":"14a08f62-123d-44f4-8f77-67fcae705754","_cell_guid":"b585cc79-cb22-46fa-9643-e116708fb4e7","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:07:28.142187Z","iopub.execute_input":"2023-01-09T18:07:28.142654Z","iopub.status.idle":"2023-01-09T18:07:28.245179Z","shell.execute_reply.started":"2023-01-09T18:07:28.142605Z","shell.execute_reply":"2023-01-09T18:07:28.243799Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head(10)","metadata":{"_uuid":"455436f0-2ace-4691-bcc9-49e2e5c4b841","_cell_guid":"0e95e528-4db9-408d-be3c-c7ba7c8d1842","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T20:09:16.155801Z","iopub.execute_input":"2023-01-09T20:09:16.156220Z","iopub.status.idle":"2023-01-09T20:09:16.175626Z","shell.execute_reply.started":"2023-01-09T20:09:16.156192Z","shell.execute_reply":"2023-01-09T20:09:16.173461Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"_uuid":"25573585-edfc-47e8-b925-e247fbf83b98","_cell_guid":"c3f6125e-49da-45d1-9d4e-fa48cb80e6b4","collapsed":false,"execution":{"iopub.status.busy":"2023-01-09T18:50:22.823279Z","iopub.execute_input":"2023-01-09T18:50:22.823817Z","iopub.status.idle":"2023-01-09T18:50:23.027100Z","shell.execute_reply.started":"2023-01-09T18:50:22.823764Z","shell.execute_reply":"2023-01-09T18:50:23.025800Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"_uuid":"b49b6977-9136-4bef-87e4-6c62fdc00b20","_cell_guid":"9808a6e0-f54e-4de8-8eb5-320b402dbffd","collapsed":false,"execution":{"iopub.status.busy":"2022-12-13T07:50:41.762661Z","iopub.execute_input":"2022-12-13T07:50:41.763195Z","iopub.status.idle":"2022-12-13T07:50:41.790983Z","shell.execute_reply.started":"2022-12-13T07:50:41.763155Z","shell.execute_reply":"2022-12-13T07:50:41.789062Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"_uuid":"d72512d9-0a7d-44d0-9f87-04b4882dc1ce","_cell_guid":"ff01b3ee-d54d-4e78-8217-ed43519b38e5","collapsed":false,"execution":{"iopub.status.busy":"2022-12-07T17:02:08.218182Z","iopub.execute_input":"2022-12-07T17:02:08.218568Z","iopub.status.idle":"2022-12-07T17:02:08.242789Z","shell.execute_reply.started":"2022-12-07T17:02:08.218517Z","shell.execute_reply":"2022-12-07T17:02:08.241502Z"},"jupyter":{"outputs_hidden":false},"trusted":true},"execution_count":null,"outputs":[]}]}