{"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":112509,"databundleVersionId":14254895,"sourceType":"competition"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport cv2\nimport PIL\nimport matplotlib.pyplot as plt\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:50:57.321833Z","iopub.execute_input":"2025-10-31T14:50:57.322164Z","iopub.status.idle":"2025-10-31T14:50:57.327311Z","shell.execute_reply.started":"2025-10-31T14:50:57.322143Z","shell.execute_reply":"2025-10-31T14:50:57.326209Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data  = pd.read_csv('/kaggle/input/csiro-biomass/train.csv')\ntrain_data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:15:50.303647Z","iopub.execute_input":"2025-10-31T14:15:50.304020Z","iopub.status.idle":"2025-10-31T14:15:50.367674Z","shell.execute_reply.started":"2025-10-31T14:15:50.303984Z","shell.execute_reply":"2025-10-31T14:15:50.366570Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data = pd.read_csv('/kaggle/input/csiro-biomass/test.csv')\ntest_data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:16:22.144899Z","iopub.execute_input":"2025-10-31T14:16:22.145328Z","iopub.status.idle":"2025-10-31T14:16:22.160907Z","shell.execute_reply.started":"2025-10-31T14:16:22.145305Z","shell.execute_reply":"2025-10-31T14:16:22.159948Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/csiro-biomass/sample_submission.csv')\nsample_submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:17:22.110099Z","iopub.execute_input":"2025-10-31T14:17:22.110451Z","iopub.status.idle":"2025-10-31T14:17:22.122096Z","shell.execute_reply.started":"2025-10-31T14:17:22.110423Z","shell.execute_reply":"2025-10-31T14:17:22.121202Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:25:51.190079Z","iopub.execute_input":"2025-10-31T14:25:51.190796Z","iopub.status.idle":"2025-10-31T14:25:51.198091Z","shell.execute_reply.started":"2025-10-31T14:25:51.190770Z","shell.execute_reply":"2025-10-31T14:25:51.197187Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data['Species'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:26:07.739789Z","iopub.execute_input":"2025-10-31T14:26:07.740114Z","iopub.status.idle":"2025-10-31T14:26:07.752322Z","shell.execute_reply.started":"2025-10-31T14:26:07.740089Z","shell.execute_reply":"2025-10-31T14:26:07.751361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data['target_name'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:27:21.018508Z","iopub.execute_input":"2025-10-31T14:27:21.018824Z","iopub.status.idle":"2025-10-31T14:27:21.027127Z","shell.execute_reply.started":"2025-10-31T14:27:21.018801Z","shell.execute_reply":"2025-10-31T14:27:21.026209Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def plot_multiple_images_per_class(df, image_path_col, class_col, samples_per_class=3):\n  \n    classes = df[class_col].unique()\n    \n    # Create subplot grid\n    fig, axes = plt.subplots(len(classes), samples_per_class, \n                            figsize=(15, 5*len(classes)))\n    \n    # Handle single class case\n    if len(classes) == 1:\n        axes = axes.reshape(1, -1)\n    \n    for row, class_name in enumerate(classes):\n        # Get images for this class\n        class_images = df[df[class_col] == class_name][image_path_col].tolist()\n        \n        # Take first 'samples_per_class' images\n        selected_images = class_images[:samples_per_class]\n        \n        for col, img_path in enumerate(selected_images):\n            ax = axes[row, col] if len(classes) > 1 else axes[col]\n            \n            # Read and process image\n            if os.path.exists(img_path):\n                img = cv2.imread(img_path)\n                if img is not None:\n                    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n                    \n                    # Display image\n                    ax.imshow(img_rgb)\n                    ax.set_title(f'Class: {class_name}\\n{os.path.basename(img_path)}', \n                                fontsize=10, pad=5)\n                    ax.axis('off')\n                else:\n                    # Display placeholder if image couldn't be loaded\n                    ax.text(0.5, 0.5, 'Image\\nnot found', \n                           ha='center', va='center', transform=ax.transAxes,\n                           fontsize=12, color='red')\n                    ax.axis('off')\n            else:\n                # Display placeholder if file doesn't exist\n                ax.text(0.5, 0.5, 'File\\nnot found', \n                       ha='center', va='center', transform=ax.transAxes,\n                       fontsize=12, color='red')\n                ax.axis('off')\n    \n    plt.tight_layout()\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:51:01.609851Z","iopub.execute_input":"2025-10-31T14:51:01.610701Z","iopub.status.idle":"2025-10-31T14:51:01.620256Z","shell.execute_reply.started":"2025-10-31T14:51:01.610672Z","shell.execute_reply":"2025-10-31T14:51:01.619252Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nbase_dir = \"/kaggle/input/csiro-biomass\"\ntrain_data['full_image_path'] = train_data['image_path'].apply(lambda x: os.path.join(base_dir, x))\n\n\nplot_multiple_images_per_class(train_data, 'full_image_path', 'Species', samples_per_class=3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:51:01.728764Z","iopub.execute_input":"2025-10-31T14:51:01.729872Z","iopub.status.idle":"2025-10-31T14:51:20.084092Z","shell.execute_reply.started":"2025-10-31T14:51:01.729836Z","shell.execute_reply":"2025-10-31T14:51:20.082527Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plot_multiple_images_per_class(train_data, 'full_image_path', 'target_name', samples_per_class=3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-31T14:56:09.640546Z","iopub.execute_input":"2025-10-31T14:56:09.640879Z","iopub.status.idle":"2025-10-31T14:56:15.567705Z","shell.execute_reply.started":"2025-10-31T14:56:09.640854Z","shell.execute_reply":"2025-10-31T14:56:15.566209Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}