{"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":"import pydicom as dicom\nimport matplotlib.pyplot as plt\nimport os\nimport cv2\nimport PIL\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport csv\nimport shutil\nfrom torch.utils.data import Dataset\nfrom PIL import Image\nimport torch\nplt.rcParams[\"figure.figsize\"] = (8, 8)\nsns.set_theme(style=\"ticks\", palette=\"bright\")","metadata":{"execution":{"iopub.status.busy":"2022-12-30T11:13:49.429065Z","iopub.execute_input":"2022-12-30T11:13:49.429441Z","iopub.status.idle":"2022-12-30T11:13:49.437296Z","shell.execute_reply.started":"2022-12-30T11:13:49.42941Z","shell.execute_reply":"2022-12-30T11:13:49.43641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#viewing a dicom image\nfig = plt.figure(figsize=(8, 8))\nimage_path = '/kaggle/input/rsna-breast-cancer-detection/train_images/10011/1031443799.dcm'\nds = dicom.dcmread(image_path)\nplt.imshow(ds.pixel_array,cmap='bone')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:58:52.679368Z","iopub.execute_input":"2022-12-30T10:58:52.67977Z","iopub.status.idle":"2022-12-30T10:58:54.186928Z","shell.execute_reply.started":"2022-12-30T10:58:52.679739Z","shell.execute_reply":"2022-12-30T10:58:54.185645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:58:57.534823Z","iopub.execute_input":"2022-12-30T10:58:57.535274Z","iopub.status.idle":"2022-12-30T10:58:57.64906Z","shell.execute_reply.started":"2022-12-30T10:58:57.535236Z","shell.execute_reply":"2022-12-30T10:58:57.647893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Details in Data\nunique_patients = train_data.patient_id.unique()\nprint(len(unique_patients))\npath = \"/kaggle/input/rsna-breast-cancer-detection/train_images\"","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:58:59.099728Z","iopub.execute_input":"2022-12-30T10:58:59.100736Z","iopub.status.idle":"2022-12-30T10:58:59.113734Z","shell.execute_reply.started":"2022-12-30T10:58:59.100688Z","shell.execute_reply":"2022-12-30T10:58:59.112191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* There are 11913 unique patient ids.","metadata":{}},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:01.60729Z","iopub.execute_input":"2022-12-30T10:59:01.607705Z","iopub.status.idle":"2022-12-30T10:59:01.642626Z","shell.execute_reply.started":"2022-12-30T10:59:01.607673Z","shell.execute_reply":"2022-12-30T10:59:01.641317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def add_img_path():\n    paths = []\n    patient_id = train_data[\"patient_id\"].astype(str)\n    image_id = train_data[\"image_id\"].astype(str)\n    for pid,imid in zip(patient_id,image_id):\n        paths.append(os.path.join(\"/kaggle/input/rsna-breast-cancer-detection/train_images/\",pid,f\"{imid}.dcm\"))\n    return paths\n        \n        ","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:03.964997Z","iopub.execute_input":"2022-12-30T10:59:03.966163Z","iopub.status.idle":"2022-12-30T10:59:03.972851Z","shell.execute_reply.started":"2022-12-30T10:59:03.966114Z","shell.execute_reply":"2022-12-30T10:59:03.97134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_path = add_img_path()","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:05.57872Z","iopub.execute_input":"2022-12-30T10:59:05.57916Z","iopub.status.idle":"2022-12-30T10:59:05.794235Z","shell.execute_reply.started":"2022-12-30T10:59:05.579121Z","shell.execute_reply":"2022-12-30T10:59:05.79293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data[\"image_path\"]=all_path","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:06.031419Z","iopub.execute_input":"2022-12-30T10:59:06.032312Z","iopub.status.idle":"2022-12-30T10:59:06.042211Z","shell.execute_reply.started":"2022-12-30T10:59:06.03227Z","shell.execute_reply":"2022-12-30T10:59:06.041242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.to_csv(\"train_with_path.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:08.452977Z","iopub.execute_input":"2022-12-30T10:59:08.453806Z","iopub.status.idle":"2022-12-30T10:59:08.786866Z","shell.execute_reply.started":"2022-12-30T10:59:08.45368Z","shell.execute_reply":"2022-12-30T10:59:08.785679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = test_data.copy()\nsubmission_df[\"age\"] = submission_df[\"age\"].fillna(submission_df[\"age\"].median())\nsubmission_df[\"cancer\"] = submission_df[\"age\"] / submission_df[\"age\"].max()\nsubmission_df = submission_df[[\"prediction_id\", \"cancer\"]].drop_duplicates(subset=\"prediction_id\")\nsubmission_df","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:10.972008Z","iopub.execute_input":"2022-12-30T10:59:10.972413Z","iopub.status.idle":"2022-12-30T10:59:10.993695Z","shell.execute_reply.started":"2022-12-30T10:59:10.97238Z","shell.execute_reply":"2022-12-30T10:59:10.992646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:11.451925Z","iopub.execute_input":"2022-12-30T10:59:11.452654Z","iopub.status.idle":"2022-12-30T10:59:11.458658Z","shell.execute_reply.started":"2022-12-30T10:59:11.452613Z","shell.execute_reply":"2022-12-30T10:59:11.457539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-12-30T10:59:15.378998Z","iopub.execute_input":"2022-12-30T10:59:15.379427Z","iopub.status.idle":"2022-12-30T10:59:15.406009Z","shell.execute_reply.started":"2022-12-30T10:59:15.379388Z","shell.execute_reply":"2022-12-30T10:59:15.405065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_1 = plt.figure(figsize=(12, 8))\nsns.histplot(data=train_data,x='age',hue='cancer')","metadata":{"execution":{"iopub.status.busy":"2022-12-30T11:13:55.255549Z","iopub.execute_input":"2022-12-30T11:13:55.256248Z","iopub.status.idle":"2022-12-30T11:13:55.939281Z","shell.execute_reply.started":"2022-12-30T11:13:55.256211Z","shell.execute_reply":"2022-12-30T11:13:55.937121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=train_data,x='age',hue='cancer', element='poly')","metadata":{"execution":{"iopub.status.busy":"2022-12-30T11:13:33.743896Z","iopub.execute_input":"2022-12-30T11:13:33.744317Z","iopub.status.idle":"2022-12-30T11:13:34.122002Z","shell.execute_reply.started":"2022-12-30T11:13:33.744282Z","shell.execute_reply":"2022-12-30T11:13:34.120986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=train_data,x='cancer',hue='laterality',palette='pastel')","metadata":{"execution":{"iopub.status.busy":"2022-12-30T11:21:39.934252Z","iopub.execute_input":"2022-12-30T11:21:39.934675Z","iopub.status.idle":"2022-12-30T11:21:40.28586Z","shell.execute_reply.started":"2022-12-30T11:21:39.934641Z","shell.execute_reply":"2022-12-30T11:21:40.284909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}