{"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 numpy as np # linear algebra\nimport pandas as pd \nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-27T15:25:45.235232Z","iopub.execute_input":"2022-08-27T15:25:45.235639Z","iopub.status.idle":"2022-08-27T15:25:46.232117Z","shell.execute_reply.started":"2022-08-27T15:25:45.235597Z","shell.execute_reply":"2022-08-27T15:25:46.230522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/mayo-clinic-strip-ai/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.234204Z","iopub.execute_input":"2022-08-27T15:25:46.2346Z","iopub.status.idle":"2022-08-27T15:25:46.249186Z","shell.execute_reply.started":"2022-08-27T15:25:46.234541Z","shell.execute_reply":"2022-08-27T15:25:46.247916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('../input/mayo-clinic-strip-ai/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.250879Z","iopub.execute_input":"2022-08-27T15:25:46.251261Z","iopub.status.idle":"2022-08-27T15:25:46.264928Z","shell.execute_reply.started":"2022-08-27T15:25:46.251226Z","shell.execute_reply":"2022-08-27T15:25:46.263743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = pd.read_csv('../input/mayo-clinic-strip-ai/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.266971Z","iopub.execute_input":"2022-08-27T15:25:46.267514Z","iopub.status.idle":"2022-08-27T15:25:46.27952Z","shell.execute_reply.started":"2022-08-27T15:25:46.26748Z","shell.execute_reply":"2022-08-27T15:25:46.278017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other = pd.read_csv('../input/mayo-clinic-strip-ai/other.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.281306Z","iopub.execute_input":"2022-08-27T15:25:46.282282Z","iopub.status.idle":"2022-08-27T15:25:46.299748Z","shell.execute_reply.started":"2022-08-27T15:25:46.282232Z","shell.execute_reply":"2022-08-27T15:25:46.297636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.324901Z","iopub.execute_input":"2022-08-27T15:25:46.325926Z","iopub.status.idle":"2022-08-27T15:25:46.350174Z","shell.execute_reply.started":"2022-08-27T15:25:46.325862Z","shell.execute_reply":"2022-08-27T15:25:46.348836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.548456Z","iopub.execute_input":"2022-08-27T15:25:46.549709Z","iopub.status.idle":"2022-08-27T15:25:46.584889Z","shell.execute_reply.started":"2022-08-27T15:25:46.549663Z","shell.execute_reply":"2022-08-27T15:25:46.583812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:46.769127Z","iopub.execute_input":"2022-08-27T15:25:46.769912Z","iopub.status.idle":"2022-08-27T15:25:46.784699Z","shell.execute_reply.started":"2022-08-27T15:25:46.769861Z","shell.execute_reply":"2022-08-27T15:25:46.783674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of Unique patients in the dataset","metadata":{}},{"cell_type":"code","source":"len(train['patient_id'].unique())","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:48.300389Z","iopub.execute_input":"2022-08-27T15:25:48.300789Z","iopub.status.idle":"2022-08-27T15:25:48.309593Z","shell.execute_reply.started":"2022-08-27T15:25:48.300754Z","shell.execute_reply":"2022-08-27T15:25:48.308437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Number of Patients having more than 1 images","metadata":{}},{"cell_type":"code","source":"(train['patient_id'].value_counts() >1).value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:49.365437Z","iopub.execute_input":"2022-08-27T15:25:49.365832Z","iopub.status.idle":"2022-08-27T15:25:49.377082Z","shell.execute_reply.started":"2022-08-27T15:25:49.3658Z","shell.execute_reply":"2022-08-27T15:25:49.375694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"89 patients have more than 1 image in the Dataset","metadata":{}},{"cell_type":"markdown","source":"### Patients having most images","metadata":{}},{"cell_type":"code","source":"train['patient_id'].value_counts()[:10].plot(kind = 'bar')","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:25:51.151819Z","iopub.execute_input":"2022-08-27T15:25:51.152224Z","iopub.status.idle":"2022-08-27T15:25:51.445377Z","shell.execute_reply.started":"2022-08-27T15:25:51.152183Z","shell.execute_reply":"2022-08-27T15:25:51.444046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of Patients not having same labels in all of their images","metadata":{}},{"cell_type":"code","source":"patients_map = {}\nfor i in range(0, len(train['patient_id'])):\n    patients_map[train.loc[i,'patient_id']] = set()\nfor i in range(0, len(train['patient_id'])):\n    patients_map[train.loc[i,'patient_id']].add(train.loc[i,'label'])","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:33:41.62207Z","iopub.execute_input":"2022-08-27T15:33:41.622455Z","iopub.status.idle":"2022-08-27T15:33:41.66657Z","shell.execute_reply.started":"2022-08-27T15:33:41.622423Z","shell.execute_reply":"2022-08-27T15:33:41.665257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"contradictory_label = 0\nfor k,v in patients_map.items():\n    if len(v) > 1:\n        contradictory_label+=1\nprint(\"Number of Patients with contradictory label are :: \", contradictory_label)","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:36:05.994546Z","iopub.execute_input":"2022-08-27T15:36:05.994985Z","iopub.status.idle":"2022-08-27T15:36:06.002076Z","shell.execute_reply.started":"2022-08-27T15:36:05.994953Z","shell.execute_reply":"2022-08-27T15:36:06.000978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"No patients have more than one label","metadata":{}},{"cell_type":"markdown","source":"# Exploring the Images","metadata":{}},{"cell_type":"code","source":"import openslide\nfrom openslide import OpenSlide\nimport cv2 ","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:36:29.744605Z","iopub.execute_input":"2022-08-27T15:36:29.74503Z","iopub.status.idle":"2022-08-27T15:36:30.091913Z","shell.execute_reply.started":"2022-08-27T15:36:29.744995Z","shell.execute_reply":"2022-08-27T15:36:30.090777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slide = OpenSlide('../input/mayo-clinic-strip-ai/train/008e5c_0.tif')\nregion = (0, 0)\nsize = (10000, 10000)\nregion = slide.read_region(region, 0, size)\nplt.figure(figsize=(8, 8))\nplt.imshow(region)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:36:30.095753Z","iopub.execute_input":"2022-08-27T15:36:30.096871Z","iopub.status.idle":"2022-08-27T15:36:48.888069Z","shell.execute_reply.started":"2022-08-27T15:36:30.096829Z","shell.execute_reply":"2022-08-27T15:36:48.883777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slide = OpenSlide('../input/mayo-clinic-strip-ai/train/006388_0.tif')\nregion = (0, 0)\nsize = (15000, 15000)\nregion = slide.read_region(region, 0, size)\nplt.figure(figsize=(8, 8))\nplt.imshow(region)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-27T15:36:48.894836Z","iopub.execute_input":"2022-08-27T15:36:48.89564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}