{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":64733,"databundleVersionId":7762802,"sourceType":"competition"}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# GeoLifeClef 2024 (\\#GLC24) : no training, naive approach","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"Simple first and naive idea to predict species regarding species observed in train for a given (region, country)","metadata":{}},{"cell_type":"code","source":"import pandas as pd\n\n# Load train/test sets (only presence/absence (PA) datasets): \ndf_train = pd.read_csv('/kaggle/input/geolifeclef-2024/GLC24_PA_metadata_train.csv', dtype={'speciesId':int}, nrows=50_000)\ndf_test = pd.read_csv('/kaggle/input/geolifeclef-2024/GLC24_PA_metadata_test.csv',  dtype={'speciesId':int})\n\ndef get_species(df_train, region, country):\n    \"\"\"\n    Collect the list of observed speciesId in train data for an input pair (region, country)\n    Return the list as a single string of ids in increasing order, space separated\n    \"\"\"\n    query = list(df_train.loc[(df_train['region'] == region) & (df_train['country'] == country), 'speciesId'].unique())\n    query.sort()\n    return ' '.join([str(c) for c in query]) if len(query) >0 else \"0\"\n\n# Loop accross all pairs (country,region) in test set to collect all associated species observed in train set:\ndf_test['predictions'] = df_test.apply(lambda x : get_species(df_train, x['region'], x['country']), axis=1)\nsub = df_test[['surveyId','predictions']]\n\n# Submission:\nsub.to_csv('/kaggle/working/submission.csv', index=False)\nsub","metadata":{"execution":{"iopub.status.busy":"2024-03-18T09:39:10.912856Z","iopub.execute_input":"2024-03-18T09:39:10.913340Z","iopub.status.idle":"2024-03-18T09:40:47.013208Z","shell.execute_reply.started":"2024-03-18T09:39:10.913305Z","shell.execute_reply":"2024-03-18T09:40:47.012209Z"},"trusted":true},"execution_count":null,"outputs":[]}]}