{"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,"isSourceIdPinned":false,"sourceType":"competition"}],"dockerImageVersionId":31239,"isInternetEnabled":false,"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 matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Load the dataset\nfile_path = '/kaggle/input/csiro-biomass/train.csv'\ndf = pd.read_csv(file_path)\n\n# Display basic information about the dataset\nprint(\"Dataset Shape:\", df.shape)\nprint(\"\\nColumn Names:\")\nfor i, col in enumerate(df.columns, 1):\n    print(f\"  {i}. {col}\")\n\nprint(\"\\nData Types:\")\nprint(df.dtypes)\n\nprint(\"\\nFirst 5 Rows:\")\nprint(df.head())\n\nprint(\"\\nBasic Statistical Summary:\")\nprint(df.describe())","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:39.262548Z","iopub.execute_input":"2025-12-21T08:40:39.262997Z","iopub.status.idle":"2025-12-21T08:40:39.291468Z","shell.execute_reply.started":"2025-12-21T08:40:39.262962Z","shell.execute_reply":"2025-12-21T08:40:39.290125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check for missing values\nprint(\"Missing Values:\")\nmissing_values = df.isnull().sum()\nprint(missing_values[missing_values > 0])\n\n# Analyze categorical variables\nprint(\"\\nUnique values in categorical columns:\")\ncategorical_columns = ['State', 'Species', 'target_name']\nfor col in categorical_columns:\n    print(f\"\\n{col}:\")\n    print(df[col].value_counts())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:39.293526Z","iopub.execute_input":"2025-12-21T08:40:39.293803Z","iopub.status.idle":"2025-12-21T08:40:39.306033Z","shell.execute_reply.started":"2025-12-21T08:40:39.293782Z","shell.execute_reply":"2025-12-21T08:40:39.305014Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.style.use('default')\nplt.rcParams.update({'figure.autolayout': True})\n\n# Create visualizations for numerical distributions\nfig, axes = plt.subplots(2, 2, figsize=(15, 10))\nfig.suptitle('Distribution of Numerical Variables', fontsize=16)\n\n# Pre_GSHH_NDVI distribution\naxes[0, 0].hist(df['Pre_GSHH_NDVI'], bins=30, color=plt.cm.tab20c(1), edgecolor='black')\naxes[0, 0].set_title('Pre_GSHH_NDVI Distribution')\naxes[0, 0].set_xlabel('Pre_GSHH_NDVI')\naxes[0, 0].set_ylabel('Frequency')\n\n# Height_Ave_cm distribution\naxes[0, 1].hist(df['Height_Ave_cm'], bins=30, color=plt.cm.tab20c(5), edgecolor='black')\naxes[0, 1].set_title('Height_Ave_cm Distribution')\naxes[0, 1].set_xlabel('Height_Ave_cm')\naxes[0, 1].set_ylabel('Frequency')\n\n# Target distribution\naxes[1, 0].hist(df['target'], bins=30, color=plt.cm.tab20c(9), edgecolor='black')\naxes[1, 0].set_title('Target Distribution')\naxes[1, 0].set_xlabel('Target')\naxes[1, 0].set_ylabel('Frequency')\n\n# Box plot for all numerical variables\nnumerical_vars = ['Pre_GSHH_NDVI', 'Height_Ave_cm', 'target']\ndf[numerical_vars].boxplot(ax=axes[1, 1])\naxes[1, 1].set_title('Box Plots of Numerical Variables')\naxes[1, 1].tick_params(axis='x', rotation=45)\n\nplt.tight_layout()\nplt.savefig('numerical_distributions.png')\nprint(\"numerical_distributions.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:39.307194Z","iopub.execute_input":"2025-12-21T08:40:39.307560Z","iopub.status.idle":"2025-12-21T08:40:40.731561Z","shell.execute_reply.started":"2025-12-21T08:40:39.307527Z","shell.execute_reply":"2025-12-21T08:40:40.730466Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Visualize categorical variables\nfig, axes = plt.subplots(1, 3, figsize=(18, 6))\n\n# State distribution\nstate_counts = df['State'].value_counts()\naxes[0].bar(state_counts.index, state_counts.values, color=plt.cm.tab20c.colors)\naxes[0].set_title('Distribution of States')\naxes[0].set_xlabel('State')\naxes[0].set_ylabel('Count')\naxes[0].tick_params(axis='x', rotation=45)\n\n# Species distribution (top 10)\nspecies_counts = df['Species'].value_counts().head(10)\naxes[1].bar(species_counts.index, species_counts.values, color=plt.cm.tab20c.colors)\naxes[1].set_title('Top 10 Species Distribution')\naxes[1].set_xlabel('Species')\naxes[1].set_ylabel('Count')\naxes[1].tick_params(axis='x', rotation=45)\n\n# Target name distribution\ntarget_counts = df['target_name'].value_counts()\naxes[2].bar(target_counts.index, target_counts.values, color=plt.cm.tab20c.colors)\naxes[2].set_title('Target Name Distribution')\naxes[2].set_xlabel('Target Name')\naxes[2].set_ylabel('Count')\naxes[2].tick_params(axis='x', rotation=45)\n\nplt.tight_layout()\nplt.savefig('categorical_distributions.png')\nprint(\"categorical_distributions.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:40.732609Z","iopub.execute_input":"2025-12-21T08:40:40.732873Z","iopub.status.idle":"2025-12-21T08:40:41.808316Z","shell.execute_reply.started":"2025-12-21T08:40:40.732851Z","shell.execute_reply":"2025-12-21T08:40:41.807358Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Correlation matrix for numerical variables\nplt.figure(figsize=(10, 8))\ncorrelation_matrix = df[['Pre_GSHH_NDVI', 'Height_Ave_cm', 'target']].corr()\nsns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', center=0,\n            square=True, linewidths=0.5, cbar_kws={\"shrink\": .8})\nplt.title('Correlation Matrix of Numerical Variables')\nplt.tight_layout()\nplt.savefig('correlation_matrix.png')\nprint(\"correlation_matrix.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:41.810396Z","iopub.execute_input":"2025-12-21T08:40:41.810698Z","iopub.status.idle":"2025-12-21T08:40:42.265313Z","shell.execute_reply.started":"2025-12-21T08:40:41.810676Z","shell.execute_reply":"2025-12-21T08:40:42.264170Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Shows:\n1.Moderate positive correlation (0.44) between Pre_GSHH_NDVI and target.\n2.Weak positive correlation (0.22) between Height_Ave_cm and target.\n3.Very weak correlation between Pre_GSHH_NDVI and Height_Ave_cm (-0.04).","metadata":{}},{"cell_type":"code","source":"# Scatter plots to show relationships\nfig, axes = plt.subplots(1, 2, figsize=(15, 6))\n\n# Pre_GSHH_NDVI vs Height_Ave_cm\naxes[0].scatter(df['Pre_GSHH_NDVI'], df['Height_Ave_cm'], alpha=0.5, color=plt.cm.tab20c(1))\naxes[0].set_xlabel('Pre_GSHH_NDVI')\naxes[0].set_ylabel('Height_Ave_cm')\naxes[0].set_title('Pre_GSHH_NDVI vs Height_Ave_cm')\n\n# Pre_GSHH_NDVI vs Target\naxes[1].scatter(df['Pre_GSHH_NDVI'], df['target'], alpha=0.5, color=plt.cm.tab20c(5))\naxes[1].set_xlabel('Pre_GSHH_NDVI')\naxes[1].set_ylabel('Target')\naxes[1].set_title('Pre_GSHH_NDVI vs Target')\n\nplt.tight_layout()\nplt.savefig('scatter_plots.png')\nprint(\"scatter_plots.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:42.266232Z","iopub.execute_input":"2025-12-21T08:40:42.266559Z","iopub.status.idle":"2025-12-21T08:40:43.060290Z","shell.execute_reply.started":"2025-12-21T08:40:42.266530Z","shell.execute_reply":"2025-12-21T08:40:43.059300Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Shows:\nA general positive trend between Pre_GSHH_NDVI and target values.\nA more scattered relationship between Pre_GSHH_NDVI and Height_Ave_cm.","metadata":{}},{"cell_type":"code","source":"# Boxplots by State\nfig, axes = plt.subplots(1, 3, figsize=(18, 6))\n\n# Pre_GSHH_NDVI by State\ndf.boxplot(column='Pre_GSHH_NDVI', by='State', ax=axes[0])\naxes[0].set_title('Pre_GSHH_NDVI by State')\naxes[0].set_xlabel('State')\naxes[0].set_ylabel('Pre_GSHH_NDVI')\n\n# Height_Ave_cm by State\ndf.boxplot(column='Height_Ave_cm', by='State', ax=axes[1])\naxes[1].set_title('Height_Ave_cm by State')\naxes[1].set_xlabel('State')\naxes[1].set_ylabel('Height_Ave_cm')\n\n# Target by State\ndf.boxplot(column='target', by='State', ax=axes[2])\naxes[2].set_title('Target by State')\naxes[2].set_xlabel('State')\naxes[2].set_ylabel('Target')\n\nplt.tight_layout()\nplt.savefig('boxplots_by_state.png')\nprint(\"boxplots_by_state.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:43.061202Z","iopub.execute_input":"2025-12-21T08:40:43.061483Z","iopub.status.idle":"2025-12-21T08:40:44.047320Z","shell.execute_reply.started":"2025-12-21T08:40:43.061461Z","shell.execute_reply":"2025-12-21T08:40:44.046356Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Shows:\n1.Tasmania (Tas) shows higher median values for both Pre_GSHH_NDVI and target.\n2,Western Australia (WA) has the lowest number of samples but shows distinct characteristics.","metadata":{}},{"cell_type":"code","source":"# Average target by Species (top 10) and target_name\nfig, axes = plt.subplots(1, 2, figsize=(15, 6))\n\n# Average target by Species (top 10)\ntop_species = df['Species'].value_counts().head(10).index\navg_target_by_species = df[df['Species'].isin(top_species)].groupby('Species')['target'].mean().sort_values(ascending=False)\naxes[0].bar(avg_target_by_species.index, avg_target_by_species.values, color=plt.cm.tab20c.colors)\naxes[0].set_title('Average Target by Species (Top 10)')\naxes[0].set_xlabel('Species')\naxes[0].set_ylabel('Average Target')\naxes[0].tick_params(axis='x', rotation=45)\n\n# Average target by target_name\navg_target_by_target_name = df.groupby('target_name')['target'].mean()\naxes[1].bar(avg_target_by_target_name.index, avg_target_by_target_name.values, color=plt.cm.tab20c.colors)\naxes[1].set_title('Average Target by Target Name')\naxes[1].set_xlabel('Target Name')\naxes[1].set_ylabel('Average Target')\naxes[1].tick_params(axis='x', rotation=45)\n\nplt.tight_layout()\nplt.savefig('average_target_analysis.png')\nprint(\"average_target_analysis.png\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-21T08:40:44.048238Z","iopub.execute_input":"2025-12-21T08:40:44.048528Z","iopub.status.idle":"2025-12-21T08:40:44.699631Z","shell.execute_reply.started":"2025-12-21T08:40:44.048505Z","shell.execute_reply":"2025-12-21T08:40:44.698316Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Shows:\n1.By Species: Subclover varieties tend to have higher average target values compared to other species.\n2.By Target Type: Dry_Total_g has the highest average target value, while Dry_Clover_g has the lowest.","metadata":{}}]}