{"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":"Let's answer the question,\n\n**What Patient Position detected the most injuries**\n\n> This does not imply that a Particular Position is more accurate in detecting an injury type. The choice of Patient position will usually be determined by the technologist at hand, considering diverse factors.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:14.716494Z","iopub.execute_input":"2023-09-20T12:46:14.716889Z","iopub.status.idle":"2023-09-20T12:46:14.722983Z","shell.execute_reply.started":"2023-09-20T12:46:14.716858Z","shell.execute_reply":"2023-09-20T12:46:14.721593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train.csv')\ndf = pd.read_csv('/kaggle/input/rsna-atd-2023-dicom-metadata/train_images_dicom_meta.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:14.728465Z","iopub.execute_input":"2023-09-20T12:46:14.728823Z","iopub.status.idle":"2023-09-20T12:46:27.697437Z","shell.execute_reply.started":"2023-09-20T12:46:14.728794Z","shell.execute_reply":"2023-09-20T12:46:27.69587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.rename(columns={'_patient_id':'patient_id', '_series_id':'series_id', 'scan_id':'scan_id'})","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:27.700373Z","iopub.execute_input":"2023-09-20T12:46:27.700843Z","iopub.status.idle":"2023-09-20T12:46:28.227529Z","shell.execute_reply.started":"2023-09-20T12:46:27.700805Z","shell.execute_reply":"2023-09-20T12:46:28.226063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We need to merge our metadata with the `train.csv` that contains injury information","metadata":{}},{"cell_type":"code","source":"meta_df = df.merge(train)\nmeta_df.sample(10)","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:28.229534Z","iopub.execute_input":"2023-09-20T12:46:28.230092Z","iopub.status.idle":"2023-09-20T12:46:29.066842Z","shell.execute_reply.started":"2023-09-20T12:46:28.230036Z","shell.execute_reply":"2023-09-20T12:46:29.065322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# New column, injury_type\nINJURY_COLS = ['kidney_healthy', 'liver_healthy', 'extravasation_healthy','bowel_healthy','spleen_healthy']","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:29.069874Z","iopub.execute_input":"2023-09-20T12:46:29.070244Z","iopub.status.idle":"2023-09-20T12:46:29.077235Z","shell.execute_reply.started":"2023-09-20T12:46:29.070212Z","shell.execute_reply":"2023-09-20T12:46:29.07511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta_df['patient position']","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:29.078995Z","iopub.execute_input":"2023-09-20T12:46:29.079497Z","iopub.status.idle":"2023-09-20T12:46:29.096623Z","shell.execute_reply.started":"2023-09-20T12:46:29.079466Z","shell.execute_reply":"2023-09-20T12:46:29.095371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta_df['patient position'].value_counts().plot(kind='pie')","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:29.098399Z","iopub.execute_input":"2023-09-20T12:46:29.098973Z","iopub.status.idle":"2023-09-20T12:46:29.485256Z","shell.execute_reply.started":"2023-09-20T12:46:29.098939Z","shell.execute_reply":"2023-09-20T12:46:29.483753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Only two patient positions were used in this dataset, `Feet First Supine (FFS)` and `Head First Supine (FFS)`. More scans used `FFS`. \nThis doesn't imply that more patients used `FFS`, but could also mean that patients with `FFS` had more scans taken than those with `HFS`. ","metadata":{}},{"cell_type":"code","source":"meta_df['any_injury'] = meta_df['any_injury'].astype(bool)\nmeta_df.groupby('patient position')['any_injury'].value_counts().\\\nplot(\n    kind='pie',\n    title='Positives & Negatives for Patient Positions',\n    legend=True,\n    table=True,\n    autopct='%.4f'\n)","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:47:42.902075Z","iopub.execute_input":"2023-09-20T12:47:42.902586Z","iopub.status.idle":"2023-09-20T12:47:43.606499Z","shell.execute_reply.started":"2023-09-20T12:47:42.902548Z","shell.execute_reply":"2023-09-20T12:47:43.60483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**More internal injuries were found in `FFS` scans in total**, \nbut does that mean there is a higher probability of finding an injury with `FFS`?","metadata":{}},{"cell_type":"markdown","source":"Let's visualize that more clearly, (it's also clear our distribution is not balanced)","metadata":{}},{"cell_type":"code","source":"ratio_positives = meta_df.groupby('patient position')['any_injury'].value_counts() / meta_df.groupby('patient position')['any_injury'].count()","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:46:30.186318Z","iopub.execute_input":"2023-09-20T12:46:30.187476Z","iopub.status.idle":"2023-09-20T12:46:30.534329Z","shell.execute_reply.started":"2023-09-20T12:46:30.187439Z","shell.execute_reply":"2023-09-20T12:46:30.533004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ratio_positives['FFS'].plot.pie(autopct='%.4f', title='Feet First Supine (FFS)')","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:50:21.887417Z","iopub.execute_input":"2023-09-20T12:50:21.887946Z","iopub.status.idle":"2023-09-20T12:50:22.051432Z","shell.execute_reply.started":"2023-09-20T12:50:21.887906Z","shell.execute_reply":"2023-09-20T12:50:22.04995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ratio_positives['HFS'].plot.pie(autopct='%.4f', title='Head First Supine (HFS)')","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:50:22.292854Z","iopub.execute_input":"2023-09-20T12:50:22.29327Z","iopub.status.idle":"2023-09-20T12:50:22.460404Z","shell.execute_reply.started":"2023-09-20T12:50:22.293236Z","shell.execute_reply":"2023-09-20T12:50:22.455517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}