{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":124685,"databundleVersionId":14664296,"sourceType":"competition"}],"dockerImageVersionId":31260,"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":"2026-02-05T14:12:12.937302Z","iopub.execute_input":"2026-02-05T14:12:12.937517Z","iopub.status.idle":"2026-02-05T14:12:16.488724Z","shell.execute_reply.started":"2026-02-05T14:12:12.937496Z","shell.execute_reply":"2026-02-05T14:12:16.487967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport csv\n\n# --- Configuration ---\n# Input Paths (based on your provided list)\nTRAIN_META_PATH = \"/kaggle/input/plantclef-2026/PlantCLEF2024_single_plant_training_metadata.csv\"\nTEST_META_PATH = \"/kaggle/input/plantclef-2026/PlantCLEF2025_test.csv\"\nOUTPUT_PATH = \"submission.csv\"\n\n# Baseline Parameter: How many top species to predict per image?\n# Predicting the top 3-5 most common species is a safe starting strategy.\nTOP_N = 5 \n\ndef generate_baseline():\n    print(\"Loading training metadata...\")\n    # 1. Load Training Metadata to find most common species\n    # We assume there is a 'species_id' column in the training metadata\n    try:\n        train_df = pd.read_csv(TRAIN_META_PATH, sep=\";\") # distinct check for separator usually ; or ,\n        if 'species_id' not in train_df.columns:\n            # Fallback if sep was comma\n            train_df = pd.read_csv(TRAIN_META_PATH, sep=\",\")\n    except Exception as e:\n        print(f\"Error reading train metadata: {e}\")\n        return\n\n    print(\"Calculating top species...\")\n    # Count frequency of each species_id\n    top_species = train_df['species_id'].value_counts().head(TOP_N).index.tolist()\n    \n    # Format the species list as a string \"[id1, id2, ...]\"\n    # The competition requires the list to be strictly formatted\n    top_species_str = \"[\" + \", \".join(map(str, top_species)) + \"]\"\n    print(f\"Baseline prediction for all images: {top_species_str}\")\n\n    # 2. Load Test Metadata to get the query IDs\n    print(\"Loading test metadata...\")\n    # The test CSV usually contains 'quadrat_id' or 'image_name'\n    try:\n        test_df = pd.read_csv(TEST_META_PATH, sep=\";\")\n        if 'quadrat_id' not in test_df.columns:\n             test_df = pd.read_csv(TEST_META_PATH, sep=\",\")\n    except Exception as e:\n        print(f\"Error reading test metadata: {e}\")\n        return\n\n    # Ensure we have the list of IDs. \n    # If the test csv has filenames like 'CBN-PdlC-F6-20200812.jpg', we strip .jpg\n    # If it has a 'quadrat_id' column, we use that directly.\n    \n    submission_ids = []\n    if 'quadrat_id' in test_df.columns:\n        submission_ids = test_df['quadrat_id'].tolist()\n    elif 'image_name' in test_df.columns:\n        submission_ids = test_df['image_name'].apply(lambda x: str(x).replace('.jpg', '')).tolist()\n    else:\n        # Fallback: Extract IDs from the filenames provided in the prompt directory\n        # (This block assumes the CSV is missing and we rely on file listing)\n        print(\"Warning: Could not infer IDs from CSV columns. Using provided file list logic.\")\n        # In a real run, rely on the CSV. Here is a dummy fallback:\n        submission_ids = [\"CBN-PdlC-F6-20200812\", \"CBN-PdlC-A4-20190722\"] # ... etc\n\n    # 3. Create Submission DataFrame\n    print(f\"Generating submission for {len(submission_ids)} images...\")\n    \n    submission_df = pd.DataFrame({\n        'quadrat_id': submission_ids,\n        'species_ids': top_species_str # Broadcast this prediction to all rows\n    })\n\n    # 4. Save to CSV with strict formatting\n    # quoting=csv.QUOTE_ALL ensures \"quadrat_id\",\"[123, 456]\" format\n    submission_df.to_csv(OUTPUT_PATH, index=False, sep=',', quoting=csv.QUOTE_ALL)\n    \n    print(f\"Saved baseline submission to {OUTPUT_PATH}\")\n    print(submission_df.head())\n\nif __name__ == \"__main__\":\n    generate_baseline()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T14:14:35.646492Z","iopub.execute_input":"2026-02-05T14:14:35.647179Z","iopub.status.idle":"2026-02-05T14:14:50.384219Z","shell.execute_reply.started":"2026-02-05T14:14:35.647149Z","shell.execute_reply":"2026-02-05T14:14:50.383504Z"}},"outputs":[],"execution_count":null}]}