{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":24800,"datasetId":1042002,"databundleVersionId":1831594}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\n\n\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-31T15:18:14.423593Z","iopub.execute_input":"2025-05-31T15:18:14.423998Z","iopub.status.idle":"2025-05-31T15:18:54.045128Z","shell.execute_reply.started":"2025-05-31T15:18:14.423975Z","shell.execute_reply":"2025-05-31T15:18:54.044213Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\ndf = pd.read_csv('/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train.csv')\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-31T15:41:13.707072Z","iopub.execute_input":"2025-05-31T15:41:13.707445Z","iopub.status.idle":"2025-05-31T15:41:13.823247Z","shell.execute_reply.started":"2025-05-31T15:41:13.707418Z","shell.execute_reply":"2025-05-31T15:41:13.822342Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\ndicom_file = \"/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train/000434271f63a053c4128a0ba6352c7f.dicom\"\nds = pydicom.dcmread(dicom_file)\nplt.imshow(ds.pixel_array, cmap=\"gray\")\nplt.axis(\"off\")\nplt.title(\"Sample Chest X-ray\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-31T15:19:08.913296Z","iopub.execute_input":"2025-05-31T15:19:08.913571Z","iopub.status.idle":"2025-05-31T15:19:10.629385Z","shell.execute_reply.started":"2025-05-31T15:19:08.913551Z","shell.execute_reply":"2025-05-31T15:19:10.62829Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\ndata_path = \"/kaggle/input/vinbigdata-chest-xray-abnormalities-detection\"\ncsv_files = [f for f in os.listdir(data_path) if f.endswith(\".csv\")]\nprint(\"CSV Tables:\", csv_files)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-31T15:41:21.744208Z","iopub.execute_input":"2025-05-31T15:41:21.744551Z","iopub.status.idle":"2025-05-31T15:41:21.751211Z","shell.execute_reply.started":"2025-05-31T15:41:21.744528Z","shell.execute_reply":"2025-05-31T15:41:21.750212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\ndata_path = \"/kaggle/input/vinbigdata-chest-xray-abnormalities-detection\"\n\nprint(\"Files in dataset folder:\")\nprint(os.listdir(data_path))\n\ntrain_df = pd.read_csv(f\"{data_path}/train.csv\")\n\n# Unique class IDs and names\nclass_mapping = train_df[['class_id', 'class_name']].drop_duplicates().sort_values('class_id')\nprint(class_mapping)\n# Load only the real CSVs\ntrain_df = pd.read_csv(f\"{data_path}/train.csv\")\nsample_submission_df = pd.read_csv(f\"{data_path}/sample_submission.csv\")\n# test\n\n\n# Filter only rows that have bounding boxes (i.e., not \"No finding\")\nbbox_df = train_df[train_df[\"class_name\"] != \"No finding\"]\n\n# Count bounding boxes per class\nbbox_counts = bbox_df[\"class_name\"].value_counts().sort_values()\nprint(bbox_counts)\n\n# Horizontal bar plot\nplt.figure(figsize=(10, 8))\nbbox_counts.plot(kind=\"barh\", color=\"skyblue\")\nplt.title(\"Number of Bounding Boxes per Class\")\nplt.xlabel(\"Box Count\")\nplt.ylabel(\"Class Name\")\nplt.grid(axis=\"x\")\nplt.tight_layout()\nplt.show()\n\n# Filter out 'No finding'\nbbox_df = train_df[train_df[\"class_name\"] != \"No finding\"].copy()\nprint(bbox_df)\n# Calculate width, height, and area\nbbox_df[\"width\"] = bbox_df[\"x_max\"] - bbox_df[\"x_min\"]\nbbox_df[\"height\"] = bbox_df[\"y_max\"] - bbox_df[\"y_min\"]\nbbox_df[\"area\"] = bbox_df[\"width\"] * bbox_df[\"height\"]\n# Average area per class\navg_area = bbox_df.groupby(\"class_name\")[\"area\"].mean().sort_values()\nprint(avg_area)\nplt.figure(figsize=(10, 6))\navg_area.plot(kind='barh', color='lightcoral')\nplt.title(\"Average Bounding Box Area per Class\")\nplt.xlabel(\"Area (pixels)\")\nplt.ylabel(\"Class\")\nplt.grid(axis='x')\nplt.tight_layout()\nplt.show()\n\nplt.figure(figsize=(12, 6))\nsns.boxplot(x='class_name', y='width', data=bbox_df)\nplt.xticks(rotation=90)\nplt.title('Bounding Box Width Distribution by Class')\nplt.grid(True)\nplt.show()\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-01T13:51:36.124699Z","iopub.execute_input":"2025-06-01T13:51:36.125047Z","iopub.status.idle":"2025-06-01T13:51:37.397594Z","shell.execute_reply.started":"2025-06-01T13:51:36.125026Z","shell.execute_reply":"2025-06-01T13:51:37.396655Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}