{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":19596,"databundleVersionId":1292430,"sourceType":"competition"}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport librosa\nfrom sklearn.preprocessing import LabelEncoder\nimport librosa.display\nimport soundfile as sf \nimport IPython.display as ipd \nfrom matplotlib.animation import FuncAnimation","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-11T19:14:40.820893Z","iopub.execute_input":"2024-01-11T19:14:40.821272Z","iopub.status.idle":"2024-01-11T19:14:41.953639Z","shell.execute_reply.started":"2024-01-11T19:14:40.821245Z","shell.execute_reply":"2024-01-11T19:14:41.952769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/birdsong-recognition/train.csv')\npd.set_option('display.max_column' , None)\npd.set_option('display.max_rows', None)  \npd.set_option('display.max_columns', None)\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:41.955552Z","iopub.execute_input":"2024-01-11T19:14:41.956133Z","iopub.status.idle":"2024-01-11T19:14:42.555749Z","shell.execute_reply.started":"2024-01-11T19:14:41.956100Z","shell.execute_reply":"2024-01-11T19:14:42.554987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:42.557206Z","iopub.execute_input":"2024-01-11T19:14:42.557659Z","iopub.status.idle":"2024-01-11T19:14:42.658310Z","shell.execute_reply.started":"2024-01-11T19:14:42.557594Z","shell.execute_reply":"2024-01-11T19:14:42.657221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_columns = data.columns[data.isnull().any()]\nnull_columns\n#identifying the null columns","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:42.660516Z","iopub.execute_input":"2024-01-11T19:14:42.660822Z","iopub.status.idle":"2024-01-11T19:14:42.735061Z","shell.execute_reply.started":"2024-01-11T19:14:42.660794Z","shell.execute_reply":"2024-01-11T19:14:42.734136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:42.736617Z","iopub.execute_input":"2024-01-11T19:14:42.737009Z","iopub.status.idle":"2024-01-11T19:14:42.744558Z","shell.execute_reply.started":"2024-01-11T19:14:42.736968Z","shell.execute_reply":"2024-01-11T19:14:42.743947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"whitegrid\")  # Set the background style\n\n# Define a custom color palette\ncustom_palette = sns.color_palette(\"viridis\", n_colors=len(data['rating'].unique()))\n\nsns.countplot(x='rating', data=data, order=data['rating'].value_counts().index, palette=custom_palette)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:42.745654Z","iopub.execute_input":"2024-01-11T19:14:42.746164Z","iopub.status.idle":"2024-01-11T19:14:43.183687Z","shell.execute_reply.started":"2024-01-11T19:14:42.746138Z","shell.execute_reply":"2024-01-11T19:14:43.182815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:43.185034Z","iopub.execute_input":"2024-01-11T19:14:43.185363Z","iopub.status.idle":"2024-01-11T19:14:43.194650Z","shell.execute_reply.started":"2024-01-11T19:14:43.185336Z","shell.execute_reply":"2024-01-11T19:14:43.193671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:43.195830Z","iopub.execute_input":"2024-01-11T19:14:43.196240Z","iopub.status.idle":"2024-01-11T19:14:43.208053Z","shell.execute_reply.started":"2024-01-11T19:14:43.196204Z","shell.execute_reply":"2024-01-11T19:14:43.207080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].fillna('no' , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:43.209005Z","iopub.execute_input":"2024-01-11T19:14:43.209445Z","iopub.status.idle":"2024-01-11T19:14:43.219878Z","shell.execute_reply.started":"2024-01-11T19:14:43.209417Z","shell.execute_reply":"2024-01-11T19:14:43.219069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"playback_used_count = data['playback_used'].value_counts()\n\ncolors = plt.cm.Set1.colors\n\nplt.figure(figsize=(4, 4))\nplt.pie(playback_used_count, labels=playback_used_count.index, autopct='%1.1f%%', startangle=90, colors=colors, wedgeprops=dict(width=0.4))\n\nplt.title('Distribution of Playback Used', fontsize=16)\n\nplt.legend(playback_used_count.index, loc='best', bbox_to_anchor=(0.8, 0.8))\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:43.224254Z","iopub.execute_input":"2024-01-11T19:14:43.224581Z","iopub.status.idle":"2024-01-11T19:14:43.541823Z","shell.execute_reply.started":"2024-01-11T19:14:43.224554Z","shell.execute_reply":"2024-01-11T19:14:43.540716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['ebird_code'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:51.127142Z","iopub.execute_input":"2024-01-11T19:14:51.128134Z","iopub.status.idle":"2024-01-11T19:14:51.136646Z","shell.execute_reply.started":"2024-01-11T19:14:51.128095Z","shell.execute_reply":"2024-01-11T19:14:51.135408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:14:56.265619Z","iopub.execute_input":"2024-01-11T19:14:56.266255Z","iopub.status.idle":"2024-01-11T19:14:56.275223Z","shell.execute_reply.started":"2024-01-11T19:14:56.266223Z","shell.execute_reply":"2024-01-11T19:14:56.274091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"channels_count = data['channels'].value_counts()\n\ncolors = sns.color_palette('pastel')[0:len(channels_count)]\n\nplt.figure(figsize=(5, 5))\nplt.pie(channels_count, labels=channels_count.index, autopct='%1.1f%%', startangle=90, colors=colors, wedgeprops=dict(width=0.4))\n\nplt.title('Distribution of Channels', fontsize=16, weight='bold')\nplt.legend(channels_count.index, title='Channels', bbox_to_anchor=(1, 0.8), loc='upper right')\nplt.tight_layout()\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:01.660442Z","iopub.execute_input":"2024-01-11T19:15:01.660783Z","iopub.status.idle":"2024-01-11T19:15:01.958753Z","shell.execute_reply.started":"2024-01-11T19:15:01.660756Z","shell.execute_reply":"2024-01-11T19:15:01.957473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['channels'] = data['channels'].astype(str).str[0].astype(int)\ndata['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:07.479261Z","iopub.execute_input":"2024-01-11T19:15:07.479948Z","iopub.status.idle":"2024-01-11T19:15:07.513599Z","shell.execute_reply.started":"2024-01-11T19:15:07.479899Z","shell.execute_reply":"2024-01-11T19:15:07.512694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['date'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:12.496345Z","iopub.execute_input":"2024-01-11T19:15:12.496759Z","iopub.status.idle":"2024-01-11T19:15:12.506262Z","shell.execute_reply.started":"2024-01-11T19:15:12.496727Z","shell.execute_reply":"2024-01-11T19:15:12.505241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['year'] = data['date'].apply(lambda x : x.split('-')[0]).astype(int)\ndata['month'] = data['date'].apply(lambda x : x.split('-')[1]).astype(int)\ndata['day'] = data['date'].apply(lambda x : x.split('-')[2]).astype(int)\ndata = data.drop(['date'] , axis=1)\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:17.149889Z","iopub.execute_input":"2024-01-11T19:15:17.150429Z","iopub.status.idle":"2024-01-11T19:15:17.247864Z","shell.execute_reply.started":"2024-01-11T19:15:17.150382Z","shell.execute_reply":"2024-01-11T19:15:17.246471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_theme(style=\"whitegrid\")\n\n# Assuming 'data' is your DataFrame and 'year' is a column in it\nplt.figure(figsize=(10, 6))\nsns.countplot(x='year', data=data, palette=\"viridis\")\n\nplt.title('Count Plot of Years', fontsize=16)\nplt.xlabel('Year', fontsize=14)\nplt.ylabel('Count', fontsize=14)\nplt.xticks(rotation=90, ha='right', fontsize=12)\nplt.yticks(fontsize=12)\nplt.tight_layout()\n\n# Add a grid for better readability\nplt.grid(axis='y', linestyle='--', alpha=0.7)\n\nplt.tight_layout()\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:23.888247Z","iopub.execute_input":"2024-01-11T19:15:23.888665Z","iopub.status.idle":"2024-01-11T19:15:25.049023Z","shell.execute_reply.started":"2024-01-11T19:15:23.888636Z","shell.execute_reply":"2024-01-11T19:15:25.047904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nsns.countplot(x='month', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Count Plot of months')\nplt.xlabel('Year')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:30.675083Z","iopub.execute_input":"2024-01-11T19:15:30.675511Z","iopub.status.idle":"2024-01-11T19:15:31.195160Z","shell.execute_reply.started":"2024-01-11T19:15:30.675457Z","shell.execute_reply":"2024-01-11T19:15:31.193906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nsns.countplot(x='day', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Count Plot of months')\nplt.xlabel('Year')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:37.274394Z","iopub.execute_input":"2024-01-11T19:15:37.274875Z","iopub.status.idle":"2024-01-11T19:15:38.169474Z","shell.execute_reply.started":"2024-01-11T19:15:37.274841Z","shell.execute_reply":"2024-01-11T19:15:38.168436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['pitch'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:42.494671Z","iopub.execute_input":"2024-01-11T19:15:42.495354Z","iopub.status.idle":"2024-01-11T19:15:42.504422Z","shell.execute_reply.started":"2024-01-11T19:15:42.495289Z","shell.execute_reply":"2024-01-11T19:15:42.503380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nsns.countplot(x='pitch', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Plot of Pitch')\nplt.xlabel('pitch')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:46.807323Z","iopub.execute_input":"2024-01-11T19:15:46.807738Z","iopub.status.idle":"2024-01-11T19:15:47.350400Z","shell.execute_reply.started":"2024-01-11T19:15:46.807705Z","shell.execute_reply":"2024-01-11T19:15:47.349257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['duration'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:52.500746Z","iopub.execute_input":"2024-01-11T19:15:52.501125Z","iopub.status.idle":"2024-01-11T19:15:52.509781Z","shell.execute_reply.started":"2024-01-11T19:15:52.501094Z","shell.execute_reply":"2024-01-11T19:15:52.509046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(['duration'] , axis=1 , inplace=True)\ndata['speed'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:15:57.256704Z","iopub.execute_input":"2024-01-11T19:15:57.257639Z","iopub.status.idle":"2024-01-11T19:15:57.276240Z","shell.execute_reply.started":"2024-01-11T19:15:57.257589Z","shell.execute_reply":"2024-01-11T19:15:57.275078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nsns.countplot(x='speed', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Plot of speed')\nplt.xlabel('speed')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:01.920192Z","iopub.execute_input":"2024-01-11T19:16:01.921267Z","iopub.status.idle":"2024-01-11T19:16:02.318564Z","shell.execute_reply.started":"2024-01-11T19:16:01.921219Z","shell.execute_reply":"2024-01-11T19:16:02.317673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['pitch'] , axis=1)\ndata = data.drop(['speed'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:06.298487Z","iopub.execute_input":"2024-01-11T19:16:06.299272Z","iopub.status.idle":"2024-01-11T19:16:06.325842Z","shell.execute_reply.started":"2024-01-11T19:16:06.299230Z","shell.execute_reply":"2024-01-11T19:16:06.325071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['species'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:11.317653Z","iopub.execute_input":"2024-01-11T19:16:11.318507Z","iopub.status.idle":"2024-01-11T19:16:11.327428Z","shell.execute_reply.started":"2024-01-11T19:16:11.318463Z","shell.execute_reply":"2024-01-11T19:16:11.326497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data['number_of_notes'].unique())\ndata['number_of_notes'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:15.642658Z","iopub.execute_input":"2024-01-11T19:16:15.643389Z","iopub.status.idle":"2024-01-11T19:16:15.656839Z","shell.execute_reply.started":"2024-01-11T19:16:15.643345Z","shell.execute_reply":"2024-01-11T19:16:15.655652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nsns.countplot(x='number_of_notes', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Plot of notes')\nplt.xlabel('number_of_notes')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:20.784711Z","iopub.execute_input":"2024-01-11T19:16:20.785097Z","iopub.status.idle":"2024-01-11T19:16:21.114267Z","shell.execute_reply.started":"2024-01-11T19:16:20.785065Z","shell.execute_reply":"2024-01-11T19:16:21.113367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bird_seen'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:25.354879Z","iopub.execute_input":"2024-01-11T19:16:25.355292Z","iopub.status.idle":"2024-01-11T19:16:25.364722Z","shell.execute_reply.started":"2024-01-11T19:16:25.355263Z","shell.execute_reply":"2024-01-11T19:16:25.363758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.fillna('yes' , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:30.233004Z","iopub.execute_input":"2024-01-11T19:16:30.233763Z","iopub.status.idle":"2024-01-11T19:16:30.326367Z","shell.execute_reply.started":"2024-01-11T19:16:30.233720Z","shell.execute_reply":"2024-01-11T19:16:30.325229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4,4))\nsns.countplot(x='bird_seen', data=data)\n\nplt.xticks(rotation =90)\nplt.title('Plot of does the bird seen')\nplt.xlabel('bird seen')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:34.942022Z","iopub.execute_input":"2024-01-11T19:16:34.942489Z","iopub.status.idle":"2024-01-11T19:16:35.262021Z","shell.execute_reply.started":"2024-01-11T19:16:34.942450Z","shell.execute_reply":"2024-01-11T19:16:35.260879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data['latitude'].nunique())\nprint(data['longitude'].nunique())","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:41.375343Z","iopub.execute_input":"2024-01-11T19:16:41.375718Z","iopub.status.idle":"2024-01-11T19:16:41.390394Z","shell.execute_reply.started":"2024-01-11T19:16:41.375692Z","shell.execute_reply":"2024-01-11T19:16:41.389236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data[data['latitude'] != 'Not specified']\ndata = data[data['longitude'] != 'Not specified']\ndata['latitude']  = data['latitude'].astype(float)\ndata['longitude']  = data['longitude'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:16:48.961672Z","iopub.execute_input":"2024-01-11T19:16:48.962194Z","iopub.status.idle":"2024-01-11T19:16:49.036486Z","shell.execute_reply.started":"2024-01-11T19:16:48.962154Z","shell.execute_reply":"2024-01-11T19:16:49.035382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:10.425673Z","iopub.execute_input":"2024-01-11T19:17:10.426076Z","iopub.status.idle":"2024-01-11T19:17:10.434765Z","shell.execute_reply.started":"2024-01-11T19:17:10.426044Z","shell.execute_reply":"2024-01-11T19:17:10.433721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['sampling_rate(in Hz)'] = data['sampling_rate'].apply(lambda x : x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:15.972495Z","iopub.execute_input":"2024-01-11T19:17:15.972898Z","iopub.status.idle":"2024-01-11T19:17:15.995555Z","shell.execute_reply.started":"2024-01-11T19:17:15.972864Z","shell.execute_reply":"2024-01-11T19:17:15.994407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 6))  \n\nax = sns.countplot(x='sampling_rate(in Hz)', data=data)\n\nfor p in ax.patches:\n    ax.annotate(f'{p.get_height()}', (p.get_x() + p.get_width() / 2., p.get_height()),\n                ha='center', va='center', xytext=(0, 10), textcoords='offset points', fontsize=8)\n\nplt.xticks(rotation=90)\nplt.title('Plot of sampling rate')\nplt.xlabel('Sampling rate')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:20.231636Z","iopub.execute_input":"2024-01-11T19:17:20.232040Z","iopub.status.idle":"2024-01-11T19:17:20.761550Z","shell.execute_reply.started":"2024-01-11T19:17:20.231997Z","shell.execute_reply":"2024-01-11T19:17:20.760446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:27.494168Z","iopub.execute_input":"2024-01-11T19:17:27.494616Z","iopub.status.idle":"2024-01-11T19:17:27.505529Z","shell.execute_reply.started":"2024-01-11T19:17:27.494582Z","shell.execute_reply":"2024-01-11T19:17:27.504157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['type'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:30.198567Z","iopub.execute_input":"2024-01-11T19:17:30.199091Z","iopub.status.idle":"2024-01-11T19:17:30.213073Z","shell.execute_reply.started":"2024-01-11T19:17:30.199054Z","shell.execute_reply":"2024-01-11T19:17:30.211993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:34.078570Z","iopub.execute_input":"2024-01-11T19:17:34.078955Z","iopub.status.idle":"2024-01-11T19:17:34.090510Z","shell.execute_reply.started":"2024-01-11T19:17:34.078913Z","shell.execute_reply":"2024-01-11T19:17:34.089428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = data['elevation'].replace(['? m' , 'Unknown m'  ,' m'] , '99999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:39.523158Z","iopub.execute_input":"2024-01-11T19:17:39.523904Z","iopub.status.idle":"2024-01-11T19:17:39.539458Z","shell.execute_reply.started":"2024-01-11T19:17:39.523865Z","shell.execute_reply":"2024-01-11T19:17:39.538214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport re\n\n# Assuming 'elevation' is the name of the column in your DataFrame\ndata['elevation'] = data['elevation'].astype(str).str.replace('~', '').str.replace('-', '')\n\ndef extract_numeric(value):\n    try:\n        numeric_part = float(re.search(r'\\d+\\.\\d+|\\d+', value).group())\n        return int(numeric_part)\n    except (ValueError, AttributeError):\n        return None  # or any other default value you want to use for non-numeric entries\n\ndata['elevation'] = data['elevation'].apply(extract_numeric)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:43.622449Z","iopub.execute_input":"2024-01-11T19:17:43.622876Z","iopub.status.idle":"2024-01-11T19:17:43.719284Z","shell.execute_reply.started":"2024-01-11T19:17:43.622834Z","shell.execute_reply":"2024-01-11T19:17:43.718185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = data['elevation'].astype(float).fillna(0)  # Convert to float and fill NaN with 0\ndata['elevation'] = round(data['elevation']).astype(int)  # Round and convert to int\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:47.518278Z","iopub.execute_input":"2024-01-11T19:17:47.518785Z","iopub.status.idle":"2024-01-11T19:17:47.527275Z","shell.execute_reply.started":"2024-01-11T19:17:47.518742Z","shell.execute_reply":"2024-01-11T19:17:47.525995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = round(data['elevation']).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:51.179057Z","iopub.execute_input":"2024-01-11T19:17:51.179446Z","iopub.status.idle":"2024-01-11T19:17:51.185508Z","shell.execute_reply.started":"2024-01-11T19:17:51.179417Z","shell.execute_reply":"2024-01-11T19:17:51.184528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = pd.to_numeric(data['elevation'] ,errors='coerce')\nsum_elev = 0\ncount_valid_values = 0\n\nfor index  , row in data.iterrows():\n    if row['elevation'] != 99999:\n        sum_elev += row['elevation']\n        count_valid_values += 1\n\nmean_elev =  sum_elev/count_valid_values\nmean_elev ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:17:55.313307Z","iopub.execute_input":"2024-01-11T19:17:55.313712Z","iopub.status.idle":"2024-01-11T19:17:56.887862Z","shell.execute_reply.started":"2024-01-11T19:17:55.313682Z","shell.execute_reply":"2024-01-11T19:17:56.886767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = data['elevation'].replace(99999, 'mean_elev')\n\ndata['elevation'] = pd.to_numeric(data['elevation'], errors='coerce').fillna(0).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:00.351647Z","iopub.execute_input":"2024-01-11T19:18:00.352167Z","iopub.status.idle":"2024-01-11T19:18:00.374144Z","shell.execute_reply.started":"2024-01-11T19:18:00.352129Z","shell.execute_reply":"2024-01-11T19:18:00.373018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:04.362439Z","iopub.execute_input":"2024-01-11T19:18:04.362820Z","iopub.status.idle":"2024-01-11T19:18:04.370715Z","shell.execute_reply.started":"2024-01-11T19:18:04.362789Z","shell.execute_reply":"2024-01-11T19:18:04.369972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndata['bitrate_of_mp3'] = pd.to_numeric(data['bitrate_of_mp3'].str.extract('(\\d+)')[0], errors='coerce')\n\nmean_value = data['bitrate_of_mp3'].mean(skipna=True)\n\ndata['bitrate_of_mp3'] = data['bitrate_of_mp3'].fillna(mean_value).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:08.180598Z","iopub.execute_input":"2024-01-11T19:18:08.181014Z","iopub.status.idle":"2024-01-11T19:18:08.267134Z","shell.execute_reply.started":"2024-01-11T19:18:08.180980Z","shell.execute_reply":"2024-01-11T19:18:08.265994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:12.522336Z","iopub.execute_input":"2024-01-11T19:18:12.522830Z","iopub.status.idle":"2024-01-11T19:18:12.531059Z","shell.execute_reply.started":"2024-01-11T19:18:12.522788Z","shell.execute_reply":"2024-01-11T19:18:12.530108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[data['bitrate_of_mp3'] == 3 ].index , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:16.218269Z","iopub.execute_input":"2024-01-11T19:18:16.218699Z","iopub.status.idle":"2024-01-11T19:18:16.235781Z","shell.execute_reply.started":"2024-01-11T19:18:16.218665Z","shell.execute_reply":"2024-01-11T19:18:16.234993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['bitrate_of_mp3'].isna()]","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:20.649791Z","iopub.execute_input":"2024-01-11T19:18:20.650199Z","iopub.status.idle":"2024-01-11T19:18:20.669612Z","shell.execute_reply.started":"2024-01-11T19:18:20.650166Z","shell.execute_reply":"2024-01-11T19:18:20.667548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['file_type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:24.209485Z","iopub.execute_input":"2024-01-11T19:18:24.209952Z","iopub.status.idle":"2024-01-11T19:18:24.218903Z","shell.execute_reply.started":"2024-01-11T19:18:24.209902Z","shell.execute_reply":"2024-01-11T19:18:24.217733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4, 6))  \n\nax = sns.countplot(x='file_type', data=data)\n\nfor p in ax.patches:\n    ax.annotate(f'{p.get_height()}', (p.get_x() + p.get_width() / 2., p.get_height()),\n                ha='center', va='center', xytext=(0, 10), textcoords='offset points', fontsize=8)\n\nplt.xticks(rotation=90)\nplt.title('Plot of file_type')\nplt.xlabel('file_type')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:28.782402Z","iopub.execute_input":"2024-01-11T19:18:28.782981Z","iopub.status.idle":"2024-01-11T19:18:29.230453Z","shell.execute_reply.started":"2024-01-11T19:18:28.782951Z","shell.execute_reply":"2024-01-11T19:18:29.229423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['volume'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:33.123154Z","iopub.execute_input":"2024-01-11T19:18:33.123536Z","iopub.status.idle":"2024-01-11T19:18:33.132462Z","shell.execute_reply.started":"2024-01-11T19:18:33.123507Z","shell.execute_reply":"2024-01-11T19:18:33.131316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4, 6))  \n\nax = sns.countplot(x='volume', data=data)\n\nfor p in ax.patches:\n    ax.annotate(f'{p.get_height()}', (p.get_x() + p.get_width() / 2., p.get_height()),\n                ha='center', va='center', xytext=(0, 10), textcoords='offset points', fontsize=8)\n\nplt.xticks(rotation=90)\nplt.title('Plot of file_type')\nplt.xlabel('file_type')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:37.038465Z","iopub.execute_input":"2024-01-11T19:18:37.038856Z","iopub.status.idle":"2024-01-11T19:18:37.519095Z","shell.execute_reply.started":"2024-01-11T19:18:37.038825Z","shell.execute_reply":"2024-01-11T19:18:37.517946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['volume'] , axis=1)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:42.347915Z","iopub.execute_input":"2024-01-11T19:18:42.349217Z","iopub.status.idle":"2024-01-11T19:18:42.363021Z","shell.execute_reply.started":"2024-01-11T19:18:42.349167Z","shell.execute_reply":"2024-01-11T19:18:42.362067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['background'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:45.990045Z","iopub.execute_input":"2024-01-11T19:18:45.990478Z","iopub.status.idle":"2024-01-11T19:18:46.002530Z","shell.execute_reply.started":"2024-01-11T19:18:45.990441Z","shell.execute_reply":"2024-01-11T19:18:46.001325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['background'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:52.322751Z","iopub.execute_input":"2024-01-11T19:18:52.323166Z","iopub.status.idle":"2024-01-11T19:18:52.336498Z","shell.execute_reply.started":"2024-01-11T19:18:52.323134Z","shell.execute_reply":"2024-01-11T19:18:52.335537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['xc_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:56.683669Z","iopub.execute_input":"2024-01-11T19:18:56.684186Z","iopub.status.idle":"2024-01-11T19:18:56.692707Z","shell.execute_reply.started":"2024-01-11T19:18:56.684143Z","shell.execute_reply":"2024-01-11T19:18:56.691816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['xc_id'] , axis=1)\ndata = data.drop(['url'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:01.185846Z","iopub.execute_input":"2024-01-11T19:19:01.186604Z","iopub.status.idle":"2024-01-11T19:19:01.211219Z","shell.execute_reply.started":"2024-01-11T19:19:01.186564Z","shell.execute_reply":"2024-01-11T19:19:01.210062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['country'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:04.701808Z","iopub.execute_input":"2024-01-11T19:19:04.702370Z","iopub.status.idle":"2024-01-11T19:19:04.711371Z","shell.execute_reply.started":"2024-01-11T19:19:04.702340Z","shell.execute_reply":"2024-01-11T19:19:04.710582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['country'] = data['country'].str.strip(\"'[]\").str.replace(\"'\", \"\").str.split(\", \")\n\n# Flatten the list of country\nall_country = [country for sublist in data['country'].dropna() for country in sublist]\n\n# Create a DataFrame with country counts\ncountry_counts = pd.Series(all_country).value_counts().reset_index()\ncountry_counts.columns = ['Country', 'Count']\n\n# Sort the DataFrame by 'Count' in descending order\ncountry_counts_sorted = country_counts.sort_values(by='Count', ascending=False)\n\n# Plot the countplot for the top 10 country\nplt.figure(figsize=(12, 6))\nsns.barplot(x='Country', y='Count', data=country_counts_sorted.head(10))\nplt.title('Top 10 country by Count')\nplt.xlabel('Country')\nplt.ylabel('Count')\nplt.xticks(rotation=45, ha='right')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:10.716500Z","iopub.execute_input":"2024-01-11T19:19:10.717627Z","iopub.status.idle":"2024-01-11T19:19:11.226117Z","shell.execute_reply.started":"2024-01-11T19:19:10.717585Z","shell.execute_reply":"2024-01-11T19:19:11.224975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data['author'].nunique())\nprint(data['recordist'].nunique())","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:27.672721Z","iopub.execute_input":"2024-01-11T19:19:27.673097Z","iopub.status.idle":"2024-01-11T19:19:27.684645Z","shell.execute_reply.started":"2024-01-11T19:19:27.673067Z","shell.execute_reply":"2024-01-11T19:19:27.683454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['author'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:32.813761Z","iopub.execute_input":"2024-01-11T19:19:32.814803Z","iopub.status.idle":"2024-01-11T19:19:32.828058Z","shell.execute_reply.started":"2024-01-11T19:19:32.814755Z","shell.execute_reply":"2024-01-11T19:19:32.827221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['primary_label'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:39.320164Z","iopub.execute_input":"2024-01-11T19:19:39.320662Z","iopub.status.idle":"2024-01-11T19:19:39.330533Z","shell.execute_reply.started":"2024-01-11T19:19:39.320622Z","shell.execute_reply":"2024-01-11T19:19:39.329526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.drop(['primary_label'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:44.592332Z","iopub.execute_input":"2024-01-11T19:19:44.592724Z","iopub.status.idle":"2024-01-11T19:19:44.606374Z","shell.execute_reply.started":"2024-01-11T19:19:44.592698Z","shell.execute_reply":"2024-01-11T19:19:44.605078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:50.412436Z","iopub.execute_input":"2024-01-11T19:19:50.412815Z","iopub.status.idle":"2024-01-11T19:19:50.423114Z","shell.execute_reply.started":"2024-01-11T19:19:50.412786Z","shell.execute_reply":"2024-01-11T19:19:50.421482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['length'] = data['length'].replace('Not specified', '0-0(s)')\ndata['length'] = data['length'].fillna('0-0(s)')\ndata[['min_length', 'max_length']] = data['length'].str.extract(r'(\\d+)-(\\d+)\\(s\\)')\ndata[['min_length', 'max_length']] = data[['min_length', 'max_length']].astype(float)\ndata = data.drop(['length'] , axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:19:55.158464Z","iopub.execute_input":"2024-01-11T19:19:55.158991Z","iopub.status.idle":"2024-01-11T19:19:55.351669Z","shell.execute_reply.started":"2024-01-11T19:19:55.158916Z","shell.execute_reply":"2024-01-11T19:19:55.350849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['time'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:01.601879Z","iopub.execute_input":"2024-01-11T19:20:01.602283Z","iopub.status.idle":"2024-01-11T19:20:01.611331Z","shell.execute_reply.started":"2024-01-11T19:20:01.602251Z","shell.execute_reply":"2024-01-11T19:20:01.610138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['time'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:06.591749Z","iopub.execute_input":"2024-01-11T19:20:06.592102Z","iopub.status.idle":"2024-01-11T19:20:06.600528Z","shell.execute_reply.started":"2024-01-11T19:20:06.592075Z","shell.execute_reply":"2024-01-11T19:20:06.599308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['license'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:11.240707Z","iopub.execute_input":"2024-01-11T19:20:11.241121Z","iopub.status.idle":"2024-01-11T19:20:11.250396Z","shell.execute_reply.started":"2024-01-11T19:20:11.241090Z","shell.execute_reply":"2024-01-11T19:20:11.249389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le  = LabelEncoder()\ndata['license'] = le.fit_transform(data['license'])\ndata['license'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:15.264992Z","iopub.execute_input":"2024-01-11T19:20:15.265467Z","iopub.status.idle":"2024-01-11T19:20:15.283493Z","shell.execute_reply.started":"2024-01-11T19:20:15.265428Z","shell.execute_reply":"2024-01-11T19:20:15.282538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:24.277964Z","iopub.execute_input":"2024-01-11T19:20:24.278396Z","iopub.status.idle":"2024-01-11T19:20:24.314325Z","shell.execute_reply.started":"2024-01-11T19:20:24.278361Z","shell.execute_reply":"2024-01-11T19:20:24.313208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Feature Engineering\n","metadata":{}},{"cell_type":"code","source":"train = data.iloc[[0 ,1 , 1147 , 1148 , 4754 , 4755 , 7221 , 7222 , 21088 , 21089]].reset_index(drop=True)\ntrain.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:52.000253Z","iopub.execute_input":"2024-01-11T19:20:52.000642Z","iopub.status.idle":"2024-01-11T19:20:52.042387Z","shell.execute_reply.started":"2024-01-11T19:20:52.000612Z","shell.execute_reply":"2024-01-11T19:20:52.041304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_directory = '/kaggle/input/birdsong-recognition/train_audio/'\n\n# Create a new column 'file_location' by combining 'category' and 'file_name'\naudio = base_directory + train['ebird_code'] + '/' + train['filename']\naudio","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:20:56.344161Z","iopub.execute_input":"2024-01-11T19:20:56.344556Z","iopub.status.idle":"2024-01-11T19:20:56.354106Z","shell.execute_reply.started":"2024-01-11T19:20:56.344527Z","shell.execute_reply":"2024-01-11T19:20:56.352790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_list = []\nsr_list = []\n\n# Loop through the 'audio' column and load each audio file\nfor audio_file in audio:\n    y_, sr_ = librosa.load(audio_file)\n    y_list.append(y_)\n    sr_list.append(sr_)\n\n# Add 'y' and 'sr' columns to the DataFrame\ntrain['y'] = y_list\ntrain['sr'] = sr_list","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:21:03.076737Z","iopub.execute_input":"2024-01-11T19:21:03.077118Z","iopub.status.idle":"2024-01-11T19:21:15.379339Z","shell.execute_reply.started":"2024-01-11T19:21:03.077088Z","shell.execute_reply":"2024-01-11T19:21:15.378414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(10):\n    print(f\"Audio {i}: {train.loc[i, 'ebird_code']}\")\n    ipd.display(ipd.Audio(train.loc[i, 'y'], rate=train.loc[i, 'sr']))","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:21:15.380847Z","iopub.execute_input":"2024-01-11T19:21:15.381366Z","iopub.status.idle":"2024-01-11T19:21:15.737457Z","shell.execute_reply.started":"2024-01-11T19:21:15.381336Z","shell.execute_reply":"2024-01-11T19:21:15.736155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_files = 10\n\n# Configure the grid layout\nnum_rows = 2\nnum_cols = num_files // num_rows\n\n# Create subplots\nfig, axes = plt.subplots(num_rows, num_cols, figsize=(15, 5))\n\n# Display audio files in a grid layout\nfor i, ax in enumerate(axes.flatten()):\n    if i < num_files:\n        ax.set_title(f\"Audio {i}: {train.loc[i, 'species']}\")\n        ax.plot(train.loc[i, 'y'])  # You might want to use plot here based on the structure of your 'y'\n        ax.axis('off')  # Turn off axis for a cleaner look\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:21:19.771897Z","iopub.execute_input":"2024-01-11T19:21:19.772322Z","iopub.status.idle":"2024-01-11T19:21:22.793717Z","shell.execute_reply.started":"2024-01-11T19:21:19.772288Z","shell.execute_reply":"2024-01-11T19:21:22.792898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['zcr'] = None\n\n# Loop through the DataFrame and calculate zero-crossing rates for each audio file\nfor i in range(len(train)):\n    y = train.loc[i, 'y']\n    zcr = librosa.feature.zero_crossing_rate(y)\n    train.at[i, 'zcr'] = zcr\n\n# Plot Zero Crossing Rate for all audio files\nnum_files_to_plot = 10  # Change this based on the number of files you want to plot\nplt.figure(figsize=(15, 10))\n\nfor i in range(num_files_to_plot):\n    zcr_values = train.loc[i, 'zcr'][0]\n    plt.subplot(4, 3, i+1)  # Assuming you want a 2x5 grid for the first 10 files\n    plt.plot(zcr_values, label='ZCR')\n    plt.title(f'ZCR - {train.loc[i, \"ebird_code\"]}')\n    plt.legend()\n    plt.xlabel('Frame Index')\n    plt.ylabel('Zero Crossing Rate')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:22:54.885339Z","iopub.execute_input":"2024-01-11T19:22:54.885779Z","iopub.status.idle":"2024-01-11T19:22:59.706899Z","shell.execute_reply.started":"2024-01-11T19:22:54.885744Z","shell.execute_reply":"2024-01-11T19:22:59.705913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['rms_energy'] = None\n\nfor i in range(len(train)):\n    y = train.loc[i, 'y']\n    rms_energy = librosa.feature.rms(y=y)\n    train.at[i, 'rms_energy'] = rms_energy\n\n# Plot RMS Energy for all audio files\nnum_files_to_plot = 10  # Change this based on the number of files you want to plot\nplt.figure(figsize=(15, 10))\n\nfor i in range(num_files_to_plot):\n    rms_energy_values = train.loc[i, 'rms_energy'][0]\n    plt.subplot(4, 3, i+1)  # Assuming you want a 2x5 grid for the first 10 files\n    plt.plot(rms_energy_values, label='RMS Energy')\n    plt.title(f'RMS Energy - {train.loc[i, \"ebird_code\"]}')\n    plt.legend()\n    plt.xlabel('Frame Index')\n    plt.ylabel('RMS Energy')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:22:59.709046Z","iopub.execute_input":"2024-01-11T19:22:59.709704Z","iopub.status.idle":"2024-01-11T19:23:03.728263Z","shell.execute_reply.started":"2024-01-11T19:22:59.709666Z","shell.execute_reply":"2024-01-11T19:23:03.727303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_spectral_rolloff(y, sr, title):\n    S, phase = librosa.magphase(librosa.stft(y))\n    rolloff = librosa.feature.spectral_rolloff(S=S, sr=sr, roll_percent=0.99)\n\n    # Plot Spectral Rolloff\n    plt.plot(rolloff[0], label='Spectral Rolloff')\n    plt.title(f'{title}')\n    plt.legend()\n\n# Plot Spectral Rolloff for all audio files\nnum_files_to_plot = 10  # Change this based on the number of files you want to plot\nplt.figure(figsize=(15, 10))\n\nfor i in range(num_files_to_plot):\n    plt.subplot(4, 3, i+1)  # Assuming you want a 2x5 grid for the first 10 files\n    plot_spectral_rolloff(train.loc[i, 'y'], train.loc[i, 'sr'], f'{train.loc[i, \"ebird_code\"]}')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:23:04.331590Z","iopub.execute_input":"2024-01-11T19:23:04.331964Z","iopub.status.idle":"2024-01-11T19:23:08.521897Z","shell.execute_reply.started":"2024-01-11T19:23:04.331911Z","shell.execute_reply":"2024-01-11T19:23:08.521110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_spectral_flux(y, sr, title):\n    onset_env = librosa.onset.onset_strength(y=y, sr=sr)\n\n    # Plot Spectral Flux\n    plt.plot(onset_env, label='Spectral Flux')\n    plt.title(f'{title}')\n    plt.legend()\n\n# Plot Spectral Flux for all audio files\nnum_files_to_plot = 10  # Change this based on the number of files you want to plot\nplt.figure(figsize=(15, 10))\n\nfor i in range(num_files_to_plot):\n    plt.subplot(4, 3, i+1)  # Assuming you want a 2x5 grid for the first 10 files\n    plot_spectral_flux(train.loc[i, 'y'], train.loc[i, 'sr'], f'{train.loc[i, \"ebird_code\"]}')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:23:10.687453Z","iopub.execute_input":"2024-01-11T19:23:10.687894Z","iopub.status.idle":"2024-01-11T19:23:15.257786Z","shell.execute_reply.started":"2024-01-11T19:23:10.687849Z","shell.execute_reply":"2024-01-11T19:23:15.256907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" train['mfcc'] = None\n\n# Loop through the DataFrame and calculate MFCCs for each audio file\nfor i in range(len(train)):\n    y = train.loc[i, 'y']\n    sr = train.loc[i, 'sr']\n    mfcc = librosa.feature.mfcc(y=y, sr=sr)\n    train.at[i, 'mfcc'] = mfcc","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:23:15.259618Z","iopub.execute_input":"2024-01-11T19:23:15.260274Z","iopub.status.idle":"2024-01-11T19:23:16.246325Z","shell.execute_reply.started":"2024-01-11T19:23:15.260242Z","shell.execute_reply":"2024-01-11T19:23:16.244729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['mel_spectrogram'] = None\n\n# Loop through the DataFrame and calculate Mel-spectrograms for each audio file\nfor i in range(len(train)):\n    y = train.loc[i, 'y']\n    sr = train.loc[i, 'sr']\n    \n    # Calculate Mel-spectrogram\n    mel_signal = librosa.feature.melspectrogram(y=y, sr=sr, hop_length=2, n_fft=200)\n    spectrogram = np.abs(mel_signal)\n    power_to_db = librosa.power_to_db(spectrogram, ref=np.max)\n    \n    # Store the result in the 'mel_spectrogram' column\n    train.at[i, 'mel_spectrogram'] = power_to_db\n\n# Display Mel-spectrograms for the first 10 audio files\nnum_files_to_display = 10\nfor i in range(num_files_to_display):\n    mel_spectrogram = train.loc[i, 'mel_spectrogram']\n    \n    # Plot the Mel-spectrogram\n    plt.figure(figsize=(7, 6))\n    librosa.display.specshow(mel_spectrogram, sr=train.loc[i, 'sr'], x_axis='time', y_axis='mel', cmap='magma', hop_length=2)\n    \n    plt.colorbar(label='dB')\n    plt.title(f'Mel-Spectrogram for {train.loc[i, \"ebird_code\"]}', fontdict=dict(size=18))\n    plt.xlabel('Time', fontdict=dict(size=15))\n    plt.ylabel('Frequency', fontdict=dict(size=15))\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:23:20.293211Z","iopub.execute_input":"2024-01-11T19:23:20.293655Z","iopub.status.idle":"2024-01-11T19:29:41.544209Z","shell.execute_reply.started":"2024-01-11T19:23:20.293622Z","shell.execute_reply":"2024-01-11T19:29:41.542990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}