{"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"},{"sourceId":1264575,"sourceType":"datasetVersion","datasetId":725893},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Chirp: Bird-call Identification","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"## Data Cleaning and Exploration","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport librosa\nimport librosa.display\nimport soundfile as sf \nimport IPython.display as ipd \nfrom matplotlib.animation import FuncAnimation\n%matplotlib inline\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.121066Z","iopub.execute_input":"2024-01-14T10:37:09.121498Z","iopub.status.idle":"2024-01-14T10:37:09.131803Z","shell.execute_reply.started":"2024-01-14T10:37:09.121463Z","shell.execute_reply":"2024-01-14T10:37:09.130468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = 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)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.133797Z","iopub.execute_input":"2024-01-14T10:37:09.134687Z","iopub.status.idle":"2024-01-14T10:37:09.398825Z","shell.execute_reply.started":"2024-01-14T10:37:09.134642Z","shell.execute_reply":"2024-01-14T10:37:09.397755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.402104Z","iopub.execute_input":"2024-01-14T10:37:09.40247Z","iopub.status.idle":"2024-01-14T10:37:09.438582Z","shell.execute_reply.started":"2024-01-14T10:37:09.402441Z","shell.execute_reply":"2024-01-14T10:37:09.437524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nulls = df.columns[df.isnull().any()]\nprint(nulls)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.442199Z","iopub.execute_input":"2024-01-14T10:37:09.443101Z","iopub.status.idle":"2024-01-14T10:37:09.471695Z","shell.execute_reply.started":"2024-01-14T10:37:09.443066Z","shell.execute_reply":"2024-01-14T10:37:09.470381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.472914Z","iopub.execute_input":"2024-01-14T10:37:09.473183Z","iopub.status.idle":"2024-01-14T10:37:09.485031Z","shell.execute_reply.started":"2024-01-14T10:37:09.47316Z","shell.execute_reply":"2024-01-14T10:37:09.483794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].fillna('no',inplace=True)\nle=LabelEncoder()\ndf['playback_used_encoded']=le.fit_transform(df['playback_used'])\n#print(df['playback_used'],df['playback_used_encoded'])","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.486508Z","iopub.execute_input":"2024-01-14T10:37:09.48677Z","iopub.status.idle":"2024-01-14T10:37:09.498913Z","shell.execute_reply.started":"2024-01-14T10:37:09.486747Z","shell.execute_reply":"2024-01-14T10:37:09.497918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('playback_used',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.500571Z","iopub.execute_input":"2024-01-14T10:37:09.500983Z","iopub.status.idle":"2024-01-14T10:37:09.519476Z","shell.execute_reply.started":"2024-01-14T10:37:09.500955Z","shell.execute_reply":"2024-01-14T10:37:09.518648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels']=df['channels'].astype(str).str[0].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.520599Z","iopub.execute_input":"2024-01-14T10:37:09.520844Z","iopub.status.idle":"2024-01-14T10:37:09.538233Z","shell.execute_reply.started":"2024-01-14T10:37:09.520821Z","shell.execute_reply":"2024-01-14T10:37:09.537596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year']=df['date'].apply(lambda x: x.split('-')[0]).astype(int)\ndf['month']=df['date'].apply(lambda x: x.split('-')[1]).astype(int)\ndf['day_of_month'] = df['date'].apply(lambda x: x.split('-')[2]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.538919Z","iopub.execute_input":"2024-01-14T10:37:09.539166Z","iopub.status.idle":"2024-01-14T10:37:09.578718Z","shell.execute_reply.started":"2024-01-14T10:37:09.539144Z","shell.execute_reply":"2024-01-14T10:37:09.577951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('date',axis=1,inplace=True)\n#df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:09.579719Z","iopub.execute_input":"2024-01-14T10:37:09.579979Z","iopub.status.idle":"2024-01-14T10:37:09.599772Z","shell.execute_reply.started":"2024-01-14T10:37:09.579955Z","shell.execute_reply":"2024-01-14T10:37:09.599045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"latitude\"].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:23.10773Z","iopub.execute_input":"2024-01-14T10:37:23.108104Z","iopub.status.idle":"2024-01-14T10:37:23.118494Z","shell.execute_reply.started":"2024-01-14T10:37:23.108075Z","shell.execute_reply":"2024-01-14T10:37:23.117351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df[df['latitude'] != 'Not specified']\ndf = df[df['longitude'] != 'Not specified']","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:31.697897Z","iopub.execute_input":"2024-01-14T10:37:31.698416Z","iopub.status.idle":"2024-01-14T10:37:31.741301Z","shell.execute_reply.started":"2024-01-14T10:37:31.698372Z","shell.execute_reply":"2024-01-14T10:37:31.739954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'] = df[\"latitude\"].astype(float) \ndf['longitude'] = df['longitude'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:41.749981Z","iopub.execute_input":"2024-01-14T10:37:41.750408Z","iopub.status.idle":"2024-01-14T10:37:41.763859Z","shell.execute_reply.started":"2024-01-14T10:37:41.750376Z","shell.execute_reply":"2024-01-14T10:37:41.762093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'] = df['sampling_rate'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:37:50.423768Z","iopub.execute_input":"2024-01-14T10:37:50.424119Z","iopub.status.idle":"2024-01-14T10:37:50.440012Z","shell.execute_reply.started":"2024-01-14T10:37:50.424093Z","shell.execute_reply":"2024-01-14T10:37:50.438322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:38:35.800239Z","iopub.execute_input":"2024-01-14T10:38:35.800587Z","iopub.status.idle":"2024-01-14T10:38:35.822839Z","shell.execute_reply.started":"2024-01-14T10:38:35.800558Z","shell.execute_reply":"2024-01-14T10:38:35.821858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['title','species','title','secondary_labels','description','license','recordist','primary_label','url','location'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:38:32.025223Z","iopub.execute_input":"2024-01-14T10:38:32.025572Z","iopub.status.idle":"2024-01-14T10:38:32.036868Z","shell.execute_reply.started":"2024-01-14T10:38:32.025544Z","shell.execute_reply":"2024-01-14T10:38:32.035111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adjusted_type = df['type'].apply(lambda x: x.split(',')).reset_index().explode(\"type\")\nadjusted_type = adjusted_type['type'].apply(lambda x: x.strip().lower()).reset_index()\nadjusted_type['type']=adjusted_type['type'].replace('calls', 'call')\nadjusted_type['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:38:46.470375Z","iopub.execute_input":"2024-01-14T10:38:46.470834Z","iopub.status.idle":"2024-01-14T10:38:46.582751Z","shell.execute_reply.started":"2024-01-14T10:38:46.470798Z","shell.execute_reply":"2024-01-14T10:38:46.581349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:39:14.37501Z","iopub.execute_input":"2024-01-14T10:39:14.375373Z","iopub.status.idle":"2024-01-14T10:39:14.383892Z","shell.execute_reply.started":"2024-01-14T10:39:14.375322Z","shell.execute_reply":"2024-01-14T10:39:14.382896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] =df['elevation'].replace(['? m','-m' ,'Unknown m','m',''], '99999')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:39:24.186485Z","iopub.execute_input":"2024-01-14T10:39:24.187028Z","iopub.status.idle":"2024-01-14T10:39:24.200602Z","shell.execute_reply.started":"2024-01-14T10:39:24.186988Z","shell.execute_reply":"2024-01-14T10:39:24.198871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].apply(lambda x: x.split('.')[0])\ndf['elevation'] = df['elevation'].apply(lambda x: x.split(' ')[0])","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:39:45.165545Z","iopub.execute_input":"2024-01-14T10:39:45.16591Z","iopub.status.idle":"2024-01-14T10:39:45.189303Z","shell.execute_reply.started":"2024-01-14T10:39:45.165882Z","shell.execute_reply":"2024-01-14T10:39:45.187859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = pd.to_numeric(df['elevation'], errors = 'coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:39:54.575587Z","iopub.execute_input":"2024-01-14T10:39:54.576039Z","iopub.status.idle":"2024-01-14T10:39:54.596024Z","shell.execute_reply.started":"2024-01-14T10:39:54.576003Z","shell.execute_reply":"2024-01-14T10:39:54.595013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dropna(inplace=True,axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:40:04.774594Z","iopub.execute_input":"2024-01-14T10:40:04.776028Z","iopub.status.idle":"2024-01-14T10:40:04.79428Z","shell.execute_reply.started":"2024-01-14T10:40:04.775992Z","shell.execute_reply":"2024-01-14T10:40:04.793596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = pd.to_numeric(df['elevation'], errors='coerce')\nsum_elevation = 0\ncount_valid_values = 0\nfor index, row in df.iterrows():\n    if row['elevation'] != 99999:\n        sum_elevation += row['elevation']\n        count_valid_values += 1\n    mean_elevation = sum_elevation / count_valid_values\nmean_elevation","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:40:20.271714Z","iopub.execute_input":"2024-01-14T10:40:20.272182Z","iopub.status.idle":"2024-01-14T10:40:20.703137Z","shell.execute_reply.started":"2024-01-14T10:40:20.272141Z","shell.execute_reply":"2024-01-14T10:40:20.701183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] =df['elevation'].replace('99999',mean_elevation)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:40:31.599139Z","iopub.execute_input":"2024-01-14T10:40:31.599481Z","iopub.status.idle":"2024-01-14T10:40:31.604964Z","shell.execute_reply.started":"2024-01-14T10:40:31.599455Z","shell.execute_reply":"2024-01-14T10:40:31.60359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:40:40.908823Z","iopub.execute_input":"2024-01-14T10:40:40.909261Z","iopub.status.idle":"2024-01-14T10:40:40.921845Z","shell.execute_reply.started":"2024-01-14T10:40:40.90923Z","shell.execute_reply":"2024-01-14T10:40:40.920404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'] = df['bitrate_of_mp3'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:40:55.746391Z","iopub.execute_input":"2024-01-14T10:40:55.746737Z","iopub.status.idle":"2024-01-14T10:40:55.758896Z","shell.execute_reply.started":"2024-01-14T10:40:55.746703Z","shell.execute_reply":"2024-01-14T10:40:55.757208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['background','author','xc_id','length'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:41:06.711285Z","iopub.execute_input":"2024-01-14T10:41:06.71162Z","iopub.status.idle":"2024-01-14T10:41:06.719725Z","shell.execute_reply.started":"2024-01-14T10:41:06.711595Z","shell.execute_reply":"2024-01-14T10:41:06.718815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:41:57.814146Z","iopub.execute_input":"2024-01-14T10:41:57.814567Z","iopub.status.idle":"2024-01-14T10:41:57.837846Z","shell.execute_reply.started":"2024-01-14T10:41:57.814535Z","shell.execute_reply":"2024-01-14T10:41:57.836938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Visulaization","metadata":{}},{"cell_type":"code","source":"sns.countplot(x='rating', data=df, order=df['rating'].value_counts().index, palette='plasma')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:42:15.337506Z","iopub.execute_input":"2024-01-14T10:42:15.33785Z","iopub.status.idle":"2024-01-14T10:42:15.586988Z","shell.execute_reply.started":"2024-01-14T10:42:15.337823Z","shell.execute_reply":"2024-01-14T10:42:15.585537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count = df['playback_used_encoded'].value_counts()\ncolors = sns.color_palette('plasma')[0:len(count)]\nplt.figure(figsize=(4, 4))\n\nplt.pie(df['playback_used_encoded'].value_counts(), labels=df['playback_used_encoded'].value_counts().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(df['playback_used_encoded'].index, loc='best', bbox_to_anchor=(0.8, 0.8))\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:47:47.256247Z","iopub.execute_input":"2024-01-14T10:47:47.256674Z","iopub.status.idle":"2024-01-14T10:47:47.420099Z","shell.execute_reply.started":"2024-01-14T10:47:47.256644Z","shell.execute_reply":"2024-01-14T10:47:47.418946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count = df['channels'].value_counts()\ncolors = sns.color_palette('plasma')[0:len(count)]\n\nplt.figure(figsize=(4, 4))\nplt.pie(count, labels=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(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-14T10:48:25.171429Z","iopub.execute_input":"2024-01-14T10:48:25.171868Z","iopub.status.idle":"2024-01-14T10:48:25.348705Z","shell.execute_reply.started":"2024-01-14T10:48:25.171835Z","shell.execute_reply":"2024-01-14T10:48:25.347814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 6))\nsns.countplot(x='year', data=df, palette=\"plasma\")\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\nplt.grid(axis='y', linestyle='--', alpha=0.7)\n\nplt.tight_layout()\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:50:44.772982Z","iopub.execute_input":"2024-01-14T10:50:44.773301Z","iopub.status.idle":"2024-01-14T10:50:45.261783Z","shell.execute_reply.started":"2024-01-14T10:50:44.773277Z","shell.execute_reply":"2024-01-14T10:50:45.261039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.countplot(x='month', data=df, palette='plasma')\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-14T10:50:45.263132Z","iopub.execute_input":"2024-01-14T10:50:45.263533Z","iopub.status.idle":"2024-01-14T10:50:45.552259Z","shell.execute_reply.started":"2024-01-14T10:50:45.263509Z","shell.execute_reply":"2024-01-14T10:50:45.551363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.countplot(x='day_of_month', data=df, palette='plasma')\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-14T10:50:45.55421Z","iopub.execute_input":"2024-01-14T10:50:45.554742Z","iopub.status.idle":"2024-01-14T10:50:45.934125Z","shell.execute_reply.started":"2024-01-14T10:50:45.554709Z","shell.execute_reply":"2024-01-14T10:50:45.93312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.countplot(x='pitch', data=df, palette='plasma')\n\nplt.xticks(rotation =90)\nplt.title('Plot of Pitch')\nplt.xlabel('pitch')\nplt.ylabel('Count')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T10:51:19.652621Z","iopub.execute_input":"2024-01-14T10:51:19.653079Z","iopub.status.idle":"2024-01-14T10:51:19.874222Z","shell.execute_reply.started":"2024-01-14T10:51:19.653043Z","shell.execute_reply":"2024-01-14T10:51:19.87219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.countplot(x='speed', data=df, palette='plasma')\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-14T10:51:48.038473Z","iopub.execute_input":"2024-01-14T10:51:48.038826Z","iopub.status.idle":"2024-01-14T10:51:48.246613Z","shell.execute_reply.started":"2024-01-14T10:51:48.038799Z","shell.execute_reply":"2024-01-14T10:51:48.245498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.countplot(x='number_of_notes', data=df, palette='plasma')\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-14T10:52:33.784753Z","iopub.execute_input":"2024-01-14T10:52:33.785212Z","iopub.status.idle":"2024-01-14T10:52:34.013844Z","shell.execute_reply.started":"2024-01-14T10:52:33.785181Z","shell.execute_reply":"2024-01-14T10:52:34.012429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4,4))\nsns.countplot(x='bird_seen', data=df, palette='plasma')\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-14T10:53:08.247575Z","iopub.execute_input":"2024-01-14T10:53:08.24794Z","iopub.status.idle":"2024-01-14T10:53:08.448237Z","shell.execute_reply.started":"2024-01-14T10:53:08.24791Z","shell.execute_reply":"2024-01-14T10:53:08.447151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 6))  \n\nax = sns.countplot(x='sampling_rate', data=df, palette='plasma')\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-14T10:54:28.584651Z","iopub.execute_input":"2024-01-14T10:54:28.585083Z","iopub.status.idle":"2024-01-14T10:54:28.805819Z","shell.execute_reply.started":"2024-01-14T10:54:28.585046Z","shell.execute_reply":"2024-01-14T10:54:28.804953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4, 4))  \n\nax = sns.countplot(x='volume', data=df, palette='plasma')\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-14T10:55:23.21379Z","iopub.execute_input":"2024-01-14T10:55:23.21506Z","iopub.status.idle":"2024-01-14T10:55:23.390413Z","shell.execute_reply.started":"2024-01-14T10:55:23.215023Z","shell.execute_reply":"2024-01-14T10:55:23.389649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4, 4))  \n\nax = sns.countplot(x='file_type', data=df, palette='plasma')\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-14T10:57:52.743107Z","iopub.execute_input":"2024-01-14T10:57:52.743601Z","iopub.status.idle":"2024-01-14T10:57:52.927083Z","shell.execute_reply.started":"2024-01-14T10:57:52.743564Z","shell.execute_reply":"2024-01-14T10:57:52.926392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Feature Engineering","metadata":{}},{"cell_type":"code","source":"audio={'aldfly':['/kaggle/input/birdsong-recognition/train_audio/aldfly/XC134874.mp3','/kaggle/input/birdsong-recognition/train_audio/aldfly/XC135454.mp3'],\n            'ameavo':['/kaggle/input/birdsong-recognition/train_audio/ameavo/XC133080.mp3','/kaggle/input/birdsong-recognition/train_audio/ameavo/XC139829.mp3'],\n            'amebit':['/kaggle/input/birdsong-recognition/train_audio/amebit/XC127371.mp3','/kaggle/input/birdsong-recognition/train_audio/amebit/XC130058.mp3'],\n            'amecro':['/kaggle/input/birdsong-recognition/train_audio/amecro/XC109768.mp3','/kaggle/input/birdsong-recognition/train_audio/amecro/XC112598.mp3'],\n            'amegfi':['/kaggle/input/birdsong-recognition/train_audio/amegfi/XC109299.mp3','/kaggle/input/birdsong-recognition/train_audio/amegfi/XC109300.mp3']}\n\naudio_signals={'aldfly':[],\n            'ameavo':[],\n            'amebit':[],\n            'amecro':[],\n            'amegfi':[]}\n\nsample_rates={'aldfly':[],\n            'ameavo':[],\n            'amebit':[],\n            'amecro':[],\n            'amegfi':[]}\n\nall_features_mfcc={\n    'aldfly':[],\n            'ameavo':[],\n            'amebit':[],\n            'amecro':[],\n            'amegfi':[]\n}\n\nfor key,value in audio_files.items():\n    print(f\"Audio {key}\")\n    y1, sr1 = librosa.load(value[0])\n    y2, sr2 = librosa.load(value[1])\n    display(ipd.Audio(y1, rate=sr1))\n    display(ipd.Audio(y2, rate=sr2))\n    audio_signals[key].append(y1)\n    audio_signals[key].append(y2)\n    sample_rates[key].append(sr1)\n    sample_rates[key].append(sr2)\nsample_rates","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:01:46.872223Z","iopub.execute_input":"2024-01-14T11:01:46.872582Z","iopub.status.idle":"2024-01-14T11:01:57.164868Z","shell.execute_reply.started":"2024-01-14T11:01:46.872554Z","shell.execute_reply":"2024-01-14T11:01:57.163173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"minn=444","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:02:25.288558Z","iopub.execute_input":"2024-01-14T11:02:25.289217Z","iopub.status.idle":"2024-01-14T11:02:25.295684Z","shell.execute_reply.started":"2024-01-14T11:02:25.289187Z","shell.execute_reply":"2024-01-14T11:02:25.293689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_features_mfcc(audio_file):\n    y, sr = librosa.load(audio_file)\n    mfcc = librosa.feature.mfcc(y=y,n_mfcc=13, sr=sr)\n    return mfcc\n\nfor key in ['aldfly','ameavo','amebit','amecro','amegfi']:\n    all_features_mfcc[key].append( np.array([extract_features_mfcc(file)[:,:minn] for file in audio_files[key]]))   #Keeping no. of frames same for all files\n    all_features_mfcc[key].append (np.mean(all_features_mfcc[key][0], axis=0))\n    all_features_mfcc[key].append (np.std(all_features_mfcc[key][0], axis=0))","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:03:58.506682Z","iopub.execute_input":"2024-01-14T11:03:58.507036Z","iopub.status.idle":"2024-01-14T11:04:01.043917Z","shell.execute_reply.started":"2024-01-14T11:03:58.507006Z","shell.execute_reply":"2024-01-14T11:04:01.043096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport librosa.display\n\nplt.figure(figsize=(10, 20))\ni = 0\nfor key in ['aldfly', 'ameavo', 'amebit', 'amecro', 'amegfi']:\n    plt.subplot(5, 2, i + 1)\n    librosa.display.specshow(all_features_mfcc[key][0][0, :, :], sr=sample_rates[key][0], x_axis='time', cmap='viridis')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title(f'MFCC- {key} 1')\n    i = i + 1\n    plt.subplot(5, 2, i + 1)\n    librosa.display.specshow(all_features_mfcc[key][0][1, :, :], sr=sample_rates[key][1], x_axis='time', cmap='viridis')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title(f'MFCC- {key} 2')\n    i = i + 1\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:15:52.405035Z","iopub.execute_input":"2024-01-14T11:15:52.405516Z","iopub.status.idle":"2024-01-14T11:15:54.328695Z","shell.execute_reply.started":"2024-01-14T11:15:52.405488Z","shell.execute_reply":"2024-01-14T11:15:54.327172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 20))\ni=0\nfor key in ['aldfly','ameavo','amebit','amecro','amegfi']:\n    plt.subplot(5, 2, i+1)\n    D = librosa.amplitude_to_db(np.abs(librosa.stft(audio_signals[key][0])), ref=np.max)\n    librosa.display.specshow(D, sr=sample_rates[key][0], x_axis='time', y_axis='log')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title(f'Spectrogram-{key} - Audio 1')\n    i=i+1\n    plt.subplot(5, 2, i+1)\n    D = librosa.amplitude_to_db(np.abs(librosa.stft(audio_signals[key][1])), ref=np.max)\n    librosa.display.specshow(D, sr=sample_rates[key][1], x_axis='time', y_axis='log')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title(f'Spectrogram-{key} - Audio 2')\n    i=i+1\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:08:50.827501Z","iopub.execute_input":"2024-01-14T11:08:50.827834Z","iopub.status.idle":"2024-01-14T11:09:05.682563Z","shell.execute_reply.started":"2024-01-14T11:08:50.827807Z","shell.execute_reply":"2024-01-14T11:09:05.681391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 20))\ni=0\nfor key in ['aldfly','ameavo','amebit','amecro','amegfi']:\n    plt.subplot(5, 2, i+1)\n    zcr = np.array([librosa.feature.zero_crossing_rate(x)[:,:minn] for x in audio_signals[key]])\n    mean_zcr = np.mean(zcr, axis=0).flatten()\n    plt.plot([x+1 for x in range(minn)],mean_zcr)\n    plt.title(f'Mean_ZCR_{key}')\n    i=i+1\n    plt.subplot(5, 2, i+1)\n    std_zcr = np.std(zcr, axis=0).flatten()\n    plt.plot([x+1 for x in range(minn)],std_zcr)\n    plt.title(f'Std_ZCR_{key}')\n    i=i+1\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:12:02.057025Z","iopub.execute_input":"2024-01-14T11:12:02.057535Z","iopub.status.idle":"2024-01-14T11:12:04.029858Z","shell.execute_reply.started":"2024-01-14T11:12:02.057498Z","shell.execute_reply":"2024-01-14T11:12:04.029024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 20))\ni=0\nfor key in ['aldfly','ameavo','amebit','amecro','amegfi']:\n    plt.subplot(5, 2, i+1)\n    zcr = np.array([librosa.feature.zero_crossing_rate(x)[:,:minn] for x in audio_signals[key]])\n    mean_zcr = np.mean(zcr, axis=0).flatten()\n    plt.plot([x+1 for x in range(minn)],mean_zcr)\n    plt.title(f'Mean_zcr_{key}')\n    i=i+1\n    plt.subplot(5, 2, i+1)\n    std_zcr = np.std(zcr, axis=0).flatten()\n    plt.plot([x+1 for x in range(minn)],std_zcr)\n    plt.title(f'Std_zcr_{key}')\n    i=i+1\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:14:39.590948Z","iopub.execute_input":"2024-01-14T11:14:39.591555Z","iopub.status.idle":"2024-01-14T11:14:41.544127Z","shell.execute_reply.started":"2024-01-14T11:14:39.591522Z","shell.execute_reply":"2024-01-14T11:14:41.542864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 20))\nsns.set_palette(\"plasma\")\nfor i, key in enumerate(audio_signals.keys()):\n    for j in range(2):  \n        plt.subplot(5, 2, i * 2 + j + 1)\n        y = audio_signals[key][j]\n        sr = sample_rates[key][j]\n        chroma = librosa.feature.chroma_stft(y=y, sr=sr)\n        librosa.display.specshow(chroma, y_axis='chroma', x_axis='time')\n        plt.colorbar()\n        plt.title(f'Chroma-{key} - Audio {j + 1}')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T11:18:13.587257Z","iopub.execute_input":"2024-01-14T11:18:13.587837Z","iopub.status.idle":"2024-01-14T11:18:21.484027Z","shell.execute_reply.started":"2024-01-14T11:18:13.587795Z","shell.execute_reply":"2024-01-14T11:18:21.482412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}