{"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":"markdown","source":"# <font color='#800080'>Notebook Index</font>\n\n### [Analysis of the Age column](#col_age)\n####   - [Summary statistics of Age](#summary_age)\n####   - [Distribution of Age](#age_dist)\n####   - [How is Age distributed w.r.t the target?](#age_w_target)\n####   - [Do people who are aged more need more number of mammograms before diagnosis?](#age_mmg)\n\n\n### [Analysis of the View column](#views)\n####   - [Description of unique image views present in the dataset](#view_desc)\n####   - [How are each individual views distributed in the training set?](#view_dist)\n####   - [How are views distributed w.r.t the target?](view_dist_targ)\nMore EDA to be added.","metadata":{}},{"cell_type":"code","source":"import os\nimport pydicom\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom scipy.stats import norm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-30T14:43:31.043256Z","iopub.execute_input":"2022-11-30T14:43:31.043719Z","iopub.status.idle":"2022-11-30T14:43:31.04985Z","shell.execute_reply.started":"2022-11-30T14:43:31.043672Z","shell.execute_reply":"2022-11-30T14:43:31.048704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    train_dir = \"/kaggle/input/rsna-breast-cancer-detection/train_images\"\n    test_dir = \"/kaggle/input/rsna-breast-cancer-detection/test_images\"\n    train_csv_dir = \"/kaggle/input/rsna-breast-cancer-detection/train.csv\"\n    test_csv_dir = \"/kaggle/input/rsna-breast-cancer-detection/test.csv\"\n    id_cols = [\"site_id\", \"patient_id\", \"image_id\", \"machine_id\"]\n    cols_only_in_train = [\"cancer\", \"biopsy\", \"invasive\", \"BIRADS\", \"difficult_negative_case\"]","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.076825Z","iopub.execute_input":"2022-11-30T14:43:31.07724Z","iopub.status.idle":"2022-11-30T14:43:31.083419Z","shell.execute_reply.started":"2022-11-30T14:43:31.077202Z","shell.execute_reply":"2022-11-30T14:43:31.082481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(CFG.train_csv_dir)","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.109502Z","iopub.execute_input":"2022-11-30T14:43:31.109952Z","iopub.status.idle":"2022-11-30T14:43:31.181873Z","shell.execute_reply.started":"2022-11-30T14:43:31.109914Z","shell.execute_reply":"2022-11-30T14:43:31.180927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.183804Z","iopub.execute_input":"2022-11-30T14:43:31.184133Z","iopub.status.idle":"2022-11-30T14:43:31.206041Z","shell.execute_reply.started":"2022-11-30T14:43:31.184102Z","shell.execute_reply":"2022-11-30T14:43:31.204573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Age <a id = \"col_age\"> </a>","metadata":{}},{"cell_type":"markdown","source":"## Summary statistics of Age <a id = \"summary_age\"> </a>","metadata":{}},{"cell_type":"code","source":"print(f\"The minimum age is: {min(train['age'])}\")\nprint(f\"The maxiumum age is: {max(train['age'])}\")\nprint(f\"The mean age is: {np.mean(train['age']):.2f}\")\nprint(f\"The standard deviation of age is: {np.std(train['age']):.2f}\")","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.209227Z","iopub.execute_input":"2022-11-30T14:43:31.209588Z","iopub.status.idle":"2022-11-30T14:43:31.230152Z","shell.execute_reply.started":"2022-11-30T14:43:31.209555Z","shell.execute_reply":"2022-11-30T14:43:31.22896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Distribution of Age <a id = \"age_dist\"> </a>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,6), tight_layout=True)\nplt.hist(train[\"age\"], color=\"blue\", linewidth=2, alpha = 0.5)\nplt.title('Histogram')\nplt.xlabel('Age')\nplt.ylabel('Count')\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.280262Z","iopub.execute_input":"2022-11-30T14:43:31.281101Z","iopub.status.idle":"2022-11-30T14:43:31.61679Z","shell.execute_reply.started":"2022-11-30T14:43:31.281052Z","shell.execute_reply":"2022-11-30T14:43:31.615673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## How is age distributed w.r.t the target? <a id = \"age_w_target\"> </a>","metadata":{}},{"cell_type":"code","source":"age_w_cancer = train[train[\"cancer\"] == 1][\"age\"]\nage_wout_cancer = train[train[\"cancer\"] == 0][\"age\"]\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12,5))\nax1.hist(age_wout_cancer, color = \"orange\", alpha = 0.7)\nax1.set_title('Without Diagnosed Cancer')\nax1.set(xlabel='Age', ylabel='Count')\n\nax2.hist(age_w_cancer, color = \"orange\", alpha = 0.7)\nax2.set_title('With Diagnosed Cancer')\nax2.set(xlabel='Age');","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:31.618745Z","iopub.execute_input":"2022-11-30T14:43:31.619178Z","iopub.status.idle":"2022-11-30T14:43:32.001508Z","shell.execute_reply.started":"2022-11-30T14:43:31.619145Z","shell.execute_reply":"2022-11-30T14:43:32.000569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Do people who are aged more need more number of mammograms before diagnosis?\n* By inspecting visually, in the age range of 26 to 40, there seem to be some fluctuations in how many mammograms are required before diagnosis.\n* The age range of 50 to 70 on an average seems to require less number of mammograms before diagnosis.\n<a id = \"age_mmg\"> </a>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\ngrp_pid_age = pd.DataFrame(train.groupby(\"patient_id\").mean()[\"age\"])\ngrp_pid_imid = train.groupby(\"patient_id\").count()[\"image_id\"]\ngrp_pid_join = grp_pid_age.join(grp_pid_imid).groupby(\"age\").mean().reset_index()\nax = sns.lineplot(data = grp_pid_join, x = \"age\", y = \"image_id\", color='purple', linewidth=1.5)\nax.set(xlabel='Age', ylabel='Average Mammograms Required');","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:32.00268Z","iopub.execute_input":"2022-11-30T14:43:32.003604Z","iopub.status.idle":"2022-11-30T14:43:32.287529Z","shell.execute_reply.started":"2022-11-30T14:43:32.003563Z","shell.execute_reply":"2022-11-30T14:43:32.286678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Views <a id = \"views\"> </a>","metadata":{}},{"cell_type":"markdown","source":"## There are six unique views that are available in the data.\n1. **CC** - **Cranial Caudal** (CC) is a view of the breast taken directly from above.[[source](https://radiopaedia.org/articles/craniocaudal-view?lang=us)]\n2. **MLO** - **Mediolateral Oblique** (MLO) is a view of the breast from the sides. [[source](https://radiopaedia.org/articles/mediolateral-oblique-view)]\n3. **ML** - **Mediolateral** (ML) is a supplementary mammographic view and shows less breast tissue and pectoral muscle than the MLO view. [[source](https://radiopaedia.org/articles/mediolateral-view#:~:text=The%20mediolateral%20(ML)%20view%20is,oblique%20view%20(MLO%20view).)]\n4. **LM** - The **lateromedial** view (LM) is taken from up against the sternum. [[source](https://radiopaedia.org/articles/lateromedial-view)]\n5. **AT** - Couldn't find more information regarding this view.\n6. **LMO** - Stands for the **lateral-medial oblique** (LMO) view. [[source](https://radiopaedia.org/articles/lateromedial-oblique-view)]\n<a id = \"view_desc\"> </a>","metadata":{}},{"cell_type":"markdown","source":"## How are each individual views distributed in the training set?\n* Majority of the images that are present in the dataset are of **MLO** and **CC** views.\n<a id = \"view_dist\"> </a>","metadata":{}},{"cell_type":"code","source":"df_grp_view = pd.DataFrame(train.groupby(\"view\").count()[\"image_id\"].sort_values())\ndf_grp_view","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:32.289678Z","iopub.execute_input":"2022-11-30T14:43:32.290285Z","iopub.status.idle":"2022-11-30T14:43:32.323185Z","shell.execute_reply.started":"2022-11-30T14:43:32.290247Z","shell.execute_reply":"2022-11-30T14:43:32.322009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## How are views distributed w.r.t the target?\n* In the patients that **do not** have cancer, there are all the **unique image views** present in the training dataset.\n* Patient that **do have** cancer in the dataset, do not have **LM, LMO, ML** image views present in the training dataset.\n<a id = \"view_dist_targ\"> </a>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.set_style(\"whitegrid\")\ngrp_non_cancer_view = train[train[\"cancer\"] == 0].groupby(\"view\").count()\nax = sns.barplot(data = grp_non_cancer_view, x = grp_non_cancer_view.index, y = \"patient_id\", log=True)\nax.set(xlabel='View', ylabel='# Without cancer patients (Log Scale)');","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:32.324743Z","iopub.execute_input":"2022-11-30T14:43:32.325096Z","iopub.status.idle":"2022-11-30T14:43:33.072172Z","shell.execute_reply.started":"2022-11-30T14:43:32.325063Z","shell.execute_reply":"2022-11-30T14:43:33.071037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.set_style(\"whitegrid\")\ngrp_cancer_view = train[train[\"cancer\"] == 1].groupby(\"view\").count()\nax = sns.barplot(data = grp_cancer_view, x = grp_cancer_view.index, y = \"patient_id\", log = True)\nax.set(xlabel='View', ylabel='# With cancer patients (Log Scale)');","metadata":{"execution":{"iopub.status.busy":"2022-11-30T14:43:33.073577Z","iopub.execute_input":"2022-11-30T14:43:33.073953Z","iopub.status.idle":"2022-11-30T14:43:33.452029Z","shell.execute_reply.started":"2022-11-30T14:43:33.073919Z","shell.execute_reply":"2022-11-30T14:43:33.450707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Work in Progress...","metadata":{}}]}