{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"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\npaths = []\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        paths.append(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":"2023-09-06T19:18:07.933508Z","iopub.execute_input":"2023-09-06T19:18:07.93466Z","iopub.status.idle":"2023-09-06T19:18:12.929556Z","shell.execute_reply.started":"2023-09-06T19:18:07.934612Z","shell.execute_reply":"2023-09-06T19:18:12.928073Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport matplotlib.pyplot as plt\nimport pydicom as dicom\nimport seaborn as sns\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:03:40.685816Z","iopub.execute_input":"2023-09-11T19:03:40.686188Z","iopub.status.idle":"2023-09-11T19:03:43.453844Z","shell.execute_reply.started":"2023-09-11T19:03:40.686159Z","shell.execute_reply":"2023-09-11T19:03:43.452476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH = '/kaggle/input/rsna-2023-abdominal-trauma-detection/'","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:17.170509Z","iopub.execute_input":"2023-09-11T19:05:17.171073Z","iopub.status.idle":"2023-09-11T19:05:17.175834Z","shell.execute_reply.started":"2023-09-11T19:05:17.171041Z","shell.execute_reply":"2023-09-11T19:05:17.174762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(os.path.join(PATH, 'train.csv'))","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:17.704443Z","iopub.execute_input":"2023-09-11T19:05:17.70555Z","iopub.status.idle":"2023-09-11T19:05:17.728689Z","shell.execute_reply.started":"2023-09-11T19:05:17.705512Z","shell.execute_reply":"2023-09-11T19:05:17.727412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:18.348137Z","iopub.execute_input":"2023-09-11T19:05:18.348613Z","iopub.status.idle":"2023-09-11T19:05:18.376139Z","shell.execute_reply.started":"2023-09-11T19:05:18.348577Z","shell.execute_reply":"2023-09-11T19:05:18.375313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:21.759933Z","iopub.execute_input":"2023-09-11T19:05:21.760844Z","iopub.status.idle":"2023-09-11T19:05:21.786622Z","shell.execute_reply.started":"2023-09-11T19:05:21.760808Z","shell.execute_reply":"2023-09-11T19:05:21.785582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SummaryStats = train_df.describe()\n\n# print()\n\nbla = pd.DataFrame(data=SummaryStats.iloc[1], columns=['Healthy', 'Injury', 'Low', 'High'])","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:22.510649Z","iopub.execute_input":"2023-09-11T19:05:22.511076Z","iopub.status.idle":"2023-09-11T19:05:22.556682Z","shell.execute_reply.started":"2023-09-11T19:05:22.511043Z","shell.execute_reply":"2023-09-11T19:05:22.555607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(data={'Category': ['Bowel', 'Extravasation', 'Kidney', 'Liver', 'Spleen'],\n                    'Healthy': ['98%', '93%', '95%', '89%', '88%'], \n                    'Injury': ['2%', '7%', '-', '-', '-'],\n                    'Low': ['-', '-', '3%', '5%', '8%'],\n                    'High': ['-', '-', '2%', '1%', '4%']})","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:05:23.321772Z","iopub.execute_input":"2023-09-11T19:05:23.322161Z","iopub.status.idle":"2023-09-11T19:05:23.337338Z","shell.execute_reply.started":"2023-09-11T19:05:23.322132Z","shell.execute_reply":"2023-09-11T19:05:23.336228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:26.133604Z","iopub.execute_input":"2023-09-10T16:35:26.133997Z","iopub.status.idle":"2023-09-10T16:35:26.144424Z","shell.execute_reply.started":"2023-09-10T16:35:26.133966Z","shell.execute_reply":"2023-09-10T16:35:26.143095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('The total number of unique patients are, ', train_df.patient_id.nunique())","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:26.392183Z","iopub.execute_input":"2023-09-10T16:35:26.392569Z","iopub.status.idle":"2023-09-10T16:35:26.399392Z","shell.execute_reply.started":"2023-09-10T16:35:26.392531Z","shell.execute_reply":"2023-09-10T16:35:26.398629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Count of the number of occurances of each patient in the data\\n',train_df.patient_id.value_counts())","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:26.651058Z","iopub.execute_input":"2023-09-10T16:35:26.652457Z","iopub.status.idle":"2023-09-10T16:35:26.661389Z","shell.execute_reply.started":"2023-09-10T16:35:26.652418Z","shell.execute_reply":"2023-09-10T16:35:26.659839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features = train_df.columns","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:35:10.322607Z","iopub.execute_input":"2023-09-11T20:35:10.323123Z","iopub.status.idle":"2023-09-11T20:35:10.328686Z","shell.execute_reply.started":"2023-09-11T20:35:10.323083Z","shell.execute_reply":"2023-09-11T20:35:10.327578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.bowel_healthy.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:35:11.237754Z","iopub.execute_input":"2023-09-11T20:35:11.238131Z","iopub.status.idle":"2023-09-11T20:35:11.246959Z","shell.execute_reply.started":"2023-09-11T20:35:11.238102Z","shell.execute_reply":"2023-09-11T20:35:11.245759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(7, 2, figsize = (12, 20))\naxes = axes.flatten()\nfor i in range(len(features)-1):\n    axes[i].bar(train_df[features[i]].value_counts().index, train_df[features[i]].value_counts().values)\n    axes[i].set_xticks([0,1])\n    axes[i].set_title(f'Count plot of {features[i]}')\n# train_df.bowel_healthy.value_counts().plot(kind='bar');","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:36:00.74Z","iopub.execute_input":"2023-09-11T20:36:00.740434Z","iopub.status.idle":"2023-09-11T20:36:03.002491Z","shell.execute_reply.started":"2023-09-11T20:36:00.740392Z","shell.execute_reply":"2023-09-11T20:36:03.001195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"health_columns = [\n    \"bowel_healthy\", \"extravasation_healthy\", \"kidney_healthy\", \n    \"liver_healthy\", \"spleen_healthy\",\n]","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:30.329482Z","iopub.execute_input":"2023-09-10T16:35:30.330227Z","iopub.status.idle":"2023-09-10T16:35:30.335739Z","shell.execute_reply.started":"2023-09-10T16:35:30.330184Z","shell.execute_reply":"2023-09-10T16:35:30.334622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train_df[health_columns].corr(), cmap='YlGnBu', annot=True, linewidths = .5)","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:30.337412Z","iopub.execute_input":"2023-09-10T16:35:30.337869Z","iopub.status.idle":"2023-09-10T16:35:30.7949Z","shell.execute_reply.started":"2023-09-10T16:35:30.337829Z","shell.execute_reply":"2023-09-10T16:35:30.793756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"injury_columns = [\n    \"bowel_injury\", \"extravasation_injury\",\n    \"kidney_low\", \"kidney_high\", \n    \"liver_low\", \"liver_high\",\n    \"spleen_low\", \"spleen_high\",\n    \"any_injury\"\n]\n\ncorr = train_df[injury_columns].corr()\n\nsns.heatmap(corr, annot=True, cmap='YlGnBu', linewidths=.5);","metadata":{"execution":{"iopub.status.busy":"2023-09-10T16:35:36.552447Z","iopub.execute_input":"2023-09-10T16:35:36.552822Z","iopub.status.idle":"2023-09-10T16:35:37.35498Z","shell.execute_reply.started":"2023-09-10T16:35:36.552793Z","shell.execute_reply":"2023-09-10T16:35:37.353751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_patients = train_df['patient_id'].count()\nprint('The total number of Patients,',num_patients)","metadata":{"execution":{"iopub.status.busy":"2023-09-10T17:00:18.331231Z","iopub.execute_input":"2023-09-10T17:00:18.3316Z","iopub.status.idle":"2023-09-10T17:00:18.33749Z","shell.execute_reply.started":"2023-09-10T17:00:18.331572Z","shell.execute_reply":"2023-09-10T17:00:18.336325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_df.loc[:, train_df.columns != 'patient_id'].\ntrain_df[train_df.columns[1:]].mean().apply(lambda X: str(round(X*100, 2))+'%')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:17:04.12276Z","iopub.execute_input":"2023-09-11T19:17:04.123213Z","iopub.status.idle":"2023-09-11T19:17:04.135632Z","shell.execute_reply.started":"2023-09-11T19:17:04.12318Z","shell.execute_reply":"2023-09-11T19:17:04.13442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\nimg_dat = dicom.read_file(img)\n\nimg_dat","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:50:02.482322Z","iopub.execute_input":"2023-09-11T19:50:02.482758Z","iopub.status.idle":"2023-09-11T19:50:02.526494Z","shell.execute_reply.started":"2023-09-11T19:50:02.482726Z","shell.execute_reply":"2023-09-11T19:50:02.525251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img_dat.pixel_array, cmap=plt.cm.bone);","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:53:45.483865Z","iopub.execute_input":"2023-09-11T19:53:45.484255Z","iopub.status.idle":"2023-09-11T19:53:45.858712Z","shell.execute_reply.started":"2023-09-11T19:53:45.484226Z","shell.execute_reply":"2023-09-11T19:53:45.857576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_label_df = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/image_level_labels.csv')\nimg_label_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:58:24.232726Z","iopub.execute_input":"2023-09-11T19:58:24.233707Z","iopub.status.idle":"2023-09-11T19:58:24.265106Z","shell.execute_reply.started":"2023-09-11T19:58:24.233662Z","shell.execute_reply":"2023-09-11T19:58:24.264204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_label_df.injury_name.value_counts().plot(kind = 'bar');\nplt.title('Injury names count plot');","metadata":{"execution":{"iopub.status.busy":"2023-09-11T19:59:42.487593Z","iopub.execute_input":"2023-09-11T19:59:42.487998Z","iopub.status.idle":"2023-09-11T19:59:42.787338Z","shell.execute_reply.started":"2023-09-11T19:59:42.487969Z","shell.execute_reply":"2023-09-11T19:59:42.786308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(img_label_df.groupby('patient_id')[['patient_id', 'injury_name']].value_counts())","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:19:25.198259Z","iopub.execute_input":"2023-09-11T20:19:25.19874Z","iopub.status.idle":"2023-09-11T20:19:25.221595Z","shell.execute_reply.started":"2023-09-11T20:19:25.198705Z","shell.execute_reply":"2023-09-11T20:19:25.220786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"EV_instances = img_label_df[(img_label_df['patient_id'] == 10004) & (img_label_df['series_id'] == 21057)].instance_number.values","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:49:05.454093Z","iopub.execute_input":"2023-09-11T20:49:05.454561Z","iopub.status.idle":"2023-09-11T20:49:05.461755Z","shell.execute_reply.started":"2023-09-11T20:49:05.454527Z","shell.execute_reply":"2023-09-11T20:49:05.460782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/362.dcm'\nimg_dat = dicom.read_file('/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/362.dcm')\n\nplt.imshow(img_dat.pixel_array, cmap=plt.cm.bone)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:24:24.760479Z","iopub.execute_input":"2023-09-11T20:24:24.760875Z","iopub.status.idle":"2023-09-11T20:24:25.140672Z","shell.execute_reply.started":"2023-09-11T20:24:24.760849Z","shell.execute_reply":"2023-09-11T20:24:25.139513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgs = []\nfor i in EV_instances:\n    imgs.append(os.path.join(PATH+'train_images/10004/21057/', str(i)+'.dcm'))","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:58:31.159177Z","iopub.execute_input":"2023-09-11T20:58:31.159591Z","iopub.status.idle":"2023-09-11T20:58:31.165967Z","shell.execute_reply.started":"2023-09-11T20:58:31.159561Z","shell.execute_reply":"2023-09-11T20:58:31.164643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(dicom.read_file(imgs[0]).pixel_array)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T20:59:53.3758Z","iopub.execute_input":"2023-09-11T20:59:53.376204Z","iopub.status.idle":"2023-09-11T20:59:53.702863Z","shell.execute_reply.started":"2023-09-11T20:59:53.376174Z","shell.execute_reply":"2023-09-11T20:59:53.701772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}],"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"}}