{"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-12-31T13:02:44.391127Z","iopub.execute_input":"2022-12-31T13:02:44.391657Z","iopub.status.idle":"2022-12-31T13:02:58.273717Z","shell.execute_reply.started":"2022-12-31T13:02:44.391606Z","shell.execute_reply":"2022-12-31T13:02:58.270813Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Note: Please comment, what is good and what is not good in this notebook. If its good kindly UPVOTE***","metadata":{}},{"cell_type":"markdown","source":"> # The goal of this competition is to identify cases of breast cancer in mammograms from screening exams. It is important to identify cases of cancer for obvious reasons, but false positives also have downsides for patients. As millions of women get mammograms each year, a useful machine learning tool could help a great many people.\n","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\nimport plotly.graph_objects as go\nimport pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:03:16.069319Z","iopub.execute_input":"2022-12-31T13:03:16.069891Z","iopub.status.idle":"2022-12-31T13:03:16.076268Z","shell.execute_reply.started":"2022-12-31T13:03:16.069842Z","shell.execute_reply":"2022-12-31T13:03:16.074793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ntrain.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:03:38.08998Z","iopub.execute_input":"2022-12-31T13:03:38.090423Z","iopub.status.idle":"2022-12-31T13:03:38.15765Z","shell.execute_reply.started":"2022-12-31T13:03:38.090384Z","shell.execute_reply":"2022-12-31T13:03:38.156691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Total number of samples collected to train the model :  54706\n\n# Unique number of patients: 11913","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:03:47.409215Z","iopub.execute_input":"2022-12-31T13:03:47.409696Z","iopub.status.idle":"2022-12-31T13:03:47.437971Z","shell.execute_reply.started":"2022-12-31T13:03:47.409649Z","shell.execute_reply":"2022-12-31T13:03:47.436506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"site_count = train.groupby('site_id')['site_id'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = site_count.site_id,values = site_count['count'])])\nfig.update_layout(\n    title=\"Site Utilization \",\n    xaxis_title=\"Sites\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:04:02.399452Z","iopub.execute_input":"2022-12-31T13:04:02.399879Z","iopub.status.idle":"2022-12-31T13:04:02.420785Z","shell.execute_reply.started":"2022-12-31T13:04:02.399841Z","shell.execute_reply":"2022-12-31T13:04:02.419399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Almost equal number of samples came from both the sites.**","metadata":{}},{"cell_type":"code","source":"laterality_count = train.groupby('laterality')['laterality'].count().reset_index(name = 'count')\nfig = px.bar(laterality_count, x='laterality', y='count', color = 'laterality')\nfig.update_layout(\n    title=\"Laterality Distribution\",\n    xaxis_title=\"Laterality\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f7f\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.282339Z","iopub.status.idle":"2022-12-31T13:02:58.282902Z","shell.execute_reply.started":"2022-12-31T13:02:58.282606Z","shell.execute_reply":"2022-12-31T13:02:58.282632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Laterality(Side of the Organ) is almost same. Equal number of samples of Right and Left side**","metadata":{}},{"cell_type":"code","source":"view_count = train.groupby('view')['view'].count().reset_index(name = 'count')\nfig = px.bar(view_count, x='view', y='count', color = 'view')\nfig.update_layout(\n    title=\"View Distribution\",\n    xaxis_title=\"View\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f7f\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:04:12.604143Z","iopub.execute_input":"2022-12-31T13:04:12.604554Z","iopub.status.idle":"2022-12-31T13:04:12.700938Z","shell.execute_reply.started":"2022-12-31T13:04:12.604501Z","shell.execute_reply":"2022-12-31T13:04:12.699771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Definition: In screening digital mammography, each breast is typically imaged with two different views, i.e., the mediolateral oblique (MLO) view and cranial caudal (CC) view (Fig. 1). The MLO view is taken from the center of the chest outward, while the CC view is taken from above the breast.\nGiven data has equal partition of views.**","metadata":{}},{"cell_type":"code","source":"age_count = train.groupby('age')['age'].count().reset_index(name = 'count')\nage_count['age'] = age_count['age'].apply(str)\nfig = px.bar(age_count, x='age', y='count', color = 'age')\nfig.update_layout(\n    title=\"Age Distribution\",\n    xaxis_title=\"Age\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f7f\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:04:22.584355Z","iopub.execute_input":"2022-12-31T13:04:22.584778Z","iopub.status.idle":"2022-12-31T13:04:23.056186Z","shell.execute_reply.started":"2022-12-31T13:04:22.584743Z","shell.execute_reply":"2022-12-31T13:04:23.054823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **the average age of the people is 60. But most of the data falls between 50 to 70. Still some of the people age started from 40 and goes upto 75**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['cancer'])['cancer'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.cancer,values = pitch['count'])])\nfig.update_layout(\n    title=\"Cancer\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.289764Z","iopub.status.idle":"2022-12-31T13:02:58.290392Z","shell.execute_reply.started":"2022-12-31T13:02:58.290129Z","shell.execute_reply":"2022-12-31T13:02:58.290162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Given dataset for training: only 2% of people had possibilities to have Cancer**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['biopsy'])['biopsy'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.biopsy,values = pitch['count'])])\nfig.update_layout(\n    title=\"Biopsy\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.291985Z","iopub.status.idle":"2022-12-31T13:02:58.292443Z","shell.execute_reply.started":"2022-12-31T13:02:58.292244Z","shell.execute_reply":"2022-12-31T13:02:58.292264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Biopsy can help determine if you have cancer or another condition. 5.4% people have to follow-up**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['invasive'])['invasive'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.invasive,values = pitch['count'])])\nfig.update_layout(\n    title=\"Invasive\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.293823Z","iopub.status.idle":"2022-12-31T13:02:58.294572Z","shell.execute_reply.started":"2022-12-31T13:02:58.294162Z","shell.execute_reply":"2022-12-31T13:02:58.294182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Tending to Spread. Its very low**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['BIRADS'])['BIRADS'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.BIRADS,values = pitch['count'])])\nfig.update_layout(\n    title=\"BIRADS\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.295894Z","iopub.status.idle":"2022-12-31T13:02:58.296738Z","shell.execute_reply.started":"2022-12-31T13:02:58.296455Z","shell.execute_reply":"2022-12-31T13:02:58.296478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Given data, 31% people need followup to confirm the cancer.\n60% people considered as Cancer Negative.\n8.6% people considered as Normal.**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['implant'])['implant'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.implant,values = pitch['count'])])\nfig.update_layout(\n    title=\"Implant\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.298154Z","iopub.status.idle":"2022-12-31T13:02:58.298645Z","shell.execute_reply.started":"2022-12-31T13:02:58.298361Z","shell.execute_reply":"2022-12-31T13:02:58.298379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Medical implants are devices or tissues that are placed inside or on the surface of the body. Many implants are prosthetics, intended to replace missing body parts. Only 2.7% people had tissue implantation**","metadata":{}},{"cell_type":"code","source":"pitch = train.groupby(['density'])['density'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.density,values = pitch['count'])])\nfig.update_layout(\n    title=\"Density\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.299743Z","iopub.status.idle":"2022-12-31T13:02:58.300695Z","shell.execute_reply.started":"2022-12-31T13:02:58.300356Z","shell.execute_reply":"2022-12-31T13:02:58.300386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **A is less and D is Extreme density. 10.5% less density and 5.22% extreme density. consider remaining 84% are medium density**","metadata":{}},{"cell_type":"code","source":"machine_count = train.groupby('machine_id')['machine_id'].count().reset_index(name = 'count')\nmachine_count['machine_id'] = machine_count['machine_id'].apply(str)\nfig = px.bar(machine_count, x='machine_id', y='count', color = 'machine_id')\nfig.update_layout(\n    title=\"Machine Distribution\",\n    xaxis_title=\"Machine ID\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f7f\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.302982Z","iopub.status.idle":"2022-12-31T13:02:58.303779Z","shell.execute_reply.started":"2022-12-31T13:02:58.303392Z","shell.execute_reply":"2022-12-31T13:02:58.303428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pitch = train.groupby(['difficult_negative_case'])['difficult_negative_case'].count().reset_index(name = 'count')\nfig = go.Figure(data = [go.Pie(labels = pitch.difficult_negative_case,values = pitch['count'])])\nfig.update_layout(\n    title=\"difficult_negative_case\",\n    xaxis_title=\"Levels\",\n    yaxis_title=\"Counts\",\n    font=dict(\n        family=\"sans serif\",\n        size=18,\n        color=\"#7f7f72\"\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.312078Z","iopub.status.idle":"2022-12-31T13:02:58.312776Z","shell.execute_reply.started":"2022-12-31T13:02:58.312447Z","shell.execute_reply":"2022-12-31T13:02:58.312479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Train image sample\nimport pydicom as dicom\nimport matplotlib.pylab as plt\n\n# specify your image path\nimage_path = '/kaggle/input/rsna-breast-cancer-detection/train_images/10006/1459541791.dcm'\nds = dicom.dcmread(image_path)\n\nplt.imshow(ds.pixel_array)\n\nimage_path = '/kaggle/input/rsna-breast-cancer-detection/train_images/10048/1234933874.dcm'\nds = dicom.dcmread(image_path)\n\nplt.imshow(ds.pixel_array)","metadata":{"execution":{"iopub.status.busy":"2022-12-31T13:02:58.315085Z","iopub.status.idle":"2022-12-31T13:02:58.315748Z","shell.execute_reply.started":"2022-12-31T13:02:58.315422Z","shell.execute_reply":"2022-12-31T13:02:58.315452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}