{"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":"gpu","dataSources":[{"sourceId":112509,"databundleVersionId":14254895,"sourceType":"competition"},{"sourceId":642378,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":484430,"modelId":499917}],"dockerImageVersionId":31153,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from torch.utils.data import Dataset, DataLoader\nfrom PIL import Image\nfrom pathlib import Path\nfrom torchvision import transforms, models\nimport torch\nimport torch.nn as nn\nfrom sklearn.model_selection import train_test_split\nfrom tqdm import tqdm\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"9d43bdc5-d300-4608-8729-47caeab02910","_cell_guid":"a06eca58-3da7-4f30-a36a-c7ec55a0bb7c","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.395065Z","iopub.execute_input":"2025-11-22T09:34:52.395329Z","iopub.status.idle":"2025-11-22T09:34:52.402636Z","shell.execute_reply.started":"2025-11-22T09:34:52.395308Z","shell.execute_reply":"2025-11-22T09:34:52.402010Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")","metadata":{"_uuid":"5060e90a-468d-4c93-b3a2-e70044ab21f2","_cell_guid":"acd8d645-9821-48a5-8a9c-c99bdb3b24b3","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.403228Z","iopub.execute_input":"2025-11-22T09:34:52.403418Z","iopub.status.idle":"2025-11-22T09:34:52.413478Z","shell.execute_reply.started":"2025-11-22T09:34:52.403404Z","shell.execute_reply":"2025-11-22T09:34:52.412757Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"BASE_PATH = '/kaggle/input/csiro-biomass/'","metadata":{"_uuid":"cf2a489c-f7d3-48c5-94b7-d81b04e2204e","_cell_guid":"412d2fe6-5ba9-4eef-817c-2cc6f631b2f5","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.414192Z","iopub.execute_input":"2025-11-22T09:34:52.414442Z","iopub.status.idle":"2025-11-22T09:34:52.425411Z","shell.execute_reply.started":"2025-11-22T09:34:52.414419Z","shell.execute_reply":"2025-11-22T09:34:52.424719Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/csiro-biomass/train.csv')\ntrain_df.columns = train_df.columns.str.lower().str.strip()\n\n\n\n# Pivot the dataframe from long → wide format\ntrain_df_wide = train_df.pivot_table(\n    index=[\"image_path\", \"sampling_date\", \"state\", \"species\", \"pre_gshh_ndvi\", \"height_ave_cm\"],\n    columns=\"target_name\",\n    values=\"target\"\n).reset_index()\n# df_wide\ntrain_df_wide = train_df_wide[['image_path','Dry_Clover_g','Dry_Dead_g','Dry_Green_g','Dry_Total_g','GDM_g']]","metadata":{"_uuid":"8affab86-741f-4321-a296-57dc82a6019a","_cell_guid":"1ddfbd59-7341-4527-930b-16b1f202fde4","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.426101Z","iopub.execute_input":"2025-11-22T09:34:52.426345Z","iopub.status.idle":"2025-11-22T09:34:52.451648Z","shell.execute_reply.started":"2025-11-22T09:34:52.426326Z","shell.execute_reply":"2025-11-22T09:34:52.451156Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df, val_df = train_test_split(train_df_wide, test_size=0.2)\ntrain_df = train_df.reset_index(drop=True)\nval_df = val_df.reset_index(drop=True)","metadata":{"_uuid":"1fdd25b2-953d-45bb-897f-c7002e6b7e5a","_cell_guid":"a7717073-2a4f-4b12-b961-c28839139b38","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.452230Z","iopub.execute_input":"2025-11-22T09:34:52.452481Z","iopub.status.idle":"2025-11-22T09:34:52.457165Z","shell.execute_reply.started":"2025-11-22T09:34:52.452467Z","shell.execute_reply":"2025-11-22T09:34:52.456579Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/csiro-biomass/test.csv')\ntest_df.columns = test_df.columns.str.lower().str.strip()\n\n\ntest_df[\"image_id\"] = test_df[\"sample_id\"].str.split(\"__\").str[0]\n\ntest_df = (\n    test_df[['image_id', 'image_path']]\n    .drop_duplicates('image_id')\n    .reset_index(drop=True)\n)\n\n# test_df","metadata":{"_uuid":"c4a4eea7-25d1-4ab0-a8be-a3021ca4041c","_cell_guid":"4782314c-6c30-4eeb-899c-a6b33d457f25","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.457817Z","iopub.execute_input":"2025-11-22T09:34:52.458007Z","iopub.status.idle":"2025-11-22T09:34:52.473141Z","shell.execute_reply.started":"2025-11-22T09:34:52.457992Z","shell.execute_reply":"2025-11-22T09:34:52.472552Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class CustomDataset(Dataset):\n    def __init__(self, df:pd.DataFrame, BASE_PATH:Path):\n        super().__init__()\n        self.df = df\n        self.base_path = Path(BASE_PATH)\n\n        self.transform = transforms.Compose([\n            transforms.Resize((224, 224)),\n            transforms.ToTensor(),\n            transforms.Normalize(mean=[0.485, 0.456, 0.406],\n                                 std=[0.229, 0.224, 0.225]),\n        ])\n\n        self.target_cols = ['Dry_Clover_g', 'Dry_Dead_g', 'Dry_Green_g', 'Dry_Total_g', 'GDM_g']\n\n        # define which columns are features (excluding image and targets)\n        self.feature_cols = ['image_path']\n\n    def __len__(self):\n        return self.df.shape[0]\n\n    def __getitem__(self, idx):\n        to_tensor = transforms.ToTensor()\n        row = self.df.iloc[idx]\n        img_path = (Path(BASE_PATH).joinpath(row['image_path']))\n        img = Image.open(img_path)\n        img = self.transform(img)\n        \n        row_y = row[self.target_cols].values\n        row_y = np.array(row_y, dtype=np.float32)\n        row_y = torch.from_numpy(row_y).float()\n        \n        return {\n            'img':img,\n            'y_tab':row_y\n               }","metadata":{"_uuid":"fb01ab7a-997f-421d-bb00-9d2d6f0727a8","_cell_guid":"e9aa0928-2466-45d7-8555-35d55b730eab","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.474115Z","iopub.execute_input":"2025-11-22T09:34:52.474367Z","iopub.status.idle":"2025-11-22T09:34:52.480199Z","shell.execute_reply.started":"2025-11-22T09:34:52.474331Z","shell.execute_reply":"2025-11-22T09:34:52.479637Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class InferenceDataset(Dataset):\n    def __init__(self, df: pd.DataFrame, base_path: Path):\n        super().__init__()\n        self.df = df\n        self.base_path = base_path\n\n        self.transform = transforms.Compose([\n            transforms.Resize((224, 224)),\n            transforms.ToTensor(),\n            transforms.Normalize(mean=[0.485, 0.456, 0.406],\n                                 std=[0.229, 0.224, 0.225]),\n        ])\n    \n    def __len__(self):\n        return self.df.shape[0]\n\n    def __getitem__(self, idx):\n        row = self.df.iloc[idx]\n        image_id = row['image_id']\n        img_path = Path(self.base_path).joinpath(row['image_path']) \n        \n        # Load and transform image\n        img = Image.open(img_path).convert('RGB')\n        img = self.transform(img)\n        \n        return {\n            'img': img,\n            'image_id': image_id  # Return the identifier for tracking\n        }","metadata":{"_uuid":"e754571a-49cc-43b7-9a24-ba26e6654afa","_cell_guid":"1111682d-f05e-4d91-b983-be7c8f998b22","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.480818Z","iopub.execute_input":"2025-11-22T09:34:52.480995Z","iopub.status.idle":"2025-11-22T09:34:52.497573Z","shell.execute_reply.started":"2025-11-22T09:34:52.480982Z","shell.execute_reply":"2025-11-22T09:34:52.496865Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_ds = CustomDataset(val_df, BASE_PATH)\nval_dl = DataLoader(val_ds, batch_size=32, shuffle=True)\n\ntrain_ds = CustomDataset(train_df, BASE_PATH)\ntrain_dl = DataLoader(train_ds, batch_size=32, shuffle=True)\n\n\ntest_ds = InferenceDataset(test_df, BASE_PATH) \ntest_dl = DataLoader(test_ds, batch_size=32, shuffle=False)","metadata":{"_uuid":"1c6a1341-a707-4bf9-a86d-e8ab0263d098","_cell_guid":"e86d0690-e54e-4008-b941-4134c9ee4a9c","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.498215Z","iopub.execute_input":"2025-11-22T09:34:52.498414Z","iopub.status.idle":"2025-11-22T09:34:52.512895Z","shell.execute_reply.started":"2025-11-22T09:34:52.498391Z","shell.execute_reply":"2025-11-22T09:34:52.512192Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def weighted_mse_loss(y_true: torch.Tensor, y_pred: torch.Tensor, weights: torch.Tensor) -> torch.Tensor:\n    \"\"\"\n    Computes Weighted Mean Squared Error (WMSE).\n    \n    Args:\n        y_true: Tensor of ground-truth targets (Batch_size, 5)\n        y_pred: Tensor of model predictions (Batch_size, 5)\n        weights: Tensor of per-element weights (5,)\n        \n    Returns:\n        torch.Tensor: scalar WMSE loss value (lower is better)\n    \"\"\"\n    # 1. Calculate squared error (element-wise)\n    squared_error = (y_true - y_pred) ** 2\n    \n    # 2. Apply weights. Weights are (5,), expand to (1, 5) for broadcasting\n    # This multiplies the squared error of each target column by its weight\n    weighted_squared_error = squared_error * weights.view(1, -1)\n    \n    # 3. Sum the weighted errors and divide by the total number of elements\n    # Using mean over the entire tensor gives the mean of all 5 targets, weighted.\n    loss = weighted_squared_error.mean() \n    \n    return loss","metadata":{"_uuid":"63a9fc7a-8882-4fba-b923-95fcb07c5dab","_cell_guid":"15419b04-c487-4ec8-8870-c284bf0cdc0a","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.513666Z","iopub.execute_input":"2025-11-22T09:34:52.513886Z","iopub.status.idle":"2025-11-22T09:34:52.525039Z","shell.execute_reply.started":"2025-11-22T09:34:52.513870Z","shell.execute_reply":"2025-11-22T09:34:52.524339Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def weighted_r2(y_true, y_pred):\n    # weights per column (order must match your y)\n    weights = torch.tensor([0.1, 0.1, 0.1, 0.5, 0.2], device=y_true.device)\n    \n    # Flatten all samples into one vector per column\n    y_true_flat = y_true.view(-1, y_true.shape[-1])\n    y_pred_flat = y_pred.view(-1, y_pred.shape[-1])\n\n    # Weighted mean\n    w_sum = torch.sum(weights)\n    y_mean = torch.sum(weights * torch.mean(y_true_flat, dim=0)) / w_sum\n\n    # Weighted R² numerator/denominator\n    ss_res = torch.sum(weights * torch.sum((y_true_flat - y_pred_flat) ** 2, dim=0))\n    ss_tot = torch.sum(weights * torch.sum((y_true_flat - y_mean) ** 2, dim=0))\n    \n    r2 = 1 - ss_res / ss_tot\n    return r2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.525831Z","iopub.execute_input":"2025-11-22T09:34:52.526072Z","iopub.status.idle":"2025-11-22T09:34:52.538568Z","shell.execute_reply.started":"2025-11-22T09:34:52.526056Z","shell.execute_reply":"2025-11-22T09:34:52.538003Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class Model(nn.Module):\n    \"\"\"\n    uses a vit base to make embeddings of images and then add x no of linear layers\n    \"\"\"\n    def __init__(self, \n                 num_linear_layers:int,\n                 linear_layer_hidden_dim:int, \n                 output_dim:int=5, \n                 input_dim:int=22,\n                 pretrained_path:str=\"/kaggle/input/resnet/pytorch/default/1/resnet18.pth\"):\n        super().__init__()\n        # self.resnet = models.resnet18(pretrained=True)\n        # Load resnet18 backbone without downloading weights\n        self.resnet = models.resnet18(weights=None)\n        \n        # Load the saved pretrained weights manually (offline)\n        state_dict = torch.load(pretrained_path, map_location=\"cpu\")\n        self.resnet.load_state_dict(state_dict)\n        for param in self.resnet.parameters():\n            param.requires_grad = True\n        \n        \n        self.merge_head = nn.Sequential(\n            nn.Linear(1000,512),\n            nn.ReLU(),\n            nn.Dropout(0.1),\n            nn.Linear(512,1024),\n            nn.ReLU(),\n            nn.Dropout(0.1),\n            nn.Linear(1024,256),\n            nn.ReLU(),\n            nn.Dropout(0.1),\n            nn.Linear(256,128),\n            nn.ReLU(),\n            nn.Dropout(0.1),\n            nn.Linear(128, output_dim)\n        )\n\n    \n    def forward(self, img):\n        pred1 = self.resnet(img)\n        pred4 = self.merge_head(pred1)\n        return pred4","metadata":{"_uuid":"4bd255af-1d73-4730-9bbe-5ea619993cc6","_cell_guid":"2fddc014-8fcc-42dc-9408-bd068ed972e7","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.539266Z","iopub.execute_input":"2025-11-22T09:34:52.539523Z","iopub.status.idle":"2025-11-22T09:34:52.550658Z","shell.execute_reply.started":"2025-11-22T09:34:52.539503Z","shell.execute_reply":"2025-11-22T09:34:52.550046Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def train_one_epoch(model, dataloader, optimizer, weights):\n    model.train()\n    total_loss = 0.0\n    loss_train_mse = 0\n    loss_train_r2 = 0\n    for batch in tqdm(dataloader, desc=\"Training\"):\n        batch_count = 0\n        \n        imgs = batch['img'].to(device)\n        y_true = batch['y_tab'].to(device)\n        \n        optimizer.zero_grad()\n\n        y_pred = model(imgs)\n        \n        loss_mse = weighted_mse_loss(y_true, y_pred, weights)\n        loss_train_mse = loss_train_mse + loss_mse.item()*imgs.shape[0]\n        \n        loss_r2 = weighted_r2(y_true, y_pred)\n        loss_train_r2 = loss_train_r2 + loss_r2.item()\n        # loss = 1 -  weighted_mse(y_true, y_pred, weights)\n        \n        loss_mse.backward()\n        optimizer.step()\n        \n    avg_loss_mse = loss_train_mse/ len(dataloader.dataset)\n    avg_loss_r2 = loss_train_r2/ len(dataloader.dataset)\n    return avg_loss_r2, avg_loss_mse","metadata":{"_uuid":"61455f02-29bb-4262-938c-fe4817917ad5","_cell_guid":"6a7a7a08-cdc9-4a08-9516-e13706b2654d","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.551310Z","iopub.execute_input":"2025-11-22T09:34:52.551476Z","iopub.status.idle":"2025-11-22T09:34:52.565887Z","shell.execute_reply.started":"2025-11-22T09:34:52.551461Z","shell.execute_reply":"2025-11-22T09:34:52.565335Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def evaluate(model, dataloader, weights):\n    model.eval()\n    total_loss_r2 = 0.0\n    total_loss_mse = 0.0\n    y_true_all, y_pred_all = [], []\n\n    with torch.no_grad():\n        for batch in tqdm(dataloader, desc=\"Validation\"):\n            img = batch['img'].to(device)\n            y_true = batch['y_tab'].to(device)\n    \n            y_pred = model(img)\n            \n            loss_r2 = weighted_r2(y_true, y_pred)\n            total_loss_r2 += loss_r2.item()\n\n            loss_mse = weighted_mse_loss(y_true, y_pred, weights)\n            total_loss_mse += loss_mse.item() * img.size(0)\n\n    avg_loss_r2 = total_loss_r2 / len(dataloader.dataset)\n    avg_loss_mse = total_loss_mse / len(dataloader.dataset)\n\n    # Example: compute weighted R² later using your function\n    return avg_loss_r2, avg_loss_mse","metadata":{"_uuid":"61e6c77a-e033-4056-a3f3-db26a54ae4fe","_cell_guid":"ed1743c1-900b-44a0-b43f-e6fedab486d4","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.566541Z","iopub.execute_input":"2025-11-22T09:34:52.566825Z","iopub.status.idle":"2025-11-22T09:34:52.581333Z","shell.execute_reply.started":"2025-11-22T09:34:52.566803Z","shell.execute_reply":"2025-11-22T09:34:52.580678Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"EPOCHS = 2\nWEIGHTS = {\n    'Dry_Clover_g': 0.1,\n    'Dry_Dead_g': 0.1,\n    'Dry_Green_g': 0.1,\n    'Dry_Total_g': 0.5,\n    'GDM_g': 0.2,\n}\n\n\nweights = torch.tensor(list(WEIGHTS.values())).to(device)\nmodel_name = 'resnet_linear_tab'\ntrain_loss_mse_list = []\ntrain_loss_r2_list = []\n\nval_loss_mse_list = []\nval_loss_r2_list = []\n\nloss_init = 10000000.0\n\nmodel = Model(3,123, 5)\nmodel.to(device)\noptimizer = torch.optim.AdamW(model.parameters(), lr=1e-2)\n\nfor epoch in range(EPOCHS):\n    # training for 1 epoch and saving the loss\n    train_loss_r2, train_loss_mse  = train_one_epoch(model, train_dl, optimizer, weights)\n    train_loss_mse_list.append(train_loss_mse)\n    train_loss_r2_list.append(train_loss_r2)\n\n    # running the evaluation on validation set \n    val_loss_r2, val_loss_mse = evaluate(model, val_dl, weights)\n    val_loss_mse_list.append(val_loss_mse)\n    val_loss_r2_list.append(val_loss_r2)\n\n    # print for epoch, train_loss and val_loss\n    # print(f'train_loss_mse:{train_loss_mse}: train_loss_r2:{train_loss_r2}')\n    print(f'epoch:{epoch+1}|train_loss_mse:{train_loss_mse}|val_loss_mse:{val_loss_mse}:val_loss_r2:{val_loss_r2}')\n    # print(f'val_loss_mse  :{val_loss_mse}:   val_loss_r2:{val_loss_r2}')\n    # print(f'='*20)\n\n    # saving model if loss less than last loss\n    # if val_loss_mse < loss_init:\n    #     PATH = f\"/kaggle/working/{model_name}_best_model.pt\"\n    #     torch.save(model.state_dict(), PATH)\n    #     loss_init = val_loss_mse","metadata":{"_uuid":"8477d340-3d85-4730-8972-1909872b1ed5","_cell_guid":"274d4289-ea52-4a26-b321-bafe62bde2a2","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:34:52.585224Z","iopub.execute_input":"2025-11-22T09:34:52.585808Z","iopub.status.idle":"2025-11-22T09:35:28.922907Z","shell.execute_reply.started":"2025-11-22T09:34:52.585784Z","shell.execute_reply":"2025-11-22T09:35:28.922155Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.eval()\n# 3. Target columns and the normalization dictionary\n\nTARGET_COLS = list(WEIGHTS.keys())\nfinal_ids = []\nfinal_vals = []\n\nfor batch in test_dl:\n    img = batch['img'].to(device)\n    img_id = batch['image_id']\n    submission_list = [img_id[0] +\"__\"+ item for item in TARGET_COLS]\n    final_ids.extend(submission_list)\n    with torch.no_grad():\n        y_preds = model(img)\n        y_preds = y_preds.tolist()\n        final_vals.extend(y_preds[0])\n\n\ndf_final=pd.DataFrame({'sample_id':final_ids, 'target':final_vals})","metadata":{"_uuid":"c1005d9e-16a9-4119-8a67-2ff7ed1043a7","_cell_guid":"43af3254-7df6-45a8-9e72-7bca260ad686","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:35:28.923801Z","iopub.execute_input":"2025-11-22T09:35:28.924057Z","iopub.status.idle":"2025-11-22T09:35:28.987354Z","shell.execute_reply.started":"2025-11-22T09:35:28.924034Z","shell.execute_reply":"2025-11-22T09:35:28.986619Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_final","metadata":{"_uuid":"1ff4699a-8067-4878-a7c5-568422274733","_cell_guid":"b050e71d-582a-40e9-b81a-386bcd874f1d","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:35:28.988082Z","iopub.execute_input":"2025-11-22T09:35:28.988303Z","iopub.status.idle":"2025-11-22T09:35:28.995589Z","shell.execute_reply.started":"2025-11-22T09:35:28.988268Z","shell.execute_reply":"2025-11-22T09:35:28.994810Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_final.to_csv('/kaggle/working/submission.csv', index=False)","metadata":{"_uuid":"ea3153f3-a6df-4dd7-9ee3-e5c672af8b20","_cell_guid":"01a14675-65ed-43ff-bd46-37b25c9fe071","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:35:28.996253Z","iopub.execute_input":"2025-11-22T09:35:28.996470Z","iopub.status.idle":"2025-11-22T09:35:29.009960Z","shell.execute_reply.started":"2025-11-22T09:35:28.996456Z","shell.execute_reply":"2025-11-22T09:35:29.009341Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Create the list of epoch numbers (starting from 1)\nepochs = list(range(1, EPOCHS + 1))\n\nplt.figure(figsize=(8, 5))\n\n# Plot the data\nplt.plot(epochs, train_loss_mse_list, marker='o', linestyle='-', color='darkgreen')\n# plt.plot(epochs, val_loss_mse_list, linestyle='-', color='blue')\n\n# Set labels and title\nplt.xlabel(\"Epoch Number\")\nplt.ylabel(\"train loss mse\")\n# plt.title('plot_title')\n\n# Ensure all epochs are labeled on the x-axis\nplt.xticks(epochs) \nplt.grid(True, linestyle='--', alpha=0.6)\nplt.show()\n# Save the file\n# plt.savefig(\"epoch_vs_train_loss_mse.png\")\n# plt.close()","metadata":{"_uuid":"726b2208-c51d-4fcd-bec2-efeb30c15141","_cell_guid":"5d56a188-4d04-4a0d-a01c-1997868b1709","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:35:29.010592Z","iopub.execute_input":"2025-11-22T09:35:29.010777Z","iopub.status.idle":"2025-11-22T09:35:29.123360Z","shell.execute_reply.started":"2025-11-22T09:35:29.010764Z","shell.execute_reply":"2025-11-22T09:35:29.122650Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Create the list of epoch numbers (starting from 1)\nepochs = list(range(1, EPOCHS + 1))\n\nplt.figure(figsize=(8, 5))\n\n# Plot the data\n# plt.plot(epochs, train_loss_mse_list, marker='o', linestyle='-', color='darkgreen')\nplt.plot(epochs, val_loss_mse_list, linestyle='-', color='blue')\n\n# Set labels and title\nplt.xlabel(\"Epoch Number\")\nplt.ylabel(\"val-loss-mse\")\n# plt.title('plot_title')\n\n# Ensure all epochs are labeled on the x-axis\nplt.xticks(epochs) \nplt.grid(True, linestyle='--', alpha=0.6)\nplt.show()\n# Save the file\n# plt.savefig(\"epoch_vs_val_loss_mse.png\")\n# plt.close()","metadata":{"_uuid":"e6210cf2-ad0d-4631-9b3f-12cba4ecbd20","_cell_guid":"29edbb6d-69f1-47a0-a44f-f354907fa73f","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2025-11-22T09:35:29.124074Z","iopub.execute_input":"2025-11-22T09:35:29.124379Z","iopub.status.idle":"2025-11-22T09:35:29.243148Z","shell.execute_reply.started":"2025-11-22T09:35:29.124361Z","shell.execute_reply":"2025-11-22T09:35:29.242596Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Create the list of epoch numbers (starting from 1)\nepochs = list(range(1, EPOCHS + 1))\n\nplt.figure(figsize=(8, 5))\n\n# Plot the data\n# plt.plot(epochs, train_loss_mse_list, marker='o', linestyle='-', color='darkgreen')\nplt.plot(epochs, val_loss_r2_list, linestyle='-', color='blue')\n\n# Set labels and title\nplt.xlabel(\"Epoch Number\")\nplt.ylabel(\"val-loss-mse\")\n# plt.title('plot_title')\n\n# Ensure all epochs are labeled on the x-axis\nplt.xticks(epochs) \nplt.grid(True, linestyle='--', alpha=0.6)\nplt.show()\n# Save the file\n# plt.savefig(\"epoch_vs_val_loss_r2.png\")\n# plt.close()","metadata":{"_uuid":"4a19f494-9465-4296-be9f-b0aaa45b6d34","_cell_guid":"5316c35d-17d3-43b6-b509-132bad6d86c7","trusted":true,"collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2025-11-22T09:35:29.243808Z","iopub.execute_input":"2025-11-22T09:35:29.244044Z","iopub.status.idle":"2025-11-22T09:35:29.345233Z","shell.execute_reply.started":"2025-11-22T09:35:29.244028Z","shell.execute_reply":"2025-11-22T09:35:29.344601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(\"submission.csv\")\norder = [\"Dry_Clover_g\", \"Dry_Dead_g\", \"Dry_Green_g\", \"Dry_Total_g\", \"GDM_g\"]\ndf = df.iloc[df['sample_id'].map(lambda x: order.index(x.split('__')[1])).argsort(kind='mergesort')]\ndf.to_csv(\"submission.csv\", index=False)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-22T09:39:46.765050Z","iopub.execute_input":"2025-11-22T09:39:46.765868Z","iopub.status.idle":"2025-11-22T09:39:46.775782Z","shell.execute_reply.started":"2025-11-22T09:39:46.765837Z","shell.execute_reply":"2025-11-22T09:39:46.775022Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"a = df.to_csv(index=False)\nprint(a)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-22T09:39:47.607783Z","iopub.execute_input":"2025-11-22T09:39:47.608492Z","iopub.status.idle":"2025-11-22T09:39:47.613079Z","shell.execute_reply.started":"2025-11-22T09:39:47.608466Z","shell.execute_reply":"2025-11-22T09:39:47.612326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":" # !head '/kaggle/input/csiro-biomass/sample_submission.csv'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-22T09:38:39.254909Z","iopub.execute_input":"2025-11-22T09:38:39.255568Z","iopub.status.idle":"2025-11-22T09:38:39.402044Z","shell.execute_reply.started":"2025-11-22T09:38:39.255542Z","shell.execute_reply":"2025-11-22T09:38:39.401335Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}