{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":99552,"databundleVersionId":13190393,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:30:25.472848Z","iopub.execute_input":"2025-08-01T11:30:25.473393Z","iopub.status.idle":"2025-08-01T11:30:25.51755Z","shell.execute_reply.started":"2025-08-01T11:30:25.473359Z","shell.execute_reply":"2025-08-01T11:30:25.515711Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir('/kaggle/input/rsna-intracranial-aneurysm-detection')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:35:25.791033Z","iopub.execute_input":"2025-08-01T11:35:25.791344Z","iopub.status.idle":"2025-08-01T11:35:25.799262Z","shell.execute_reply.started":"2025-08-01T11:35:25.791323Z","shell.execute_reply":"2025-08-01T11:35:25.79805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_iterator(df):\n    return df[['SeriesInstanceUID']]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:40:23.451573Z","iopub.execute_input":"2025-08-01T11:40:23.452407Z","iopub.status.idle":"2025-08-01T11:40:23.457337Z","shell.execute_reply.started":"2025-08-01T11:40:23.452376Z","shell.execute_reply":"2025-08-01T11:40:23.455982Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_path = '/kaggle/input/rsna-intracranial-aneurysm-detection'\ntrain_df = pd.read_csv(os.path.join(train_path,'train.csv'))\n\ndf_analysis = create_iterator(train_df)\n\nfor idx in tqdm(df_analysis.index, desc=\"loading...\"):\n\n    scan_id = df_analysis.at[idx,'SeriesInstanceUID']\n\n    try:\n        len_segmentations = len([f for f in os.listdir(os.path.join(train_path,'segmentations',scan_id))])\n    except:\n        len_segmentations = 0\n\n    try:\n        len_series = len([f for f in os.listdir(os.path.join(train_path,'series',scan_id))])\n    except:\n        len_series = 0\n    \n    df_analysis.loc[idx,'segmentations'] = len_segmentations\n    df_analysis.loc[idx,'series'] = len_series","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:43:40.845196Z","iopub.execute_input":"2025-08-01T11:43:40.845529Z","iopub.status.idle":"2025-08-01T11:47:10.42668Z","shell.execute_reply.started":"2025-08-01T11:43:40.845505Z","shell.execute_reply":"2025-08-01T11:47:10.425582Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_analysis","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:52:27.779838Z","iopub.execute_input":"2025-08-01T11:52:27.780191Z","iopub.status.idle":"2025-08-01T11:52:27.793961Z","shell.execute_reply.started":"2025-08-01T11:52:27.780166Z","shell.execute_reply":"2025-08-01T11:52:27.79301Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_analysis['segmentations'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:57:25.706738Z","iopub.execute_input":"2025-08-01T11:57:25.707059Z","iopub.status.idle":"2025-08-01T11:57:25.714425Z","shell.execute_reply.started":"2025-08-01T11:57:25.707035Z","shell.execute_reply":"2025-08-01T11:57:25.713563Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(df_analysis.sort_values(by='segmentations').tail(1)['SeriesInstanceUID'].loc[2578])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:52:24.456196Z","iopub.execute_input":"2025-08-01T11:52:24.456571Z","iopub.status.idle":"2025-08-01T11:52:24.466083Z","shell.execute_reply.started":"2025-08-01T11:52:24.45654Z","shell.execute_reply":"2025-08-01T11:52:24.464746Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir('/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.49718418682238683779854914910561017368')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:51:36.050772Z","iopub.execute_input":"2025-08-01T11:51:36.051121Z","iopub.status.idle":"2025-08-01T11:51:36.062913Z","shell.execute_reply.started":"2025-08-01T11:51:36.051096Z","shell.execute_reply":"2025-08-01T11:51:36.061818Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(6, 4))\nsns.countplot(data=df_analysis, x='segmentations', palette='Set2')\n\nplt.title('Frequency of Segmentations')\nplt.xlabel('Segmentation Present (0 = No, 1 = Yes)')\nplt.ylabel('Number of Series')\nplt.xticks([0, 1], ['No', 'Yes'])  # Optional: label formatting\nplt.grid(axis='y', linestyle='--', alpha=0.7)\nplt.tight_layout()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:48:29.001696Z","iopub.execute_input":"2025-08-01T11:48:29.00206Z","iopub.status.idle":"2025-08-01T11:48:30.222418Z","shell.execute_reply.started":"2025-08-01T11:48:29.002029Z","shell.execute_reply":"2025-08-01T11:48:30.221545Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(8, 4))\nsns.histplot(data=df_analysis, x='series', bins=30, kde=False, color='skyblue')\n\nplt.title('Distribution of Series Values')\nplt.xlabel('Series')\nplt.ylabel('Frequency')\nplt.grid(axis='y', linestyle='--', alpha=0.7)\nplt.tight_layout()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-01T11:53:33.772625Z","iopub.execute_input":"2025-08-01T11:53:33.772912Z","iopub.status.idle":"2025-08-01T11:53:34.049717Z","shell.execute_reply.started":"2025-08-01T11:53:33.772886Z","shell.execute_reply":"2025-08-01T11:53:34.048724Z"}},"outputs":[],"execution_count":null}]}