{"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":7398896,"sourceType":"datasetVersion","datasetId":4302054}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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","execution":{"iopub.status.busy":"2024-01-14T07:32:09.807343Z","iopub.execute_input":"2024-01-14T07:32:09.807869Z","iopub.status.idle":"2024-01-14T07:32:10.300709Z","shell.execute_reply.started":"2024-01-14T07:32:09.807822Z","shell.execute_reply":"2024-01-14T07:32:10.297617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.303372Z","iopub.execute_input":"2024-01-14T07:32:10.304096Z","iopub.status.idle":"2024-01-14T07:32:10.310903Z","shell.execute_reply.started":"2024-01-14T07:32:10.304056Z","shell.execute_reply":"2024-01-14T07:32:10.309365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.313108Z","iopub.execute_input":"2024-01-14T07:32:10.315341Z","iopub.status.idle":"2024-01-14T07:32:10.617957Z","shell.execute_reply.started":"2024-01-14T07:32:10.315267Z","shell.execute_reply":"2024-01-14T07:32:10.616353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.62065Z","iopub.execute_input":"2024-01-14T07:32:10.621392Z","iopub.status.idle":"2024-01-14T07:32:10.654503Z","shell.execute_reply.started":"2024-01-14T07:32:10.621349Z","shell.execute_reply":"2024-01-14T07:32:10.652723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\npd.set_option('display.expand_frame_repr', False)\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.655908Z","iopub.execute_input":"2024-01-14T07:32:10.65658Z","iopub.status.idle":"2024-01-14T07:32:10.664433Z","shell.execute_reply.started":"2024-01-14T07:32:10.656539Z","shell.execute_reply":"2024-01-14T07:32:10.662338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.666443Z","iopub.execute_input":"2024-01-14T07:32:10.666859Z","iopub.status.idle":"2024-01-14T07:32:10.711623Z","shell.execute_reply.started":"2024-01-14T07:32:10.666808Z","shell.execute_reply":"2024-01-14T07:32:10.71035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_columns = df.columns[df.isnull().any()]\nnull_columns","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.713039Z","iopub.execute_input":"2024-01-14T07:32:10.713446Z","iopub.status.idle":"2024-01-14T07:32:10.748167Z","shell.execute_reply.started":"2024-01-14T07:32:10.71341Z","shell.execute_reply":"2024-01-14T07:32:10.746706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.750356Z","iopub.execute_input":"2024-01-14T07:32:10.750758Z","iopub.status.idle":"2024-01-14T07:32:10.759821Z","shell.execute_reply.started":"2024-01-14T07:32:10.750727Z","shell.execute_reply":"2024-01-14T07:32:10.759018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"whitegrid\")  \n\ncustom_palette = sns.color_palette(\"magma\", n_colors=len(df['rating'].unique()))\n\nsns.countplot(x='rating', data=df, order=df['rating'].value_counts().index, palette=custom_palette)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:10.761102Z","iopub.execute_input":"2024-01-14T07:32:10.76155Z","iopub.status.idle":"2024-01-14T07:32:11.089811Z","shell.execute_reply.started":"2024-01-14T07:32:10.761522Z","shell.execute_reply":"2024-01-14T07:32:11.088398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.094456Z","iopub.execute_input":"2024-01-14T07:32:11.095018Z","iopub.status.idle":"2024-01-14T07:32:11.105316Z","shell.execute_reply.started":"2024-01-14T07:32:11.094983Z","shell.execute_reply":"2024-01-14T07:32:11.103183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.107163Z","iopub.execute_input":"2024-01-14T07:32:11.107529Z","iopub.status.idle":"2024-01-14T07:32:11.12156Z","shell.execute_reply.started":"2024-01-14T07:32:11.107476Z","shell.execute_reply":"2024-01-14T07:32:11.120436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].fillna('no' , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.123096Z","iopub.execute_input":"2024-01-14T07:32:11.123421Z","iopub.status.idle":"2024-01-14T07:32:11.131207Z","shell.execute_reply.started":"2024-01-14T07:32:11.123394Z","shell.execute_reply":"2024-01-14T07:32:11.129995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"playback_used_count = df['playback_used'].value_counts()\n\ncolors = plt.cm.viridis.colors\n\nplt.figure(figsize=(8, 8))  \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-14T07:32:11.132451Z","iopub.execute_input":"2024-01-14T07:32:11.13399Z","iopub.status.idle":"2024-01-14T07:32:11.384108Z","shell.execute_reply.started":"2024-01-14T07:32:11.133952Z","shell.execute_reply":"2024-01-14T07:32:11.383163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ebird_code'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.385428Z","iopub.execute_input":"2024-01-14T07:32:11.386339Z","iopub.status.idle":"2024-01-14T07:32:11.394532Z","shell.execute_reply.started":"2024-01-14T07:32:11.386301Z","shell.execute_reply":"2024-01-14T07:32:11.393625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.395815Z","iopub.execute_input":"2024-01-14T07:32:11.39674Z","iopub.status.idle":"2024-01-14T07:32:11.407452Z","shell.execute_reply.started":"2024-01-14T07:32:11.396701Z","shell.execute_reply":"2024-01-14T07:32:11.406589Z"},"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-14T07:32:11.40875Z","iopub.execute_input":"2024-01-14T07:32:11.40956Z","iopub.status.idle":"2024-01-14T07:32:11.430286Z","shell.execute_reply.started":"2024-01-14T07:32:11.409521Z","shell.execute_reply":"2024-01-14T07:32:11.429203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.431901Z","iopub.execute_input":"2024-01-14T07:32:11.432564Z","iopub.status.idle":"2024-01-14T07:32:11.441021Z","shell.execute_reply.started":"2024-01-14T07:32:11.432526Z","shell.execute_reply":"2024-01-14T07:32:11.439366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.442784Z","iopub.execute_input":"2024-01-14T07:32:11.443534Z","iopub.status.idle":"2024-01-14T07:32:11.472356Z","shell.execute_reply.started":"2024-01-14T07:32:11.44349Z","shell.execute_reply":"2024-01-14T07:32:11.471608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.473727Z","iopub.execute_input":"2024-01-14T07:32:11.474291Z","iopub.status.idle":"2024-01-14T07:32:11.511206Z","shell.execute_reply.started":"2024-01-14T07:32:11.474259Z","shell.execute_reply":"2024-01-14T07:32:11.510166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.512748Z","iopub.execute_input":"2024-01-14T07:32:11.513149Z","iopub.status.idle":"2024-01-14T07:32:11.520962Z","shell.execute_reply.started":"2024-01-14T07:32:11.513117Z","shell.execute_reply":"2024-01-14T07:32:11.519857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['duration'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.522375Z","iopub.execute_input":"2024-01-14T07:32:11.522768Z","iopub.status.idle":"2024-01-14T07:32:11.540175Z","shell.execute_reply.started":"2024-01-14T07:32:11.522741Z","shell.execute_reply":"2024-01-14T07:32:11.539114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].unique()\ndf['species'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.541397Z","iopub.execute_input":"2024-01-14T07:32:11.541848Z","iopub.status.idle":"2024-01-14T07:32:11.558826Z","shell.execute_reply.started":"2024-01-14T07:32:11.541811Z","shell.execute_reply":"2024-01-14T07:32:11.557342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.560187Z","iopub.execute_input":"2024-01-14T07:32:11.560673Z","iopub.status.idle":"2024-01-14T07:32:11.574833Z","shell.execute_reply.started":"2024-01-14T07:32:11.560643Z","shell.execute_reply":"2024-01-14T07:32:11.572975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.57645Z","iopub.execute_input":"2024-01-14T07:32:11.577447Z","iopub.status.idle":"2024-01-14T07:32:11.587845Z","shell.execute_reply.started":"2024-01-14T07:32:11.577406Z","shell.execute_reply":"2024-01-14T07:32:11.586856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['number_of_notes'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.58912Z","iopub.execute_input":"2024-01-14T07:32:11.590835Z","iopub.status.idle":"2024-01-14T07:32:11.603069Z","shell.execute_reply.started":"2024-01-14T07:32:11.590706Z","shell.execute_reply":"2024-01-14T07:32:11.601303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['secondary_labels'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.604463Z","iopub.execute_input":"2024-01-14T07:32:11.604975Z","iopub.status.idle":"2024-01-14T07:32:11.618239Z","shell.execute_reply.started":"2024-01-14T07:32:11.604933Z","shell.execute_reply":"2024-01-14T07:32:11.61713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.619486Z","iopub.execute_input":"2024-01-14T07:32:11.619898Z","iopub.status.idle":"2024-01-14T07:32:11.62861Z","shell.execute_reply.started":"2024-01-14T07:32:11.619861Z","shell.execute_reply":"2024-01-14T07:32:11.627846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.638453Z","iopub.execute_input":"2024-01-14T07:32:11.638906Z","iopub.status.idle":"2024-01-14T07:32:11.652215Z","shell.execute_reply.started":"2024-01-14T07:32:11.638872Z","shell.execute_reply":"2024-01-14T07:32:11.650049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.654545Z","iopub.execute_input":"2024-01-14T07:32:11.655014Z","iopub.status.idle":"2024-01-14T07:32:11.668091Z","shell.execute_reply.started":"2024-01-14T07:32:11.654973Z","shell.execute_reply":"2024-01-14T07:32:11.666765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['location'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.669966Z","iopub.execute_input":"2024-01-14T07:32:11.671263Z","iopub.status.idle":"2024-01-14T07:32:11.686018Z","shell.execute_reply.started":"2024-01-14T07:32:11.671219Z","shell.execute_reply":"2024-01-14T07:32:11.684934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.687764Z","iopub.execute_input":"2024-01-14T07:32:11.688124Z","iopub.status.idle":"2024-01-14T07:32:11.697335Z","shell.execute_reply.started":"2024-01-14T07:32:11.688092Z","shell.execute_reply":"2024-01-14T07:32:11.696195Z"},"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-14T07:32:11.698945Z","iopub.execute_input":"2024-01-14T07:32:11.699239Z","iopub.status.idle":"2024-01-14T07:32:11.745812Z","shell.execute_reply.started":"2024-01-14T07:32:11.699212Z","shell.execute_reply":"2024-01-14T07:32:11.743547Z"},"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-14T07:32:11.747466Z","iopub.execute_input":"2024-01-14T07:32:11.747922Z","iopub.status.idle":"2024-01-14T07:32:11.758441Z","shell.execute_reply.started":"2024-01-14T07:32:11.747886Z","shell.execute_reply":"2024-01-14T07:32:11.757559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.759431Z","iopub.execute_input":"2024-01-14T07:32:11.759722Z","iopub.status.idle":"2024-01-14T07:32:11.799272Z","shell.execute_reply.started":"2024-01-14T07:32:11.75969Z","shell.execute_reply":"2024-01-14T07:32:11.797363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.80126Z","iopub.execute_input":"2024-01-14T07:32:11.801687Z","iopub.status.idle":"2024-01-14T07:32:11.838977Z","shell.execute_reply.started":"2024-01-14T07:32:11.801654Z","shell.execute_reply":"2024-01-14T07:32:11.837878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.840568Z","iopub.execute_input":"2024-01-14T07:32:11.840952Z","iopub.status.idle":"2024-01-14T07:32:11.853526Z","shell.execute_reply.started":"2024-01-14T07:32:11.84092Z","shell.execute_reply":"2024-01-14T07:32:11.851159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate']=df['sampling_rate'].fillna(0).astype(str).apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.856679Z","iopub.execute_input":"2024-01-14T07:32:11.857286Z","iopub.status.idle":"2024-01-14T07:32:11.877144Z","shell.execute_reply.started":"2024-01-14T07:32:11.857239Z","shell.execute_reply":"2024-01-14T07:32:11.876044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.878385Z","iopub.execute_input":"2024-01-14T07:32:11.880069Z","iopub.status.idle":"2024-01-14T07:32:11.887883Z","shell.execute_reply.started":"2024-01-14T07:32:11.880025Z","shell.execute_reply":"2024-01-14T07:32:11.886523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.889272Z","iopub.execute_input":"2024-01-14T07:32:11.889612Z","iopub.status.idle":"2024-01-14T07:32:11.904987Z","shell.execute_reply.started":"2024-01-14T07:32:11.889582Z","shell.execute_reply":"2024-01-14T07:32:11.903287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:11.906351Z","iopub.execute_input":"2024-01-14T07:32:11.906776Z","iopub.status.idle":"2024-01-14T07:32:11.917399Z","shell.execute_reply.started":"2024-01-14T07:32:11.906741Z","shell.execute_reply":"2024-01-14T07:32:11.916351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adjusted_type=df['type'].astype(str).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-14T07:32:11.918641Z","iopub.execute_input":"2024-01-14T07:32:11.918969Z","iopub.status.idle":"2024-01-14T07:32:12.181744Z","shell.execute_reply.started":"2024-01-14T07:32:11.918941Z","shell.execute_reply":"2024-01-14T07:32:12.180819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.183117Z","iopub.execute_input":"2024-01-14T07:32:12.183387Z","iopub.status.idle":"2024-01-14T07:32:12.212504Z","shell.execute_reply.started":"2024-01-14T07:32:12.183362Z","shell.execute_reply":"2024-01-14T07:32:12.210517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.21388Z","iopub.execute_input":"2024-01-14T07:32:12.2142Z","iopub.status.idle":"2024-01-14T07:32:12.225319Z","shell.execute_reply.started":"2024-01-14T07:32:12.214172Z","shell.execute_reply":"2024-01-14T07:32:12.222743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.227823Z","iopub.execute_input":"2024-01-14T07:32:12.228257Z","iopub.status.idle":"2024-01-14T07:32:12.246181Z","shell.execute_reply.started":"2024-01-14T07:32:12.228219Z","shell.execute_reply":"2024-01-14T07:32:12.244107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.248981Z","iopub.execute_input":"2024-01-14T07:32:12.249509Z","iopub.status.idle":"2024-01-14T07:32:12.26329Z","shell.execute_reply.started":"2024-01-14T07:32:12.249464Z","shell.execute_reply":"2024-01-14T07:32:12.262236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.264854Z","iopub.execute_input":"2024-01-14T07:32:12.265302Z","iopub.status.idle":"2024-01-14T07:32:12.28018Z","shell.execute_reply.started":"2024-01-14T07:32:12.26526Z","shell.execute_reply":"2024-01-14T07:32:12.2786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3']==0]","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.282183Z","iopub.execute_input":"2024-01-14T07:32:12.28266Z","iopub.status.idle":"2024-01-14T07:32:12.307519Z","shell.execute_reply.started":"2024-01-14T07:32:12.282618Z","shell.execute_reply":"2024-01-14T07:32:12.306186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(df[df['bitrate_of_mp3']=='3'].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.309988Z","iopub.execute_input":"2024-01-14T07:32:12.31069Z","iopub.status.idle":"2024-01-14T07:32:12.330548Z","shell.execute_reply.started":"2024-01-14T07:32:12.310595Z","shell.execute_reply":"2024-01-14T07:32:12.328996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3'].isna()]","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.332947Z","iopub.execute_input":"2024-01-14T07:32:12.333663Z","iopub.status.idle":"2024-01-14T07:32:12.36677Z","shell.execute_reply.started":"2024-01-14T07:32:12.333625Z","shell.execute_reply":"2024-01-14T07:32:12.365243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3']=df['bitrate_of_mp3'].fillna('0')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.368246Z","iopub.execute_input":"2024-01-14T07:32:12.369835Z","iopub.status.idle":"2024-01-14T07:32:12.378113Z","shell.execute_reply.started":"2024-01-14T07:32:12.369757Z","shell.execute_reply":"2024-01-14T07:32:12.376371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.380196Z","iopub.execute_input":"2024-01-14T07:32:12.380732Z","iopub.status.idle":"2024-01-14T07:32:12.414009Z","shell.execute_reply.started":"2024-01-14T07:32:12.380686Z","shell.execute_reply":"2024-01-14T07:32:12.413026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['file_type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.415117Z","iopub.execute_input":"2024-01-14T07:32:12.416595Z","iopub.status.idle":"2024-01-14T07:32:12.424712Z","shell.execute_reply.started":"2024-01-14T07:32:12.416536Z","shell.execute_reply":"2024-01-14T07:32:12.423516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['volume'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.427023Z","iopub.execute_input":"2024-01-14T07:32:12.427765Z","iopub.status.idle":"2024-01-14T07:32:12.440038Z","shell.execute_reply.started":"2024-01-14T07:32:12.427726Z","shell.execute_reply":"2024-01-14T07:32:12.438345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.443566Z","iopub.execute_input":"2024-01-14T07:32:12.444394Z","iopub.status.idle":"2024-01-14T07:32:12.456531Z","shell.execute_reply.started":"2024-01-14T07:32:12.444349Z","shell.execute_reply":"2024-01-14T07:32:12.45464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['primary_label'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.458582Z","iopub.execute_input":"2024-01-14T07:32:12.459639Z","iopub.status.idle":"2024-01-14T07:32:12.470097Z","shell.execute_reply.started":"2024-01-14T07:32:12.459572Z","shell.execute_reply":"2024-01-14T07:32:12.468861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.47325Z","iopub.execute_input":"2024-01-14T07:32:12.473647Z","iopub.status.idle":"2024-01-14T07:32:12.483182Z","shell.execute_reply.started":"2024-01-14T07:32:12.473609Z","shell.execute_reply":"2024-01-14T07:32:12.481756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value']=df['length'].str.extract(r'(\\d+)')\ndf['min_value']=pd.to_numeric(df['min_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.484696Z","iopub.execute_input":"2024-01-14T07:32:12.484996Z","iopub.status.idle":"2024-01-14T07:32:12.545529Z","shell.execute_reply.started":"2024-01-14T07:32:12.48497Z","shell.execute_reply":"2024-01-14T07:32:12.544133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.546871Z","iopub.execute_input":"2024-01-14T07:32:12.547249Z","iopub.status.idle":"2024-01-14T07:32:12.55802Z","shell.execute_reply.started":"2024-01-14T07:32:12.547217Z","shell.execute_reply":"2024-01-14T07:32:12.556554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value']=df['length'].str.extract(r'-(\\d+)')\ndf['max_value']=pd.to_numeric(df['max_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.559956Z","iopub.execute_input":"2024-01-14T07:32:12.560357Z","iopub.status.idle":"2024-01-14T07:32:12.612518Z","shell.execute_reply.started":"2024-01-14T07:32:12.56032Z","shell.execute_reply":"2024-01-14T07:32:12.611295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.613638Z","iopub.execute_input":"2024-01-14T07:32:12.613921Z","iopub.status.idle":"2024-01-14T07:32:12.620852Z","shell.execute_reply.started":"2024-01-14T07:32:12.613896Z","shell.execute_reply":"2024-01-14T07:32:12.619848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.621771Z","iopub.execute_input":"2024-01-14T07:32:12.622055Z","iopub.status.idle":"2024-01-14T07:32:12.657888Z","shell.execute_reply.started":"2024-01-14T07:32:12.622032Z","shell.execute_reply":"2024-01-14T07:32:12.656167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.660362Z","iopub.execute_input":"2024-01-14T07:32:12.660755Z","iopub.status.idle":"2024-01-14T07:32:12.701981Z","shell.execute_reply.started":"2024-01-14T07:32:12.660723Z","shell.execute_reply":"2024-01-14T07:32:12.700642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style='white')\nplt.figure(figsize=(10,6))\nsns.countplot(x='rating',data=df,order=df['rating'].value_counts().index,palette='Set1')\nplt.title('Distribution of Ratings')\nplt.xlabel('Rating')\nplt.ylabel('Count')\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:12.704155Z","iopub.execute_input":"2024-01-14T07:32:12.704987Z","iopub.status.idle":"2024-01-14T07:32:13.025138Z","shell.execute_reply.started":"2024-01-14T07:32:12.704952Z","shell.execute_reply":"2024-01-14T07:32:13.023944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count=df['number_of_notes'].value_counts()\ncustom_colors=[(239/255, 71/255, 111/255, 1),(247/255, 140/255, 107/255, 1),(255/255, 209/255, 102/255, 1),(6/255, 214/255, 160/255, 1),(17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(10,10))\nplt.pie(values_count,labels=None, autopct='%1.1f%%', startangle=90,colors=custom_colors, wedgeprops=dict(width=0.3) )\nplt.gca().set_facecolor('#07384C')\nplt.title(f'Distribution of number of notes', fontsize=15)\nplt.legend(values_count.index, title='Categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:13.026671Z","iopub.execute_input":"2024-01-14T07:32:13.027061Z","iopub.status.idle":"2024-01-14T07:32:13.287832Z","shell.execute_reply.started":"2024-01-14T07:32:13.027024Z","shell.execute_reply":"2024-01-14T07:32:13.287051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-14T07:32:13.289161Z","iopub.execute_input":"2024-01-14T07:32:13.289669Z","iopub.status.idle":"2024-01-14T07:32:13.319892Z","shell.execute_reply.started":"2024-01-14T07:32:13.28964Z","shell.execute_reply":"2024-01-14T07:32:13.318894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_directory = '/kaggle/input/birdsong-recognition/train_audio/'\n\naudio = base_directory + train['ebird_code'] + '/' + train['filename']\naudio","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:13.321589Z","iopub.execute_input":"2024-01-14T07:32:13.322231Z","iopub.status.idle":"2024-01-14T07:32:13.336694Z","shell.execute_reply.started":"2024-01-14T07:32:13.322198Z","shell.execute_reply":"2024-01-14T07:32:13.3345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_list = []\nsr_list = []\n\nfor audio_file in audio:\n    y_, sr_ = librosa.load(audio_file)\n    y_list.append(y_)\n    sr_list.append(sr_)\n\ntrain['y'] = y_list\ntrain['sr'] = sr_list","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:13.338838Z","iopub.execute_input":"2024-01-14T07:32:13.339327Z","iopub.status.idle":"2024-01-14T07:32:17.096439Z","shell.execute_reply.started":"2024-01-14T07:32:13.339281Z","shell.execute_reply":"2024-01-14T07:32:17.094764Z"},"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-14T07:32:17.098075Z","iopub.execute_input":"2024-01-14T07:32:17.098691Z","iopub.status.idle":"2024-01-14T07:32:17.444406Z","shell.execute_reply.started":"2024-01-14T07:32:17.098659Z","shell.execute_reply":"2024-01-14T07:32:17.442556Z"},"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-14T07:32:17.446509Z","iopub.execute_input":"2024-01-14T07:32:17.447229Z","iopub.status.idle":"2024-01-14T07:32:20.289853Z","shell.execute_reply.started":"2024-01-14T07:32:17.44719Z","shell.execute_reply":"2024-01-14T07:32:20.287913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['zcr'] = None\n\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\nnum_files_to_plot = 10  \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)  \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-14T07:32:20.29149Z","iopub.execute_input":"2024-01-14T07:32:20.291777Z","iopub.status.idle":"2024-01-14T07:32:23.210424Z","shell.execute_reply.started":"2024-01-14T07:32:20.291752Z","shell.execute_reply":"2024-01-14T07:32:23.209254Z"},"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\nnum_files_to_plot = 10  \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)  \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()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:23.212025Z","iopub.execute_input":"2024-01-14T07:32:23.212548Z","iopub.status.idle":"2024-01-14T07:32:26.385215Z","shell.execute_reply.started":"2024-01-14T07:32:23.21251Z","shell.execute_reply":"2024-01-14T07:32:26.384142Z"},"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()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T07:32:26.386713Z","iopub.execute_input":"2024-01-14T07:32:26.387083Z","iopub.status.idle":"2024-01-14T07:32:29.816244Z","shell.execute_reply.started":"2024-01-14T07:32:26.387051Z","shell.execute_reply":"2024-01-14T07:32:29.813923Z"},"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-14T07:32:29.818931Z","iopub.execute_input":"2024-01-14T07:32:29.819443Z","iopub.status.idle":"2024-01-14T07:32:33.223914Z","shell.execute_reply.started":"2024-01-14T07:32:29.819406Z","shell.execute_reply":"2024-01-14T07:32:33.222872Z"},"trusted":true},"execution_count":null,"outputs":[]}]}