{"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":"none","dataSources":[{"sourceId":91844,"databundleVersionId":11361821,"sourceType":"competition"},{"sourceId":14202163,"sourceType":"datasetVersion","datasetId":9057678}],"dockerImageVersionId":31234,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport pickle\nimport os\n\ntrain_df = pd.read_csv(\"/kaggle/input/birdclef-2025/train.csv\").drop(columns = ['url', 'license'])\ntaxonomy_df = pd.read_csv(\"/kaggle/input/birdclef-2025/taxonomy.csv\")\n\ntrain_df = pd.merge(\n                train_df,\n                taxonomy_df[['primary_label', 'class_name']],\n                how = 'left',\n                on = ['primary_label']\n            )","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:07:11.899545Z","iopub.execute_input":"2025-12-18T00:07:11.899952Z","iopub.status.idle":"2025-12-18T00:07:17.634827Z","shell.execute_reply.started":"2025-12-18T00:07:11.899910Z","shell.execute_reply":"2025-12-18T00:07:17.633328Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_df[train_df[\"secondary_labels\"]!=\"['']\"])/ len(train_df)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:37:44.810168Z","iopub.execute_input":"2025-12-17T22:37:44.810491Z","iopub.status.idle":"2025-12-17T22:37:44.821594Z","shell.execute_reply.started":"2025-12-17T22:37:44.810467Z","shell.execute_reply":"2025-12-17T22:37:44.820659Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_animal_classses = taxonomy_df.class_name.unique()\nfor animal in unique_animal_classses:\n    print(animal)\n    data = train_df[train_df['class_name'] == animal]\n    print(data.primary_label.value_counts())\n    sns.scatterplot(data = data, x = 'latitude', y = 'longitude', hue = 'primary_label', legend=False)\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:38:24.452574Z","iopub.execute_input":"2025-12-17T22:38:24.452955Z","iopub.status.idle":"2025-12-17T22:38:25.732300Z","shell.execute_reply.started":"2025-12-17T22:38:24.452929Z","shell.execute_reply":"2025-12-17T22:38:25.731104Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.primary_label.value_counts().plot.hist(bins = 300)\nprint(train_df.primary_label.value_counts().describe())\nprint('classic')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:38:44.567320Z","iopub.execute_input":"2025-12-17T22:38:44.567658Z","iopub.status.idle":"2025-12-17T22:38:45.138443Z","shell.execute_reply.started":"2025-12-17T22:38:44.567634Z","shell.execute_reply":"2025-12-17T22:38:45.137409Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\nimport numpy as np\nle = LabelEncoder().fit(train_df.primary_label)\ntrain_idx, small_test_idx = train_test_split(\n    np.arange(len(train_df)),\n    train_size = 0.8,\n    test_size = 0.2*0.2, \n    random_state = 32, \n    stratify = train_df['primary_label']\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:38:51.415314Z","iopub.execute_input":"2025-12-17T22:38:51.415652Z","iopub.status.idle":"2025-12-17T22:38:51.451476Z","shell.execute_reply.started":"2025-12-17T22:38:51.415623Z","shell.execute_reply":"2025-12-17T22:38:51.450453Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['primary_label'] = le.transform(train_df['primary_label'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:38:51.541615Z","iopub.execute_input":"2025-12-17T22:38:51.541983Z","iopub.status.idle":"2025-12-17T22:38:51.552254Z","shell.execute_reply.started":"2025-12-17T22:38:51.541959Z","shell.execute_reply":"2025-12-17T22:38:51.551312Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.iloc[small_test_idx].primary_label.value_counts().plot.hist(bins = 300)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:39:26.066558Z","iopub.execute_input":"2025-12-17T22:39:26.067334Z","iopub.status.idle":"2025-12-17T22:39:26.617531Z","shell.execute_reply.started":"2025-12-17T22:39:26.067292Z","shell.execute_reply":"2025-12-17T22:39:26.616503Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.iloc[train_idx].primary_label.value_counts().plot.hist(bins = 300)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T22:39:34.517078Z","iopub.execute_input":"2025-12-17T22:39:34.517885Z","iopub.status.idle":"2025-12-17T22:39:35.115114Z","shell.execute_reply.started":"2025-12-17T22:39:34.517848Z","shell.execute_reply":"2025-12-17T22:39:35.114203Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.groupby('class_name')['rating'].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:07:17.637500Z","iopub.execute_input":"2025-12-18T00:07:17.638144Z","iopub.status.idle":"2025-12-18T00:07:17.717936Z","shell.execute_reply.started":"2025-12-18T00:07:17.638106Z","shell.execute_reply":"2025-12-18T00:07:17.716809Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df[train_df['rating'] != 0].groupby('class_name')['rating'].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:08:36.052302Z","iopub.execute_input":"2025-12-18T00:08:36.052748Z","iopub.status.idle":"2025-12-18T00:08:36.089336Z","shell.execute_reply.started":"2025-12-18T00:08:36.052701Z","shell.execute_reply":"2025-12-18T00:08:36.088235Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"taxonomy_2 = pd.read_excel('/kaggle/input/birdfams/AviList-v2025-11Jun-extended.xlsx', index_col = 'Sequence')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:21:58.015224Z","iopub.execute_input":"2025-12-18T00:21:58.015570Z","iopub.status.idle":"2025-12-18T00:22:11.340134Z","shell.execute_reply.started":"2025-12-18T00:21:58.015542Z","shell.execute_reply":"2025-12-18T00:22:11.339062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#families by audios\npd.merge(\n    left = taxonomy_2, \n    right = train_df, \n    left_on = 'Scientific_name', \n    right_on = 'scientific_name').drop_duplicates(subset = ['filename'])['Family'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:21:45.328140Z","iopub.execute_input":"2025-12-18T00:21:45.328550Z","iopub.status.idle":"2025-12-18T00:21:45.433784Z","shell.execute_reply.started":"2025-12-18T00:21:45.328506Z","shell.execute_reply":"2025-12-18T00:21:45.432818Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#families by species\npd.merge(\n    left = taxonomy_2, \n    right = train_df, \n    left_on = 'Scientific_name', \n    right_on = 'scientific_name').drop_duplicates(subset = ['scientific_name'])['Family'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-18T00:20:52.837258Z","iopub.execute_input":"2025-12-18T00:20:52.837598Z","iopub.status.idle":"2025-12-18T00:20:52.898197Z","shell.execute_reply.started":"2025-12-18T00:20:52.837570Z","shell.execute_reply":"2025-12-18T00:20:52.897123Z"}},"outputs":[],"execution_count":null}]}