{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":112509,"databundleVersionId":14254895,"sourceType":"competition"}],"dockerImageVersionId":31240,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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 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","trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:19:27.583543Z","iopub.execute_input":"2025-12-23T16:19:27.583743Z","iopub.status.idle":"2025-12-23T16:19:29.621179Z","shell.execute_reply.started":"2025-12-23T16:19:27.583726Z","shell.execute_reply":"2025-12-23T16:19:29.619793Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\n\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom sklearn.preprocessing import MinMaxScaler, LabelEncoder\nfrom sklearn.model_selection import train_test_split\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:23:28.890689Z","iopub.execute_input":"2025-12-23T16:23:28.891266Z","iopub.status.idle":"2025-12-23T16:23:29.950461Z","shell.execute_reply.started":"2025-12-23T16:23:28.891227Z","shell.execute_reply":"2025-12-23T16:23:29.949838Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/csiro-biomass/train.csv\")\ntest_df  = pd.read_csv(\"/kaggle/input/csiro-biomass/test.csv\")\n\nprint(train_df.shape)\ntrain_df.head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:24:00.875106Z","iopub.execute_input":"2025-12-23T16:24:00.875988Z","iopub.status.idle":"2025-12-23T16:24:00.921103Z","shell.execute_reply.started":"2025-12-23T16:24:00.875957Z","shell.execute_reply":"2025-12-23T16:24:00.920581Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isnull().sum()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:24:19.203788Z","iopub.execute_input":"2025-12-23T16:24:19.204289Z","iopub.status.idle":"2025-12-23T16:24:19.210934Z","shell.execute_reply.started":"2025-12-23T16:24:19.204268Z","shell.execute_reply":"2025-12-23T16:24:19.210303Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(\n    x=\"target_name\",\n    y=\"target\",\n    data=train_df\n)\nplt.xticks(rotation=45)\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:24:30.682695Z","iopub.execute_input":"2025-12-23T16:24:30.683191Z","iopub.status.idle":"2025-12-23T16:24:30.893526Z","shell.execute_reply.started":"2025-12-23T16:24:30.683170Z","shell.execute_reply":"2025-12-23T16:24:30.892815Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Kaggle dataset root\nROOT_DIR = \"/kaggle/input/csiro-biomass\"\n\n# CSV files\ntrain_df = pd.read_csv(os.path.join(ROOT_DIR, \"train.csv\"))\ntest_df = pd.read_csv(os.path.join(ROOT_DIR, \"test.csv\"))\n\n# Check columns\nprint(train_df.columns)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:37:08.634164Z","iopub.execute_input":"2025-12-23T16:37:08.634730Z","iopub.status.idle":"2025-12-23T16:37:08.648952Z","shell.execute_reply.started":"2025-12-23T16:37:08.634705Z","shell.execute_reply":"2025-12-23T16:37:08.648407Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# train image full path\ntrain_df['image_full_path'] = train_df['image_path'].apply(lambda x: os.path.join(ROOT_DIR, x))\n\n# Safety check: first 5 images\nfor path in train_df['image_full_path'].head():\n    assert os.path.exists(path), f\"File not found: {path}\"\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:37:31.258018Z","iopub.execute_input":"2025-12-23T16:37:31.258283Z","iopub.status.idle":"2025-12-23T16:37:31.266688Z","shell.execute_reply.started":"2025-12-23T16:37:31.258264Z","shell.execute_reply":"2025-12-23T16:37:31.266049Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['image_id'] = train_df['image_path'].apply(lambda x: os.path.basename(x).split('.')[0])\ntrain_df[['image_path','image_id']].head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:37:46.394869Z","iopub.execute_input":"2025-12-23T16:37:46.395591Z","iopub.status.idle":"2025-12-23T16:37:46.405738Z","shell.execute_reply.started":"2025-12-23T16:37:46.395561Z","shell.execute_reply":"2025-12-23T16:37:46.405176Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cat_cols = ['target_name', 'State', 'Species']\n\nle_dict = {}\nfor col in cat_cols:\n    le = LabelEncoder()\n    train_df[col] = le.fit_transform(train_df[col])\n    le_dict[col] = le\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:38:03.708458Z","iopub.execute_input":"2025-12-23T16:38:03.709138Z","iopub.status.idle":"2025-12-23T16:38:03.715558Z","shell.execute_reply.started":"2025-12-23T16:38:03.709115Z","shell.execute_reply":"2025-12-23T16:38:03.714842Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_cols = ['Pre_GSHH_NDVI', 'Height_Ave_cm']\n\nscaler = MinMaxScaler()\ntrain_df[num_cols] = scaler.fit_transform(train_df[num_cols])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:38:12.346760Z","iopub.execute_input":"2025-12-23T16:38:12.347292Z","iopub.status.idle":"2025-12-23T16:38:12.356190Z","shell.execute_reply.started":"2025-12-23T16:38:12.347268Z","shell.execute_reply":"2025-12-23T16:38:12.355567Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def load_image(img_path, size=(224,224)):\n    img = cv2.imread(img_path)\n    if img is None:\n        raise FileNotFoundError(f\"Image not found: {img_path}\")\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    img = cv2.resize(img, size)\n    img = img / 255.0  # normalize\n    return img\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:38:20.514500Z","iopub.execute_input":"2025-12-23T16:38:20.514777Z","iopub.status.idle":"2025-12-23T16:38:20.519257Z","shell.execute_reply.started":"2025-12-23T16:38:20.514755Z","shell.execute_reply":"2025-12-23T16:38:20.518595Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_arrays = []\nimage_ids = train_df['image_full_path'].unique()[:10]\n\nfor path in image_ids:\n    img = load_image(path)\n    image_arrays.append(img)\n\nprint(\"Loaded images shape:\", np.array(image_arrays).shape)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:38:31.482209Z","iopub.execute_input":"2025-12-23T16:38:31.482479Z","iopub.status.idle":"2025-12-23T16:38:32.157367Z","shell.execute_reply.started":"2025-12-23T16:38:31.482459Z","shell.execute_reply":"2025-12-23T16:38:32.156706Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Example: only CSV features for now\nX_tab = train_df[['Pre_GSHH_NDVI', 'Height_Ave_cm', 'State', 'Species']].values\ny = train_df['target'].values\n\nX_train_tab, X_val_tab, y_train, y_val = train_test_split(\n    X_tab, y, test_size=0.2, random_state=42\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:38:50.494597Z","iopub.execute_input":"2025-12-23T16:38:50.495313Z","iopub.status.idle":"2025-12-23T16:38:50.501482Z","shell.execute_reply.started":"2025-12-23T16:38:50.495287Z","shell.execute_reply":"2025-12-23T16:38:50.500833Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import random\n\nsample_path = random.choice(train_df['image_full_path'].values)\nimg = load_image(sample_path)\n\nplt.imshow(img)\nplt.axis(\"off\")\nplt.title(os.path.basename(sample_path))\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-23T16:39:13.092184Z","iopub.execute_input":"2025-12-23T16:39:13.092711Z","iopub.status.idle":"2025-12-23T16:39:13.315709Z","shell.execute_reply.started":"2025-12-23T16:39:13.092688Z","shell.execute_reply":"2025-12-23T16:39:13.315048Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}