{"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":[{"sourceId":37333,"databundleVersionId":3949526,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":false,"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\n# for 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\ndf = pd.read_csv(\"/kaggle/input/mayo-clinic-strip-ai/train.csv\")\nprint(df.head())","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:30.917465Z","iopub.execute_input":"2025-07-01T01:54:30.917752Z","iopub.status.idle":"2025-07-01T01:54:30.929653Z","shell.execute_reply.started":"2025-07-01T01:54:30.917733Z","shell.execute_reply":"2025-07-01T01:54:30.928378Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Num rows:\", len(df))\nprint(\"Unique patients:\", df['patient_id'].nunique())\nprint(\"Images per patient (avg):\", df.groupby('patient_id').size().mean())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:31.529264Z","iopub.execute_input":"2025-07-01T01:54:31.529557Z","iopub.status.idle":"2025-07-01T01:54:31.546574Z","shell.execute_reply.started":"2025-07-01T01:54:31.529535Z","shell.execute_reply":"2025-07-01T01:54:31.545511Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\nsns.countplot(data=df, x='label')\nplt.title('Label Distribution (CE vs LAA)')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:31.956404Z","iopub.execute_input":"2025-07-01T01:54:31.956767Z","iopub.status.idle":"2025-07-01T01:54:33.442043Z","shell.execute_reply.started":"2025-07-01T01:54:31.956739Z","shell.execute_reply":"2025-07-01T01:54:33.440632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Count occurrences of each label\nlabel_counts = df['label'].value_counts()\nprint(\"Label counts:\")\nprint(label_counts)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:33.443369Z","iopub.execute_input":"2025-07-01T01:54:33.443752Z","iopub.status.idle":"2025-07-01T01:54:33.453995Z","shell.execute_reply.started":"2025-07-01T01:54:33.443731Z","shell.execute_reply":"2025-07-01T01:54:33.452458Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"center_counts = df['center_id'].value_counts()\nprint(\"Sample count per center:\")\nprint(center_counts)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:41.263116Z","iopub.execute_input":"2025-07-01T01:54:41.263435Z","iopub.status.idle":"2025-07-01T01:54:41.272085Z","shell.execute_reply.started":"2025-07-01T01:54:41.263411Z","shell.execute_reply":"2025-07-01T01:54:41.270949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.crosstab(df['center_id'], df['label'], normalize='index') * 100","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:49.083149Z","iopub.execute_input":"2025-07-01T01:54:49.083462Z","iopub.status.idle":"2025-07-01T01:54:49.131342Z","shell.execute_reply.started":"2025-07-01T01:54:49.083439Z","shell.execute_reply":"2025-07-01T01:54:49.130304Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from PIL import Image\nimport matplotlib.pyplot as plt\n\n# Path to your image file (example)\nimg_path = '/kaggle/input/mayo-clinic-strip-ai/train/008e5c_0.tif'\n\n# Load image with PIL\nimg = Image.open(img_path)\n\n# Display image with matplotlib\nplt.figure(figsize=(8, 8))\nplt.imshow(img)\nplt.axis('off')  # Hide axis for cleaner view\nplt.title('Sample CE Visualization')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:54:51.63564Z","iopub.execute_input":"2025-07-01T01:54:51.636021Z","iopub.status.idle":"2025-07-01T01:55:09.948544Z","shell.execute_reply.started":"2025-07-01T01:54:51.635991Z","shell.execute_reply":"2025-07-01T01:55:09.947017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"img_path = '/kaggle/input/mayo-clinic-strip-ai/train/6baf51_0.tif'\nImage.MAX_IMAGE_PIXELS = None\n\n# Load image with PIL\nimg = Image.open(img_path)\n\n# Display image with matplotlib\nplt.figure(figsize=(8, 8))\nplt.imshow(img)\nplt.axis('off')  # Hide axis for cleaner view\nplt.title('Sample LAA Visualization')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:56:06.997655Z","iopub.execute_input":"2025-07-01T01:56:06.998638Z","iopub.status.idle":"2025-07-01T01:57:53.401642Z","shell.execute_reply.started":"2025-07-01T01:56:06.998609Z","shell.execute_reply":"2025-07-01T01:57:53.39997Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_image_size(image_id):\n    path = f'/kaggle/input/mayo-clinic-strip-ai/train/{image_id}.tif'\n    with Image.open(path) as img:\n        return img.size  # returns (width, height)\n\n# Apply to all images (warning: slow for big datasets)\ndf['image_size'] = df['image_id'].apply(get_image_size)\n\n# Split width and height into separate columns\ndf['width'] = df['image_size'].apply(lambda x: x[0])\ndf['height'] = df['image_size'].apply(lambda x: x[1])\n\n# Plot distributions\nplt.figure(figsize=(12,5))\nplt.subplot(1,2,1)\ndf['width'].hist(bins=30)\nplt.title('Image Width Distribution')\nplt.xlabel('Width (pixels)')\nplt.ylabel('Count')\n\nplt.subplot(1,2,2)\ndf['height'].hist(bins=30)\nplt.title('Image Height Distribution')\nplt.xlabel('Height (pixels)')\nplt.ylabel('Count')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:58:29.084673Z","iopub.execute_input":"2025-07-01T01:58:29.085027Z","iopub.status.idle":"2025-07-01T01:58:38.950875Z","shell.execute_reply.started":"2025-07-01T01:58:29.084995Z","shell.execute_reply":"2025-07-01T01:58:38.949832Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['area'] = df['width'] * df['height']\n\n# Find smallest and largest by area\nsmallest = df.loc[df['area'].idxmin()]\nlargest = df.loc[df['area'].idxmax()]\n\nprint(\"Smallest image:\")\nprint(f\"Image ID: {smallest['image_id']}\")\nprint(f\"Width: {smallest['width']} px, Height: {smallest['height']} px\")\nprint(f\"Area: {smallest['area']} pixels² ({smallest['area'] / 1_000_000:.2f} MP)\")\n\nprint(\"\\nLargest image:\")\nprint(f\"Image ID: {largest['image_id']}\")\nprint(f\"Width: {largest['width']} px, Height: {largest['height']} px\")\nprint(f\"Area: {largest['area']} pixels² ({largest['area'] / 1_000_000:.2f} MP)\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-01T01:59:23.36608Z","iopub.execute_input":"2025-07-01T01:59:23.366502Z","iopub.status.idle":"2025-07-01T01:59:23.37629Z","shell.execute_reply.started":"2025-07-01T01:59:23.366472Z","shell.execute_reply":"2025-07-01T01:59:23.375362Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pad smaller images or ","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"pad smaller images or compress -> think about\nfixed size for inputs for each model","metadata":{}}]}