{"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":"code","source":"import pandas as pd\nimport numpy as np\nfrom PIL import Image\nImage.MAX_IMAGE_PIXELS = None\n\nfrom collections import Counter\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-07T01:07:47.913483Z","iopub.execute_input":"2023-10-07T01:07:47.913889Z","iopub.status.idle":"2023-10-07T01:07:47.918975Z","shell.execute_reply.started":"2023-10-07T01:07:47.913848Z","shell.execute_reply":"2023-10-07T01:07:47.918148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT_DIR = \"/kaggle/input/UBC-OCEAN\"","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:06:57.44576Z","iopub.execute_input":"2023-10-07T01:06:57.446357Z","iopub.status.idle":"2023-10-07T01:06:57.45105Z","shell.execute_reply.started":"2023-10-07T01:06:57.44633Z","shell.execute_reply":"2023-10-07T01:06:57.44991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# CSV files","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_csv(f\"{ROOT_DIR}/train.csv\")\ndf_test = pd.read_csv( f\"{ROOT_DIR}/test.csv\")\ndf_sub  = pd.read_csv( f\"{ROOT_DIR}/sample_submission.csv\")\nprint(df_train.shape, df_test.shape, df_sub.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:06:57.452547Z","iopub.execute_input":"2023-10-07T01:06:57.453179Z","iopub.status.idle":"2023-10-07T01:06:57.50124Z","shell.execute_reply.started":"2023-10-07T01:06:57.453142Z","shell.execute_reply":"2023-10-07T01:06:57.500209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(df_train.head(10))\nplt.hist(df_train[\"label\"])\nplt.xlabel(\"label\")\nplt.ylabel(\"counts\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:06:57.503251Z","iopub.execute_input":"2023-10-07T01:06:57.503553Z","iopub.status.idle":"2023-10-07T01:06:57.768217Z","shell.execute_reply.started":"2023-10-07T01:06:57.503527Z","shell.execute_reply":"2023-10-07T01:06:57.766896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(df_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:06:57.770829Z","iopub.execute_input":"2023-10-07T01:06:57.771136Z","iopub.status.idle":"2023-10-07T01:07:01.700445Z","shell.execute_reply.started":"2023-10-07T01:06:57.77111Z","shell.execute_reply":"2023-10-07T01:07:01.699633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gdfs = []\nlabels = []\nfor label, gdf in df_train.groupby(\"label\"):\n    gdfs.append(gdf)\n    labels.append(label)\n    \nfor column in [\"image_width\", \"image_height\", \"is_tma\"]:\n    plt.hist([gdf[column] for gdf in gdfs], bins=5, label=labels)\n    plt.legend(loc='upper right')\n    plt.xlabel( column )\n    plt.ylabel( \"count of records\" )\n    plt.title( f\"Histogram of {column}\" )\n    plt.grid()\n    plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:22:37.885688Z","iopub.execute_input":"2023-10-07T01:22:37.88608Z","iopub.status.idle":"2023-10-07T01:22:38.82907Z","shell.execute_reply.started":"2023-10-07T01:22:37.886052Z","shell.execute_reply":"2023-10-07T01:22:38.82783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head(1)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:20:20.383621Z","iopub.execute_input":"2023-10-07T01:20:20.384599Z","iopub.status.idle":"2023-10-07T01:20:20.393075Z","shell.execute_reply.started":"2023-10-07T01:20:20.384544Z","shell.execute_reply":"2023-10-07T01:20:20.392227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.head(1)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:20:22.871393Z","iopub.execute_input":"2023-10-07T01:20:22.872569Z","iopub.status.idle":"2023-10-07T01:20:22.883172Z","shell.execute_reply.started":"2023-10-07T01:20:22.872521Z","shell.execute_reply":"2023-10-07T01:20:22.882041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train image thumbnail","metadata":{}},{"cell_type":"code","source":"DISP_SIZE = 256\nNUM_DISP_PER_LABEL = 5\n\nfor label, gdf in df_train.groupby(\"label\"):\n    \n    print(\"\\n\\n\" + \"=\" * 100)\n    print(f\"// label = {label}\")\n    cnt = 0\n    for i, row in gdf.iterrows():\n        try:\n            file_image = f\"{ROOT_DIR}/train_images/{row.image_id}.png\"\n            file_thumbnail = f\"{ROOT_DIR}/train_thumbnails/{row.image_id}_thumbnail.png\"\n            image = Image.open(file_thumbnail)\n        except:\n            continue\n        print( f\"  image_id = {row.image_id}\" )\n        display( image.resize( (image.size[0] * DISP_SIZE // image.size[1], DISP_SIZE ) ) )\n        cnt += 1\n        if cnt >= NUM_DISP_PER_LABEL:\n            break","metadata":{"execution":{"iopub.status.busy":"2023-10-07T01:20:24.277554Z","iopub.execute_input":"2023-10-07T01:20:24.278622Z","iopub.status.idle":"2023-10-07T01:20:31.492396Z","shell.execute_reply.started":"2023-10-07T01:20:24.278585Z","shell.execute_reply":"2023-10-07T01:20:31.491317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}