{"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"}],"dockerImageVersionId":30626,"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 zip(range(10), 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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-15T23:13:29.368324Z","iopub.execute_input":"2023-12-15T23:13:29.368809Z","iopub.status.idle":"2023-12-15T23:13:29.389312Z","shell.execute_reply.started":"2023-12-15T23:13:29.368776Z","shell.execute_reply":"2023-12-15T23:13:29.38818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os, glob\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nDATASET_FOLDER = \"/kaggle/input/UBC-OCEAN/\"","metadata":{"execution":{"iopub.status.busy":"2023-12-15T23:37:12.136258Z","iopub.execute_input":"2023-12-15T23:37:12.13664Z","iopub.status.idle":"2023-12-15T23:37:12.646871Z","shell.execute_reply.started":"2023-12-15T23:37:12.136611Z","shell.execute_reply":"2023-12-15T23:37:12.645303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(os.path.join(DATASET_FOLDER, \"train.csv\"))\n# labels = list(df_train[\"label\"].unique())\nprint(f\"Dataset/train size: {len(df_train)}\")\ndisplay(df_train.head())","metadata":{"execution":{"iopub.status.busy":"2023-12-15T23:16:33.639207Z","iopub.execute_input":"2023-12-15T23:16:33.639656Z","iopub.status.idle":"2023-12-15T23:16:33.693542Z","shell.execute_reply.started":"2023-12-15T23:16:33.639619Z","shell.execute_reply":"2023-12-15T23:16:33.691719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## The distribution of labels\n\nWe have waymore HGSC kind and EC","metadata":{}},{"cell_type":"code","source":"_= df_train[[\"label\"]].value_counts().plot.pie(autopct='%1.1f%%', ylabel=\"label\")","metadata":{"execution":{"iopub.status.busy":"2023-12-15T23:17:05.907424Z","iopub.execute_input":"2023-12-15T23:17:05.907868Z","iopub.status.idle":"2023-12-15T23:17:06.154306Z","shell.execute_reply.started":"2023-12-15T23:17:05.907831Z","shell.execute_reply":"2023-12-15T23:17:06.153404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## TMA distribition\n\nLooks like very few samples have TMA","metadata":{}},{"cell_type":"code","source":"grouped_tma = df_train.groupby(\"is_tma\", as_index=False)[[\"label\"]]\ndf_grouped = grouped_tma.value_counts()\ndf_grouped = df_grouped.groupby(['label', 'is_tma']).sum().unstack()\ndisplay(df_grouped)\n_ = df_grouped.plot(kind=\"bar\", grid=True, figsize=(5, 2))","metadata":{"execution":{"iopub.status.busy":"2023-12-15T23:31:39.597954Z","iopub.execute_input":"2023-12-15T23:31:39.598417Z","iopub.status.idle":"2023-12-15T23:31:40.098488Z","shell.execute_reply.started":"2023-12-15T23:31:39.598329Z","shell.execute_reply":"2023-12-15T23:31:40.096836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def cdiv(a, b):\n    return -(a // -b)","metadata":{"execution":{"iopub.status.busy":"2023-12-15T23:57:39.021084Z","iopub.execute_input":"2023-12-15T23:57:39.021442Z","iopub.status.idle":"2023-12-15T23:57:39.026079Z","shell.execute_reply.started":"2023-12-15T23:57:39.021413Z","shell.execute_reply":"2023-12-15T23:57:39.024879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Image sizes\n\nThey are all over the place","metadata":{}},{"cell_type":"code","source":"sns.scatterplot(\n    df_train, \n    x='image_width', \n    y='image_height',\n    hue='label')\n","metadata":{"execution":{"iopub.status.busy":"2023-12-16T00:08:19.097234Z","iopub.execute_input":"2023-12-16T00:08:19.097677Z","iopub.status.idle":"2023-12-16T00:08:19.496161Z","shell.execute_reply.started":"2023-12-16T00:08:19.097645Z","shell.execute_reply":"2023-12-16T00:08:19.495079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for lb, dfg in df_train.groupby(\"label\"):\n    fig, axes = plt.subplots(ncols=4, figsize=(16, 4))\n    for i, name in enumerate(dfg[\"image_id\"].sample(4)):\n        # print(f\"{lb}: {name}\")\n        img_path = os.path.join(DATASET_FOLDER, \"train_thumbnails\", f\"{name}_thumbnail.png\")\n        if not os.path.isfile(img_path):\n            img_path = os.path.join(DATASET_FOLDER, \"train_images\", f\"{name}.png\")\n            print(f\"Missing thumbnail for {img_path} but img exists {os.path.isfile(img_path)}\")\n            continue\n        axes[i].imshow(plt.imread(img_path))\n        axes[i].set_title(f\"{lb}\")\n        axes[i].set_axis_off()\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-16T00:20:39.515395Z","iopub.execute_input":"2023-12-16T00:20:39.515782Z","iopub.status.idle":"2023-12-16T00:21:05.576886Z","shell.execute_reply.started":"2023-12-16T00:20:39.51575Z","shell.execute_reply":"2023-12-16T00:21:05.575906Z"},"trusted":true},"execution_count":null,"outputs":[]}]}