{"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":7368410,"sourceType":"datasetVersion","datasetId":4280819},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424}],"dockerImageVersionId":30626,"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\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-11T13:24:24.637641Z","iopub.execute_input":"2024-01-11T13:24:24.638082Z","iopub.status.idle":"2024-01-11T13:24:24.645355Z","shell.execute_reply.started":"2024-01-11T13:24:24.638050Z","shell.execute_reply":"2024-01-11T13:24:24.642836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:26.323854Z","iopub.execute_input":"2024-01-11T13:24:26.324290Z","iopub.status.idle":"2024-01-11T13:24:26.583614Z","shell.execute_reply.started":"2024-01-11T13:24:26.324226Z","shell.execute_reply":"2024-01-11T13:24:26.581672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lets change the pandas view settings to be able to see all the columns","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_columns',None)\npd.set_option('display.expand_frame_repr',False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:26.612607Z","iopub.execute_input":"2024-01-11T13:24:26.613011Z","iopub.status.idle":"2024-01-11T13:24:26.619019Z","shell.execute_reply.started":"2024-01-11T13:24:26.612978Z","shell.execute_reply":"2024-01-11T13:24:26.617783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:26.783156Z","iopub.execute_input":"2024-01-11T13:24:26.783810Z","iopub.status.idle":"2024-01-11T13:24:26.812834Z","shell.execute_reply.started":"2024-01-11T13:24:26.783770Z","shell.execute_reply":"2024-01-11T13:24:26.811154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:26.985130Z","iopub.execute_input":"2024-01-11T13:24:26.985820Z","iopub.status.idle":"2024-01-11T13:24:26.993334Z","shell.execute_reply.started":"2024-01-11T13:24:26.985779Z","shell.execute_reply":"2024-01-11T13:24:26.992216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_with_nulls=data.columns[data.isnull().any()]\nprint(column_with_nulls)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.047224Z","iopub.execute_input":"2024-01-11T13:24:27.047696Z","iopub.status.idle":"2024-01-11T13:24:27.078725Z","shell.execute_reply.started":"2024-01-11T13:24:27.047661Z","shell.execute_reply":"2024-01-11T13:24:27.077160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.columns","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.252072Z","iopub.execute_input":"2024-01-11T13:24:27.252468Z","iopub.status.idle":"2024-01-11T13:24:27.261450Z","shell.execute_reply.started":"2024-01-11T13:24:27.252434Z","shell.execute_reply":"2024-01-11T13:24:27.259551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['rating'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.473045Z","iopub.execute_input":"2024-01-11T13:24:27.473510Z","iopub.status.idle":"2024-01-11T13:24:27.485318Z","shell.execute_reply.started":"2024-01-11T13:24:27.473472Z","shell.execute_reply":"2024-01-11T13:24:27.482994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.537118Z","iopub.execute_input":"2024-01-11T13:24:27.537500Z","iopub.status.idle":"2024-01-11T13:24:27.547427Z","shell.execute_reply.started":"2024-01-11T13:24:27.537468Z","shell.execute_reply":"2024-01-11T13:24:27.545981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since rating column has only 11 distinct numerical values so we need not encode it.","metadata":{}},{"cell_type":"code","source":"data['rating'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.808323Z","iopub.execute_input":"2024-01-11T13:24:27.808795Z","iopub.status.idle":"2024-01-11T13:24:27.821407Z","shell.execute_reply.started":"2024-01-11T13:24:27.808757Z","shell.execute_reply":"2024-01-11T13:24:27.819896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:27.964373Z","iopub.execute_input":"2024-01-11T13:24:27.964760Z","iopub.status.idle":"2024-01-11T13:24:27.972784Z","shell.execute_reply.started":"2024-01-11T13:24:27.964735Z","shell.execute_reply":"2024-01-11T13:24:27.971074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:28.105134Z","iopub.execute_input":"2024-01-11T13:24:28.105558Z","iopub.status.idle":"2024-01-11T13:24:28.117962Z","shell.execute_reply.started":"2024-01-11T13:24:28.105523Z","shell.execute_reply":"2024-01-11T13:24:28.116134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"play_back used column has a small number of null entries also so lets fill those with 'no' since most of the entries(18964/21375) have no playback.","metadata":{}},{"cell_type":"code","source":"data['playback_used'].fillna('no', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:28.421689Z","iopub.execute_input":"2024-01-11T13:24:28.422127Z","iopub.status.idle":"2024-01-11T13:24:28.430073Z","shell.execute_reply.started":"2024-01-11T13:24:28.422095Z","shell.execute_reply":"2024-01-11T13:24:28.428840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:28.564722Z","iopub.execute_input":"2024-01-11T13:24:28.565135Z","iopub.status.idle":"2024-01-11T13:24:28.574942Z","shell.execute_reply.started":"2024-01-11T13:24:28.565102Z","shell.execute_reply":"2024-01-11T13:24:28.573747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['playback_used'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:28.732146Z","iopub.execute_input":"2024-01-11T13:24:28.732538Z","iopub.status.idle":"2024-01-11T13:24:28.742924Z","shell.execute_reply.started":"2024-01-11T13:24:28.732508Z","shell.execute_reply":"2024-01-11T13:24:28.741676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"now to use this column(playback_used) in our model we need to encode it using 0 and 1","metadata":{}},{"cell_type":"code","source":"le=LabelEncoder()\ndata['playback_used_encoded'] = le.fit_transform(data['playback_used'])\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:29.108566Z","iopub.execute_input":"2024-01-11T13:24:29.109379Z","iopub.status.idle":"2024-01-11T13:24:29.145849Z","shell.execute_reply.started":"2024-01-11T13:24:29.109323Z","shell.execute_reply":"2024-01-11T13:24:29.144803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since we have encoded playback_used we no longer need the original playback_used column containing strings of 'yes' and 'no'","metadata":{}},{"cell_type":"code","source":"data.drop('playback_used',axis=1 , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:29.367752Z","iopub.execute_input":"2024-01-11T13:24:29.368132Z","iopub.status.idle":"2024-01-11T13:24:29.382678Z","shell.execute_reply.started":"2024-01-11T13:24:29.368105Z","shell.execute_reply":"2024-01-11T13:24:29.380941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['ebird_code'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:29.519769Z","iopub.execute_input":"2024-01-11T13:24:29.520156Z","iopub.status.idle":"2024-01-11T13:24:29.530421Z","shell.execute_reply.started":"2024-01-11T13:24:29.520120Z","shell.execute_reply":"2024-01-11T13:24:29.529200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['ebird_code'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:29.698509Z","iopub.execute_input":"2024-01-11T13:24:29.699653Z","iopub.status.idle":"2024-01-11T13:24:29.707185Z","shell.execute_reply.started":"2024-01-11T13:24:29.699619Z","shell.execute_reply":"2024-01-11T13:24:29.706139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"column ebird_code contains 264 unique values we will later encode this column also to be used in our model","metadata":{}},{"cell_type":"code","source":"data['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:29.991786Z","iopub.execute_input":"2024-01-11T13:24:29.992193Z","iopub.status.idle":"2024-01-11T13:24:30.000748Z","shell.execute_reply.started":"2024-01-11T13:24:29.992161Z","shell.execute_reply":"2024-01-11T13:24:29.999529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['channels'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:30.148776Z","iopub.execute_input":"2024-01-11T13:24:30.149190Z","iopub.status.idle":"2024-01-11T13:24:30.161510Z","shell.execute_reply.started":"2024-01-11T13:24:30.149159Z","shell.execute_reply":"2024-01-11T13:24:30.159154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"channels column has only two category '1 (mono)', '2 (stereo)' so we can encode it and for that we first convert it to string , take the first character and again convert in to integer data type, but please note that this column won't help us in our model because librosa will convert all the audios to mono channel.","metadata":{}},{"cell_type":"code","source":"data['channels']=data['channels'].astype(str).str[0].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:30.512713Z","iopub.execute_input":"2024-01-11T13:24:30.513139Z","iopub.status.idle":"2024-01-11T13:24:30.534488Z","shell.execute_reply.started":"2024-01-11T13:24:30.513105Z","shell.execute_reply":"2024-01-11T13:24:30.533105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['channels'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:30.730008Z","iopub.execute_input":"2024-01-11T13:24:30.730338Z","iopub.status.idle":"2024-01-11T13:24:30.740534Z","shell.execute_reply.started":"2024-01-11T13:24:30.730315Z","shell.execute_reply":"2024-01-11T13:24:30.737974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['date'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:30.793707Z","iopub.execute_input":"2024-01-11T13:24:30.794129Z","iopub.status.idle":"2024-01-11T13:24:30.806411Z","shell.execute_reply.started":"2024-01-11T13:24:30.794096Z","shell.execute_reply":"2024-01-11T13:24:30.804118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['date'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:30.937470Z","iopub.execute_input":"2024-01-11T13:24:30.938797Z","iopub.status.idle":"2024-01-11T13:24:30.950726Z","shell.execute_reply.started":"2024-01-11T13:24:30.938723Z","shell.execute_reply":"2024-01-11T13:24:30.949278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The date column has format yyyy-mm-dd so we can split based on hyphen an create three columns each for year, month and date.\nThe idea behind using this is that it is possible that some birds may come out only certain months of the year depending upon the wheather conditions suitable to them.","metadata":{}},{"cell_type":"code","source":"data['year']=data['date'].apply(lambda x: x.split('-')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:31.257687Z","iopub.execute_input":"2024-01-11T13:24:31.258074Z","iopub.status.idle":"2024-01-11T13:24:31.277506Z","shell.execute_reply.started":"2024-01-11T13:24:31.258047Z","shell.execute_reply":"2024-01-11T13:24:31.275642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['month']=data['date'].apply(lambda x: x.split('-')[1]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:31.416855Z","iopub.execute_input":"2024-01-11T13:24:31.417259Z","iopub.status.idle":"2024-01-11T13:24:31.435653Z","shell.execute_reply.started":"2024-01-11T13:24:31.417223Z","shell.execute_reply":"2024-01-11T13:24:31.433945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['day']=data['date'].apply(lambda x: x.split('-')[2]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:31.548359Z","iopub.execute_input":"2024-01-11T13:24:31.548744Z","iopub.status.idle":"2024-01-11T13:24:31.566774Z","shell.execute_reply.started":"2024-01-11T13:24:31.548720Z","shell.execute_reply":"2024-01-11T13:24:31.565952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now we can drop the date column since we have extracted its information in the form of year,month and date","metadata":{}},{"cell_type":"code","source":"data.drop('date', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:31.891250Z","iopub.execute_input":"2024-01-11T13:24:31.891634Z","iopub.status.idle":"2024-01-11T13:24:31.907609Z","shell.execute_reply.started":"2024-01-11T13:24:31.891580Z","shell.execute_reply":"2024-01-11T13:24:31.905762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:32.054797Z","iopub.execute_input":"2024-01-11T13:24:32.055235Z","iopub.status.idle":"2024-01-11T13:24:32.087211Z","shell.execute_reply.started":"2024-01-11T13:24:32.055204Z","shell.execute_reply":"2024-01-11T13:24:32.085599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['pitch'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:32.227508Z","iopub.execute_input":"2024-01-11T13:24:32.227959Z","iopub.status.idle":"2024-01-11T13:24:32.237054Z","shell.execute_reply.started":"2024-01-11T13:24:32.227933Z","shell.execute_reply":"2024-01-11T13:24:32.235980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['pitch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:32.390919Z","iopub.execute_input":"2024-01-11T13:24:32.391782Z","iopub.status.idle":"2024-01-11T13:24:32.403386Z","shell.execute_reply.started":"2024-01-11T13:24:32.391739Z","shell.execute_reply":"2024-01-11T13:24:32.401898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since pitch column has only 4 categories we can do a label encoding for this","metadata":{}},{"cell_type":"code","source":"le=LabelEncoder()\ndata['pitch_encoded'] = le.fit_transform(data['pitch'])\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:32.760367Z","iopub.execute_input":"2024-01-11T13:24:32.760934Z","iopub.status.idle":"2024-01-11T13:24:32.796773Z","shell.execute_reply.started":"2024-01-11T13:24:32.760899Z","shell.execute_reply":"2024-01-11T13:24:32.795795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After label encodeing we must drop the pitch column sice it is of no use now","metadata":{}},{"cell_type":"code","source":"data.drop('pitch', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:33.083458Z","iopub.execute_input":"2024-01-11T13:24:33.083936Z","iopub.status.idle":"2024-01-11T13:24:33.099435Z","shell.execute_reply.started":"2024-01-11T13:24:33.083901Z","shell.execute_reply":"2024-01-11T13:24:33.097265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['duration'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:33.272112Z","iopub.execute_input":"2024-01-11T13:24:33.272520Z","iopub.status.idle":"2024-01-11T13:24:33.285501Z","shell.execute_reply.started":"2024-01-11T13:24:33.272487Z","shell.execute_reply":"2024-01-11T13:24:33.284413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['duration'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:33.463375Z","iopub.execute_input":"2024-01-11T13:24:33.463813Z","iopub.status.idle":"2024-01-11T13:24:33.474272Z","shell.execute_reply.started":"2024-01-11T13:24:33.463781Z","shell.execute_reply":"2024-01-11T13:24:33.471811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:33.625377Z","iopub.execute_input":"2024-01-11T13:24:33.626548Z","iopub.status.idle":"2024-01-11T13:24:33.663496Z","shell.execute_reply.started":"2024-01-11T13:24:33.626508Z","shell.execute_reply":"2024-01-11T13:24:33.661439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"duration column has no null value and its data type is integer so we need not do anything with this colummn, Similarly filename column also has no null value and is used to get the path of the audios while iterating through each one of them so we are not doing anything with this column also.","metadata":{}},{"cell_type":"code","source":"data['speed'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:33.981398Z","iopub.execute_input":"2024-01-11T13:24:33.981779Z","iopub.status.idle":"2024-01-11T13:24:33.992803Z","shell.execute_reply.started":"2024-01-11T13:24:33.981753Z","shell.execute_reply":"2024-01-11T13:24:33.990171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['speed'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:34.451967Z","iopub.execute_input":"2024-01-11T13:24:34.452398Z","iopub.status.idle":"2024-01-11T13:24:34.461103Z","shell.execute_reply.started":"2024-01-11T13:24:34.452366Z","shell.execute_reply":"2024-01-11T13:24:34.459305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['speed'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:34.504841Z","iopub.execute_input":"2024-01-11T13:24:34.505260Z","iopub.status.idle":"2024-01-11T13:24:34.517043Z","shell.execute_reply.started":"2024-01-11T13:24:34.505225Z","shell.execute_reply":"2024-01-11T13:24:34.515523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\ndata['speed_encoded'] = le.fit_transform(data['speed'])\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:34.575442Z","iopub.execute_input":"2024-01-11T13:24:34.575871Z","iopub.status.idle":"2024-01-11T13:24:34.614384Z","shell.execute_reply.started":"2024-01-11T13:24:34.575841Z","shell.execute_reply":"2024-01-11T13:24:34.613494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since we have emnoded the speed so we no linger need the original speed column so lets drop it.","metadata":{}},{"cell_type":"code","source":"data.drop('speed',axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:34.879735Z","iopub.execute_input":"2024-01-11T13:24:34.880143Z","iopub.status.idle":"2024-01-11T13:24:34.896080Z","shell.execute_reply.started":"2024-01-11T13:24:34.880112Z","shell.execute_reply":"2024-01-11T13:24:34.894771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['title'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:35.047338Z","iopub.execute_input":"2024-01-11T13:24:35.047817Z","iopub.status.idle":"2024-01-11T13:24:35.062468Z","shell.execute_reply.started":"2024-01-11T13:24:35.047782Z","shell.execute_reply":"2024-01-11T13:24:35.060691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since title column has 21375 unique entries which means it is unique to each and every entry so cant do much about it, it wont help us in classifying the birds so lets just drop it.","metadata":{}},{"cell_type":"code","source":"data.drop('title',axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:35.366180Z","iopub.execute_input":"2024-01-11T13:24:35.366566Z","iopub.status.idle":"2024-01-11T13:24:35.383197Z","shell.execute_reply.started":"2024-01-11T13:24:35.366535Z","shell.execute_reply":"2024-01-11T13:24:35.381227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['secondary_labels'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:35.539027Z","iopub.execute_input":"2024-01-11T13:24:35.539435Z","iopub.status.idle":"2024-01-11T13:24:35.553478Z","shell.execute_reply.started":"2024-01-11T13:24:35.539402Z","shell.execute_reply":"2024-01-11T13:24:35.551449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Same goes with the column secondary labels which are basically the nick names of the bird in different countries again the column is not much useful because of a large number of unique values so we just drop it.","metadata":{}},{"cell_type":"code","source":"data.drop('secondary_labels',axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:35.879177Z","iopub.execute_input":"2024-01-11T13:24:35.879626Z","iopub.status.idle":"2024-01-11T13:24:35.898462Z","shell.execute_reply.started":"2024-01-11T13:24:35.879560Z","shell.execute_reply":"2024-01-11T13:24:35.896264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bird_seen'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:36.003940Z","iopub.execute_input":"2024-01-11T13:24:36.004380Z","iopub.status.idle":"2024-01-11T13:24:36.015331Z","shell.execute_reply.started":"2024-01-11T13:24:36.004348Z","shell.execute_reply":"2024-01-11T13:24:36.014171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So in the columns Bird seen most of the birds were seen and a few entries are null we can replace the null entries with yes and then label encode the column.","metadata":{}},{"cell_type":"code","source":"data['bird_seen'].fillna('yes', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:36.353871Z","iopub.execute_input":"2024-01-11T13:24:36.354276Z","iopub.status.idle":"2024-01-11T13:24:36.361868Z","shell.execute_reply.started":"2024-01-11T13:24:36.354242Z","shell.execute_reply":"2024-01-11T13:24:36.360134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\ndata['bird_seen_encoded'] = le.fit_transform(data['bird_seen'])","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:36.568336Z","iopub.execute_input":"2024-01-11T13:24:36.568803Z","iopub.status.idle":"2024-01-11T13:24:36.579806Z","shell.execute_reply.started":"2024-01-11T13:24:36.568770Z","shell.execute_reply":"2024-01-11T13:24:36.578085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bird_seen_encoded'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:36.725801Z","iopub.execute_input":"2024-01-11T13:24:36.726210Z","iopub.status.idle":"2024-01-11T13:24:36.736319Z","shell.execute_reply.started":"2024-01-11T13:24:36.726177Z","shell.execute_reply":"2024-01-11T13:24:36.734769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After encoding we no longer need the original column so lets just drop it.","metadata":{}},{"cell_type":"code","source":"data.drop('bird_seen',axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:37.038366Z","iopub.execute_input":"2024-01-11T13:24:37.038820Z","iopub.status.idle":"2024-01-11T13:24:37.058051Z","shell.execute_reply.started":"2024-01-11T13:24:37.038783Z","shell.execute_reply":"2024-01-11T13:24:37.056763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Location column states very precisely where the bird is located , it may not be helpful to us in model training because of its preciseness but can be helpful to us if we create a map.","metadata":{}},{"cell_type":"code","source":"count_not_specified = (data['latitude'] == 'Not specified').sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:37.393383Z","iopub.execute_input":"2024-01-11T13:24:37.393827Z","iopub.status.idle":"2024-01-11T13:24:37.401416Z","shell.execute_reply.started":"2024-01-11T13:24:37.393795Z","shell.execute_reply":"2024-01-11T13:24:37.399564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_not_specified","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:37.574316Z","iopub.execute_input":"2024-01-11T13:24:37.574825Z","iopub.status.idle":"2024-01-11T13:24:37.584173Z","shell.execute_reply.started":"2024-01-11T13:24:37.574786Z","shell.execute_reply":"2024-01-11T13:24:37.582128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_not_specified_longitude = (data['longitude'] == 'Not specified').sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:37.765471Z","iopub.execute_input":"2024-01-11T13:24:37.765909Z","iopub.status.idle":"2024-01-11T13:24:37.772442Z","shell.execute_reply.started":"2024-01-11T13:24:37.765885Z","shell.execute_reply":"2024-01-11T13:24:37.771392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_not_specified_longitude","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:37.953704Z","iopub.execute_input":"2024-01-11T13:24:37.954113Z","iopub.status.idle":"2024-01-11T13:24:37.962552Z","shell.execute_reply.started":"2024-01-11T13:24:37.954082Z","shell.execute_reply":"2024-01-11T13:24:37.961305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since there are very small number of entries that have latitude and longitude not specified so we can consider dropping those rows.","metadata":{}},{"cell_type":"code","source":"data=data[data['latitude']!='Not specified']\ndata=data[data['longitude']!='Not specified']","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:38.347947Z","iopub.execute_input":"2024-01-11T13:24:38.348363Z","iopub.status.idle":"2024-01-11T13:24:38.384736Z","shell.execute_reply.started":"2024-01-11T13:24:38.348329Z","shell.execute_reply":"2024-01-11T13:24:38.383101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_not_specified_longitude1 = (data['longitude'] == 'Not specified').sum()\ncount_not_specified_longitude1","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:38.505109Z","iopub.execute_input":"2024-01-11T13:24:38.505511Z","iopub.status.idle":"2024-01-11T13:24:38.514817Z","shell.execute_reply.started":"2024-01-11T13:24:38.505476Z","shell.execute_reply":"2024-01-11T13:24:38.513675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_not_specified_latitude1 = (data['latitude'] == 'Not specified').sum()\ncount_not_specified_latitude1","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:38.711077Z","iopub.execute_input":"2024-01-11T13:24:38.711447Z","iopub.status.idle":"2024-01-11T13:24:38.722469Z","shell.execute_reply.started":"2024-01-11T13:24:38.711422Z","shell.execute_reply":"2024-01-11T13:24:38.721291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"But note that the data type for these two columns is not float so lets convert them to float.","metadata":{}},{"cell_type":"code","source":"data['latitude']=data['latitude'].astype(float)\ndata['longitude']=data['longitude'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:39.070079Z","iopub.execute_input":"2024-01-11T13:24:39.071096Z","iopub.status.idle":"2024-01-11T13:24:39.082218Z","shell.execute_reply.started":"2024-01-11T13:24:39.071060Z","shell.execute_reply":"2024-01-11T13:24:39.080543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['sampling_rate'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:39.243561Z","iopub.execute_input":"2024-01-11T13:24:39.243993Z","iopub.status.idle":"2024-01-11T13:24:39.257559Z","shell.execute_reply.started":"2024-01-11T13:24:39.243957Z","shell.execute_reply":"2024-01-11T13:24:39.255084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note the we are only interested in the numerical value so we will split this column based on space.","metadata":{}},{"cell_type":"code","source":"data['sampling_rate']=data['sampling_rate'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:39.621041Z","iopub.execute_input":"2024-01-11T13:24:39.621404Z","iopub.status.idle":"2024-01-11T13:24:39.636274Z","shell.execute_reply.started":"2024-01-11T13:24:39.621380Z","shell.execute_reply":"2024-01-11T13:24:39.634966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:39.797899Z","iopub.execute_input":"2024-01-11T13:24:39.798313Z","iopub.status.idle":"2024-01-11T13:24:39.811021Z","shell.execute_reply.started":"2024-01-11T13:24:39.798276Z","shell.execute_reply":"2024-01-11T13:24:39.808799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since the type column has large number of unique values we can safely ignore this column","metadata":{}},{"cell_type":"code","source":"data['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:40.155382Z","iopub.execute_input":"2024-01-11T13:24:40.157279Z","iopub.status.idle":"2024-01-11T13:24:40.169046Z","shell.execute_reply.started":"2024-01-11T13:24:40.157207Z","shell.execute_reply":"2024-01-11T13:24:40.167704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].replace(['? m', 'Unknown m', ' m'], '9999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:40.618306Z","iopub.execute_input":"2024-01-11T13:24:40.618743Z","iopub.status.idle":"2024-01-11T13:24:40.632876Z","shell.execute_reply.started":"2024-01-11T13:24:40.618710Z","shell.execute_reply":"2024-01-11T13:24:40.630822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace(',','')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:40.669498Z","iopub.execute_input":"2024-01-11T13:24:40.671086Z","iopub.status.idle":"2024-01-11T13:24:40.684556Z","shell.execute_reply.started":"2024-01-11T13:24:40.671041Z","shell.execute_reply":"2024-01-11T13:24:40.683133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('~','')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:40.725978Z","iopub.execute_input":"2024-01-11T13:24:40.726433Z","iopub.status.idle":"2024-01-11T13:24:40.741171Z","shell.execute_reply.started":"2024-01-11T13:24:40.726397Z","shell.execute_reply":"2024-01-11T13:24:40.739929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('.','')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:40.919554Z","iopub.execute_input":"2024-01-11T13:24:40.919997Z","iopub.status.idle":"2024-01-11T13:24:40.934947Z","shell.execute_reply.started":"2024-01-11T13:24:40.919962Z","shell.execute_reply":"2024-01-11T13:24:40.933647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('?? m','9999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:41.102020Z","iopub.execute_input":"2024-01-11T13:24:41.102492Z","iopub.status.idle":"2024-01-11T13:24:41.118017Z","shell.execute_reply.started":"2024-01-11T13:24:41.102458Z","shell.execute_reply":"2024-01-11T13:24:41.116041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('1650-1900 m','1775')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:41.307908Z","iopub.execute_input":"2024-01-11T13:24:41.308281Z","iopub.status.idle":"2024-01-11T13:24:41.323124Z","shell.execute_reply.started":"2024-01-11T13:24:41.308249Z","shell.execute_reply":"2024-01-11T13:24:41.321307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('- m','9999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:41.503035Z","iopub.execute_input":"2024-01-11T13:24:41.503454Z","iopub.status.idle":"2024-01-11T13:24:41.518108Z","shell.execute_reply.started":"2024-01-11T13:24:41.503424Z","shell.execute_reply":"2024-01-11T13:24:41.515804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('930-990 m','9999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:41.683186Z","iopub.execute_input":"2024-01-11T13:24:41.683610Z","iopub.status.idle":"2024-01-11T13:24:41.695182Z","shell.execute_reply.started":"2024-01-11T13:24:41.683559Z","shell.execute_reply":"2024-01-11T13:24:41.694409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('1400m','1400')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:41.877874Z","iopub.execute_input":"2024-01-11T13:24:41.878283Z","iopub.status.idle":"2024-01-11T13:24:41.893670Z","shell.execute_reply.started":"2024-01-11T13:24:41.878251Z","shell.execute_reply":"2024-01-11T13:24:41.891886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].str.replace('1900m','1900')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.078759Z","iopub.execute_input":"2024-01-11T13:24:42.079186Z","iopub.status.idle":"2024-01-11T13:24:42.093398Z","shell.execute_reply.started":"2024-01-11T13:24:42.079153Z","shell.execute_reply":"2024-01-11T13:24:42.091561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].apply(lambda x: x.split(\" \")[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.290270Z","iopub.execute_input":"2024-01-11T13:24:42.290754Z","iopub.status.idle":"2024-01-11T13:24:42.307547Z","shell.execute_reply.started":"2024-01-11T13:24:42.290718Z","shell.execute_reply":"2024-01-11T13:24:42.305053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.424192Z","iopub.execute_input":"2024-01-11T13:24:42.425369Z","iopub.status.idle":"2024-01-11T13:24:42.435327Z","shell.execute_reply.started":"2024-01-11T13:24:42.425305Z","shell.execute_reply":"2024-01-11T13:24:42.433726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'] = data['elevation'].abs()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.683332Z","iopub.execute_input":"2024-01-11T13:24:42.683795Z","iopub.status.idle":"2024-01-11T13:24:42.690135Z","shell.execute_reply.started":"2024-01-11T13:24:42.683762Z","shell.execute_reply":"2024-01-11T13:24:42.689006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.832673Z","iopub.execute_input":"2024-01-11T13:24:42.833732Z","iopub.status.idle":"2024-01-11T13:24:42.845221Z","shell.execute_reply.started":"2024-01-11T13:24:42.833694Z","shell.execute_reply":"2024-01-11T13:24:42.844150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=pd.to_numeric(data['elevation'],errors='coerce')\nsum_elevation=0\ncount_valid_values=0\n\nfor index,row in data.iterrows():\n    if row['elevation']!=9999:\n        sum_elevation+=row['elevation']\n        count_valid_values+=1\nmean_elevation =sum_elevation/count_valid_values\nmean_elevation","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:42.998809Z","iopub.execute_input":"2024-01-11T13:24:42.999197Z","iopub.status.idle":"2024-01-11T13:24:44.198395Z","shell.execute_reply.started":"2024-01-11T13:24:42.999166Z","shell.execute_reply":"2024-01-11T13:24:44.196400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation']=data['elevation'].replace(['9999'],667)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.201251Z","iopub.execute_input":"2024-01-11T13:24:44.201636Z","iopub.status.idle":"2024-01-11T13:24:44.209093Z","shell.execute_reply.started":"2024-01-11T13:24:44.201585Z","shell.execute_reply":"2024-01-11T13:24:44.206766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.211053Z","iopub.execute_input":"2024-01-11T13:24:44.211476Z","iopub.status.idle":"2024-01-11T13:24:44.224924Z","shell.execute_reply.started":"2024-01-11T13:24:44.211441Z","shell.execute_reply":"2024-01-11T13:24:44.222977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The column description contains the url of the audios source so it is not useful we may drop it","metadata":{}},{"cell_type":"code","source":"data.drop(\"description\" , axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.227827Z","iopub.execute_input":"2024-01-11T13:24:44.228232Z","iopub.status.idle":"2024-01-11T13:24:44.243879Z","shell.execute_reply.started":"2024-01-11T13:24:44.228195Z","shell.execute_reply":"2024-01-11T13:24:44.241815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.245792Z","iopub.execute_input":"2024-01-11T13:24:44.246217Z","iopub.status.idle":"2024-01-11T13:24:44.256203Z","shell.execute_reply.started":"2024-01-11T13:24:44.246185Z","shell.execute_reply":"2024-01-11T13:24:44.254820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.257586Z","iopub.execute_input":"2024-01-11T13:24:44.258256Z","iopub.status.idle":"2024-01-11T13:24:44.276676Z","shell.execute_reply.started":"2024-01-11T13:24:44.258221Z","shell.execute_reply":"2024-01-11T13:24:44.274473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"You can clearly see that the number of samples having a bitrate 128000 is fairly large as compared to the second highest bitrate 320000 so we can replace the null values with a bitrate of 128000.","metadata":{}},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.578367Z","iopub.execute_input":"2024-01-11T13:24:44.578813Z","iopub.status.idle":"2024-01-11T13:24:44.612901Z","shell.execute_reply.started":"2024-01-11T13:24:44.578780Z","shell.execute_reply":"2024-01-11T13:24:44.611929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.816975Z","iopub.execute_input":"2024-01-11T13:24:44.817402Z","iopub.status.idle":"2024-01-11T13:24:44.826392Z","shell.execute_reply.started":"2024-01-11T13:24:44.817367Z","shell.execute_reply":"2024-01-11T13:24:44.825012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].fillna('128000', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:44.977388Z","iopub.execute_input":"2024-01-11T13:24:44.977955Z","iopub.status.idle":"2024-01-11T13:24:44.985003Z","shell.execute_reply.started":"2024-01-11T13:24:44.977919Z","shell.execute_reply":"2024-01-11T13:24:44.983696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now since we just need the nukmber we can split the column based on space","metadata":{}},{"cell_type":"code","source":"data['bitrate_of_mp3']=data['bitrate_of_mp3'].apply(lambda x: x.split(\" \")[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:45.404734Z","iopub.execute_input":"2024-01-11T13:24:45.405458Z","iopub.status.idle":"2024-01-11T13:24:45.424048Z","shell.execute_reply.started":"2024-01-11T13:24:45.405419Z","shell.execute_reply":"2024-01-11T13:24:45.421473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['bitrate_of_mp3'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:45.616242Z","iopub.execute_input":"2024-01-11T13:24:45.616697Z","iopub.status.idle":"2024-01-11T13:24:45.627672Z","shell.execute_reply.started":"2024-01-11T13:24:45.616662Z","shell.execute_reply":"2024-01-11T13:24:45.626327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:45.797896Z","iopub.execute_input":"2024-01-11T13:24:45.798549Z","iopub.status.idle":"2024-01-11T13:24:45.825333Z","shell.execute_reply.started":"2024-01-11T13:24:45.798515Z","shell.execute_reply":"2024-01-11T13:24:45.823623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['file_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:46.172634Z","iopub.execute_input":"2024-01-11T13:24:46.173015Z","iopub.status.idle":"2024-01-11T13:24:46.185369Z","shell.execute_reply.started":"2024-01-11T13:24:46.172984Z","shell.execute_reply":"2024-01-11T13:24:46.183844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since there are very few wav ,mp2,aac files we may drop them","metadata":{}},{"cell_type":"code","source":"data = data[data['file_type'] != 'wav']\ndata = data[data['file_type'] != 'mp2']\ndata = data[data['file_type'] != 'aac']\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:46.453803Z","iopub.execute_input":"2024-01-11T13:24:46.454185Z","iopub.status.idle":"2024-01-11T13:24:46.491770Z","shell.execute_reply.started":"2024-01-11T13:24:46.454155Z","shell.execute_reply":"2024-01-11T13:24:46.490160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"now since all the files are mp3 we can drop the column file_type","metadata":{}},{"cell_type":"code","source":"data.drop('file_type', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:46.805252Z","iopub.execute_input":"2024-01-11T13:24:46.805671Z","iopub.status.idle":"2024-01-11T13:24:46.818159Z","shell.execute_reply.started":"2024-01-11T13:24:46.805635Z","shell.execute_reply":"2024-01-11T13:24:46.816711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['volume'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:47.020900Z","iopub.execute_input":"2024-01-11T13:24:47.021396Z","iopub.status.idle":"2024-01-11T13:24:47.034547Z","shell.execute_reply.started":"2024-01-11T13:24:47.021338Z","shell.execute_reply":"2024-01-11T13:24:47.033129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can encode the column volumn","metadata":{}},{"cell_type":"code","source":"le=LabelEncoder()\ndata['volume_encoded'] = le.fit_transform(data['volume'])\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:47.405420Z","iopub.execute_input":"2024-01-11T13:24:47.405870Z","iopub.status.idle":"2024-01-11T13:24:47.417737Z","shell.execute_reply.started":"2024-01-11T13:24:47.405837Z","shell.execute_reply":"2024-01-11T13:24:47.415903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:47.596317Z","iopub.execute_input":"2024-01-11T13:24:47.596933Z","iopub.status.idle":"2024-01-11T13:24:47.624972Z","shell.execute_reply.started":"2024-01-11T13:24:47.596907Z","shell.execute_reply":"2024-01-11T13:24:47.623213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop('volume', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:47.776579Z","iopub.execute_input":"2024-01-11T13:24:47.777061Z","iopub.status.idle":"2024-01-11T13:24:47.788160Z","shell.execute_reply.started":"2024-01-11T13:24:47.777024Z","shell.execute_reply":"2024-01-11T13:24:47.787056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[\"background\"].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:48.000868Z","iopub.execute_input":"2024-01-11T13:24:48.001303Z","iopub.status.idle":"2024-01-11T13:24:48.009691Z","shell.execute_reply.started":"2024-01-11T13:24:48.001268Z","shell.execute_reply":"2024-01-11T13:24:48.008856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"since most of the values in the column background are null we can simply drop the column","metadata":{}},{"cell_type":"code","source":"data.drop('background', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:48.447782Z","iopub.execute_input":"2024-01-11T13:24:48.448161Z","iopub.status.idle":"2024-01-11T13:24:48.460341Z","shell.execute_reply.started":"2024-01-11T13:24:48.448128Z","shell.execute_reply":"2024-01-11T13:24:48.458781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['xc_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:48.567767Z","iopub.execute_input":"2024-01-11T13:24:48.568170Z","iopub.status.idle":"2024-01-11T13:24:48.575189Z","shell.execute_reply.started":"2024-01-11T13:24:48.568144Z","shell.execute_reply":"2024-01-11T13:24:48.573831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['url'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:48.763955Z","iopub.execute_input":"2024-01-11T13:24:48.764472Z","iopub.status.idle":"2024-01-11T13:24:48.777036Z","shell.execute_reply.started":"2024-01-11T13:24:48.764432Z","shell.execute_reply":"2024-01-11T13:24:48.775803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"xc_id column gives unique value for each sample audio, so we can consider dropping it, same goes with the column url.","metadata":{}},{"cell_type":"code","source":"data.drop('xc_id', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:49.131821Z","iopub.execute_input":"2024-01-11T13:24:49.132237Z","iopub.status.idle":"2024-01-11T13:24:49.145889Z","shell.execute_reply.started":"2024-01-11T13:24:49.132205Z","shell.execute_reply":"2024-01-11T13:24:49.144374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop('url', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:49.359873Z","iopub.execute_input":"2024-01-11T13:24:49.360259Z","iopub.status.idle":"2024-01-11T13:24:49.372839Z","shell.execute_reply.started":"2024-01-11T13:24:49.360228Z","shell.execute_reply":"2024-01-11T13:24:49.370469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['country'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:49.515486Z","iopub.execute_input":"2024-01-11T13:24:49.516841Z","iopub.status.idle":"2024-01-11T13:24:49.527382Z","shell.execute_reply.started":"2024-01-11T13:24:49.516803Z","shell.execute_reply":"2024-01-11T13:24:49.525699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['country'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:49.748408Z","iopub.execute_input":"2024-01-11T13:24:49.748939Z","iopub.status.idle":"2024-01-11T13:24:49.759871Z","shell.execute_reply.started":"2024-01-11T13:24:49.748905Z","shell.execute_reply":"2024-01-11T13:24:49.757897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Countries column can help us identify the bird since there can be birds which are region specific(found in specific countries only) so we should do a label encoding of countries so that we can use this in out model.","metadata":{}},{"cell_type":"code","source":"le=LabelEncoder()\ndata['country_encoded'] = le.fit_transform(data['country'])","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:50.113455Z","iopub.execute_input":"2024-01-11T13:24:50.113892Z","iopub.status.idle":"2024-01-11T13:24:50.126429Z","shell.execute_reply.started":"2024-01-11T13:24:50.113862Z","shell.execute_reply":"2024-01-11T13:24:50.124285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['author'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:50.257352Z","iopub.execute_input":"2024-01-11T13:24:50.257777Z","iopub.status.idle":"2024-01-11T13:24:50.267696Z","shell.execute_reply.started":"2024-01-11T13:24:50.257745Z","shell.execute_reply":"2024-01-11T13:24:50.265742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['recordist'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:50.507498Z","iopub.execute_input":"2024-01-11T13:24:50.507974Z","iopub.status.idle":"2024-01-11T13:24:50.518203Z","shell.execute_reply.started":"2024-01-11T13:24:50.507937Z","shell.execute_reply":"2024-01-11T13:24:50.516333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['author']!=data['recordist']]","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:50.665019Z","iopub.execute_input":"2024-01-11T13:24:50.666384Z","iopub.status.idle":"2024-01-11T13:24:50.687187Z","shell.execute_reply.started":"2024-01-11T13:24:50.666340Z","shell.execute_reply":"2024-01-11T13:24:50.685064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we can see that all the rows have author= recordist so we can drop any one of them","metadata":{}},{"cell_type":"code","source":"data.drop('author', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:51.070287Z","iopub.execute_input":"2024-01-11T13:24:51.070712Z","iopub.status.idle":"2024-01-11T13:24:51.081940Z","shell.execute_reply.started":"2024-01-11T13:24:51.070687Z","shell.execute_reply":"2024-01-11T13:24:51.080741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['primary_label'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:51.223347Z","iopub.execute_input":"2024-01-11T13:24:51.223783Z","iopub.status.idle":"2024-01-11T13:24:51.240498Z","shell.execute_reply.started":"2024-01-11T13:24:51.223751Z","shell.execute_reply":"2024-01-11T13:24:51.239380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are a lot of unique values in the primary labels we cant do anything in this column so we can simply drop it","metadata":{}},{"cell_type":"code","source":"data.drop('primary_label', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:51.705731Z","iopub.execute_input":"2024-01-11T13:24:51.706104Z","iopub.status.idle":"2024-01-11T13:24:51.718453Z","shell.execute_reply.started":"2024-01-11T13:24:51.706076Z","shell.execute_reply":"2024-01-11T13:24:51.717223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:51.919027Z","iopub.execute_input":"2024-01-11T13:24:51.919441Z","iopub.status.idle":"2024-01-11T13:24:51.930327Z","shell.execute_reply.started":"2024-01-11T13:24:51.919408Z","shell.execute_reply":"2024-01-11T13:24:51.928704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['length'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:52.074718Z","iopub.execute_input":"2024-01-11T13:24:52.075165Z","iopub.status.idle":"2024-01-11T13:24:52.086424Z","shell.execute_reply.started":"2024-01-11T13:24:52.075130Z","shell.execute_reply":"2024-01-11T13:24:52.085320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['min_value']=data['length'].str.extract(r'(\\d+)')\ndata['min_value']= pd.to_numeric(data['min_value'],errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:52.215948Z","iopub.execute_input":"2024-01-11T13:24:52.216410Z","iopub.status.idle":"2024-01-11T13:24:52.254332Z","shell.execute_reply.started":"2024-01-11T13:24:52.216375Z","shell.execute_reply":"2024-01-11T13:24:52.252304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['max_value']=data['length'].str.extract(r'-(\\d+)')\ndata['max_value']= pd.to_numeric(data['max_value'],errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:53.714397Z","iopub.execute_input":"2024-01-11T13:24:53.714951Z","iopub.status.idle":"2024-01-11T13:24:53.748707Z","shell.execute_reply.started":"2024-01-11T13:24:53.714911Z","shell.execute_reply":"2024-01-11T13:24:53.747453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:53.874941Z","iopub.execute_input":"2024-01-11T13:24:53.875763Z","iopub.status.idle":"2024-01-11T13:24:53.902458Z","shell.execute_reply.started":"2024-01-11T13:24:53.875723Z","shell.execute_reply":"2024-01-11T13:24:53.901058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['min_value'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:54.035216Z","iopub.execute_input":"2024-01-11T13:24:54.036129Z","iopub.status.idle":"2024-01-11T13:24:54.046629Z","shell.execute_reply.started":"2024-01-11T13:24:54.036094Z","shell.execute_reply":"2024-01-11T13:24:54.044576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['max_value'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:54.217534Z","iopub.execute_input":"2024-01-11T13:24:54.220043Z","iopub.status.idle":"2024-01-11T13:24:54.232352Z","shell.execute_reply.started":"2024-01-11T13:24:54.219889Z","shell.execute_reply":"2024-01-11T13:24:54.230507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note that more than 14000 samples would have null values in these above columns of length which we have added so i dont think we should use this feature since we neither can replace 14000+ entries with some mean or anything nor we can drop them, so i prefer to drop the length column","metadata":{}},{"cell_type":"code","source":"data.drop('length', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:54.578132Z","iopub.execute_input":"2024-01-11T13:24:54.578898Z","iopub.status.idle":"2024-01-11T13:24:54.590605Z","shell.execute_reply.started":"2024-01-11T13:24:54.578861Z","shell.execute_reply":"2024-01-11T13:24:54.588700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop('min_value', axis=1, inplace=True)\ndata.drop('max_value', axis=1, inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:54.718009Z","iopub.execute_input":"2024-01-11T13:24:54.718398Z","iopub.status.idle":"2024-01-11T13:24:54.737895Z","shell.execute_reply.started":"2024-01-11T13:24:54.718368Z","shell.execute_reply":"2024-01-11T13:24:54.736255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['time'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:54.876710Z","iopub.execute_input":"2024-01-11T13:24:54.877068Z","iopub.status.idle":"2024-01-11T13:24:54.884692Z","shell.execute_reply.started":"2024-01-11T13:24:54.877044Z","shell.execute_reply":"2024-01-11T13:24:54.883757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['time'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:55.042012Z","iopub.execute_input":"2024-01-11T13:24:55.042488Z","iopub.status.idle":"2024-01-11T13:24:55.053062Z","shell.execute_reply.started":"2024-01-11T13:24:55.042446Z","shell.execute_reply":"2024-01-11T13:24:55.051492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are a lot of unique values in time i would like to drop this column","metadata":{}},{"cell_type":"code","source":"data.drop('time', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:55.360298Z","iopub.execute_input":"2024-01-11T13:24:55.360685Z","iopub.status.idle":"2024-01-11T13:24:55.371322Z","shell.execute_reply.started":"2024-01-11T13:24:55.360659Z","shell.execute_reply":"2024-01-11T13:24:55.369810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['license'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:55.545128Z","iopub.execute_input":"2024-01-11T13:24:55.545552Z","iopub.status.idle":"2024-01-11T13:24:55.557817Z","shell.execute_reply.started":"2024-01-11T13:24:55.545519Z","shell.execute_reply":"2024-01-11T13:24:55.556330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['license'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:55.712126Z","iopub.execute_input":"2024-01-11T13:24:55.712572Z","iopub.status.idle":"2024-01-11T13:24:55.722538Z","shell.execute_reply.started":"2024-01-11T13:24:55.712537Z","shell.execute_reply":"2024-01-11T13:24:55.720326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Licence column has only 4 categories and no null values so we can label encode it","metadata":{}},{"cell_type":"code","source":"le=LabelEncoder()\ndata['license_encoded'] = le.fit_transform(data['license'])\nencoded_unique_values= data['license_encoded'].unique()\nlabel_mapping =dict(zip(data['license'],data['license_encoded']))\n\nprint(\"label encoded unique values:\", encoded_unique_values)\nprint(\"Label Mapping\", label_mapping)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.140827Z","iopub.execute_input":"2024-01-11T13:24:56.141224Z","iopub.status.idle":"2024-01-11T13:24:56.159160Z","shell.execute_reply.started":"2024-01-11T13:24:56.141199Z","shell.execute_reply":"2024-01-11T13:24:56.158142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop('license', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.250071Z","iopub.execute_input":"2024-01-11T13:24:56.250524Z","iopub.status.idle":"2024-01-11T13:24:56.263750Z","shell.execute_reply.started":"2024-01-11T13:24:56.250491Z","shell.execute_reply":"2024-01-11T13:24:56.262282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.435371Z","iopub.execute_input":"2024-01-11T13:24:56.435840Z","iopub.status.idle":"2024-01-11T13:24:56.460805Z","shell.execute_reply.started":"2024-01-11T13:24:56.435802Z","shell.execute_reply":"2024-01-11T13:24:56.459551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.634059Z","iopub.execute_input":"2024-01-11T13:24:56.634542Z","iopub.status.idle":"2024-01-11T13:24:56.658323Z","shell.execute_reply.started":"2024-01-11T13:24:56.634488Z","shell.execute_reply":"2024-01-11T13:24:56.657603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.802013Z","iopub.execute_input":"2024-01-11T13:24:56.802443Z","iopub.status.idle":"2024-01-11T13:24:56.812457Z","shell.execute_reply.started":"2024-01-11T13:24:56.802411Z","shell.execute_reply":"2024-01-11T13:24:56.811413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:56.994640Z","iopub.execute_input":"2024-01-11T13:24:56.996309Z","iopub.status.idle":"2024-01-11T13:24:57.005756Z","shell.execute_reply.started":"2024-01-11T13:24:56.996247Z","shell.execute_reply":"2024-01-11T13:24:57.004463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This column has a lot of unique values so we can ignore it.","metadata":{}},{"cell_type":"code","source":"data.drop('type', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:57.383780Z","iopub.execute_input":"2024-01-11T13:24:57.384323Z","iopub.status.idle":"2024-01-11T13:24:57.393893Z","shell.execute_reply.started":"2024-01-11T13:24:57.384297Z","shell.execute_reply":"2024-01-11T13:24:57.392002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['number_of_notes'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:57.588905Z","iopub.execute_input":"2024-01-11T13:24:57.589308Z","iopub.status.idle":"2024-01-11T13:24:57.598877Z","shell.execute_reply.started":"2024-01-11T13:24:57.589278Z","shell.execute_reply":"2024-01-11T13:24:57.597066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['number_of_notes'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:57.766124Z","iopub.execute_input":"2024-01-11T13:24:57.766498Z","iopub.status.idle":"2024-01-11T13:24:57.777447Z","shell.execute_reply.started":"2024-01-11T13:24:57.766474Z","shell.execute_reply":"2024-01-11T13:24:57.775129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since this column \"number_of_notes\" has more than 14k+ Non specified entries so we cann neither fill them with some sort of mean or anything else nor we can drop these so many rows so i prefer to drop this column","metadata":{}},{"cell_type":"code","source":"data.drop('number_of_notes', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:58.121262Z","iopub.execute_input":"2024-01-11T13:24:58.122866Z","iopub.status.idle":"2024-01-11T13:24:58.135116Z","shell.execute_reply.started":"2024-01-11T13:24:58.122806Z","shell.execute_reply":"2024-01-11T13:24:58.133090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.to_csv('/kaggle/working/output_file.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:58.307980Z","iopub.execute_input":"2024-01-11T13:24:58.308416Z","iopub.status.idle":"2024-01-11T13:24:58.479187Z","shell.execute_reply.started":"2024-01-11T13:24:58.308383Z","shell.execute_reply":"2024-01-11T13:24:58.477725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='month', data=data)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:58.500717Z","iopub.execute_input":"2024-01-11T13:24:58.501111Z","iopub.status.idle":"2024-01-11T13:24:58.820897Z","shell.execute_reply.started":"2024-01-11T13:24:58.501080Z","shell.execute_reply":"2024-01-11T13:24:58.819643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see that most of the Bird Recordigs are taken arond the months of may and june","metadata":{}},{"cell_type":"code","source":"\ntop_countries = data.groupby('country').size().sort_values(ascending=False).head(10)\n\nplt.pie(top_countries, labels=None, autopct=None, startangle=90, colors=sns.color_palette('viridis'))\n\nplt.legend(labels=top_countries.index + ' (' + top_countries.map(lambda x: f'{x/sum(top_countries)*100:.1f}%') + ')', loc='upper left', bbox_to_anchor=(1, 1))\n\nplt.title('Top 10 Countries with Highest Records')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:58.973041Z","iopub.execute_input":"2024-01-11T13:24:58.973424Z","iopub.status.idle":"2024-01-11T13:24:59.195338Z","shell.execute_reply.started":"2024-01-11T13:24:58.973392Z","shell.execute_reply":"2024-01-11T13:24:59.194480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can clearly see that most of the records are of birds from USA","metadata":{}},{"cell_type":"markdown","source":"We can clearly see that most of the records are of birds from USA","metadata":{}},{"cell_type":"code","source":"sns.set_theme(style='whitegrid')\n\n# Assuming 'latitude' is the column you want to plot\nplt.figure(figsize=(10, 6))\n\n# Create the histogram with a filled color\nsns.histplot(data['latitude'], bins=20, kde=False, color='#3498db', edgecolor='#2980b9', linewidth=0.5)\n\n# Adding labels and title with a touch of style\nplt.xlabel('Latitude', fontsize=14, labelpad=10, color='#34495e')\nplt.ylabel('Frequency', fontsize=14, labelpad=10, color='#34495e')\nplt.title('Histogram of Latitude', fontsize=16, pad=20, fontweight='bold', color='#34495e')\n\n# Set background color\nplt.gca().set_facecolor('#ecf0f1')\n\n# Adding grid lines for better readability\nplt.grid(axis='y', linestyle='--', alpha=0.7)\n\n# Removing the top and right spines for aesthetics\nsns.despine()\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:59.460437Z","iopub.execute_input":"2024-01-11T13:24:59.461365Z","iopub.status.idle":"2024-01-11T13:24:59.790618Z","shell.execute_reply.started":"2024-01-11T13:24:59.461328Z","shell.execute_reply":"2024-01-11T13:24:59.788567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This Plot suggests that most of the birds are Concentrated in the 30-60 degrees latitude region","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\n\n\nsns.scatterplot(x='longitude', y='latitude', data=data, color='#3498db', alpha=0.7, edgecolor='black',s=15)\n\n\nplt.xlabel('Longitude', fontsize=14, labelpad=10, color='#34495e')\nplt.ylabel('Latitude', fontsize=14, labelpad=10, color='#34495e')\nplt.title('Scatter Plot: Latitude vs Longitude', fontsize=16, pad=20, fontweight='bold', color='#34495e')\n\n\nplt.gca().set_facecolor('#ecf0f1')\n\nplt.grid(axis='both', linestyle='--', alpha=0.7)\n\nsns.despine()\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:24:59.792523Z","iopub.execute_input":"2024-01-11T13:24:59.792889Z","iopub.status.idle":"2024-01-11T13:25:00.115987Z","shell.execute_reply.started":"2024-01-11T13:24:59.792859Z","shell.execute_reply":"2024-01-11T13:25:00.113658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The above plot Clearly suggest that United States has best Ecological Balance ","metadata":{}},{"cell_type":"code","source":"# Now lets do some feature extraction ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:00.176317Z","iopub.execute_input":"2024-01-11T13:25:00.176760Z","iopub.status.idle":"2024-01-11T13:25:00.182399Z","shell.execute_reply.started":"2024-01-11T13:25:00.176728Z","shell.execute_reply":"2024-01-11T13:25:00.181192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport librosa.display\nimport soundfile as sf\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:00.340754Z","iopub.execute_input":"2024-01-11T13:25:00.341208Z","iopub.status.idle":"2024-01-11T13:25:00.347105Z","shell.execute_reply.started":"2024-01-11T13:25:00.341174Z","shell.execute_reply":"2024-01-11T13:25:00.346007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amecro1=\"/kaggle/input/bird-voice/bird_voices/XC114551.mp3\"\namecro2=\"/kaggle/input/bird-voice/bird_voices/XC114552.mp3\"\ncoohaw1=\"/kaggle/input/bird-voice/bird_voices/XC123581.mp3\"\ncoohaw2=\"/kaggle/input/bird-voice/bird_voices/XC123582.mp3\"\nmerlin1=\"/kaggle/input/bird-voice/bird_voices/XC145140.mp3\"\nmerlin2=\"/kaggle/input/bird-voice/bird_voices/XC137975.mp3\"\nveery1=\"/kaggle/input/bird-voice/bird_voices/XC142682.mp3\"\nveery2=\"/kaggle/input/bird-voice/bird_voices/XC120869.mp3\"\naldfly1=\"/kaggle/input/bird-voice/bird_voices/XC137570.mp3\"\naldfly2=\"/kaggle/input/bird-voice/bird_voices/XC142068.mp3\"\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:00.517340Z","iopub.execute_input":"2024-01-11T13:25:00.517844Z","iopub.status.idle":"2024-01-11T13:25:00.525517Z","shell.execute_reply.started":"2024-01-11T13:25:00.517811Z","shell.execute_reply":"2024-01-11T13:25:00.523867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amecro1_audio, sr1 = librosa.load(amecro1)\namecro2_audio, sr2 = librosa.load(amecro2)\ncoohaw1_audio, sr3 = librosa.load(coohaw1)\ncoohaw2_audio, sr4 = librosa.load(coohaw2)\nmerlin1_audio, sr5 = librosa.load(merlin1)\nmerlin2_audio, sr6 = librosa.load(merlin2)\n\nveery1_audio, sr7 = librosa.load(veery1)\nveery2_audio, sr8 = librosa.load(veery2)\naldfly1_audio, sr9 = librosa.load(aldfly1)\naldfly2_audio, sr10 = librosa.load(aldfly2)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:00.701521Z","iopub.execute_input":"2024-01-11T13:25:00.701911Z","iopub.status.idle":"2024-01-11T13:25:01.099059Z","shell.execute_reply.started":"2024-01-11T13:25:00.701888Z","shell.execute_reply":"2024-01-11T13:25:01.096457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"lets find the zero crossing rates and we will compare them afterwards:","metadata":{}},{"cell_type":"code","source":"amecro_zcr1= librosa.feature.zero_crossing_rate(amecro1_audio)\namecro_zcr2=librosa.feature.zero_crossing_rate(amecro2_audio)\ncoohaw_zcr1=librosa.feature.zero_crossing_rate(coohaw1_audio)\ncoohaw_zcr2=librosa.feature.zero_crossing_rate(coohaw2_audio)\nmerlin_zcr1=librosa.feature.zero_crossing_rate(merlin1_audio)\nmerlin_zcr2=librosa.feature.zero_crossing_rate(merlin2_audio)\nveery_zcr1=librosa.feature.zero_crossing_rate(veery1_audio)\nveery_zcr2=librosa.feature.zero_crossing_rate(veery2_audio)\naldfly_zcr1=librosa.feature.zero_crossing_rate(aldfly1_audio)\naldfly_zcr2=librosa.feature.zero_crossing_rate(aldfly2_audio)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:01.101893Z","iopub.execute_input":"2024-01-11T13:25:01.102414Z","iopub.status.idle":"2024-01-11T13:25:01.197097Z","shell.execute_reply.started":"2024-01-11T13:25:01.102370Z","shell.execute_reply":"2024-01-11T13:25:01.195051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amecro_energy1=librosa.feature.rms(y=amecro1_audio)\namecro_energy2=librosa.feature.rms(y=amecro2_audio)\ncoohaw_energy1=librosa.feature.rms(y=coohaw1_audio)\ncoohaw_energy2=librosa.feature.rms(y=coohaw2_audio)\nmerlin_energy1=librosa.feature.rms(y=merlin1_audio)\nmerlin_energy2=librosa.feature.rms(y=merlin2_audio)\nveery_energy1=librosa.feature.rms(y=veery1_audio)\nveery_energy2=librosa.feature.rms(y=veery2_audio)\naldfly_energy1=librosa.feature.rms(y=aldfly1_audio)\naldfly_energy2=librosa.feature.rms(y=aldfly2_audio)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:01.244695Z","iopub.execute_input":"2024-01-11T13:25:01.245149Z","iopub.status.idle":"2024-01-11T13:25:01.465568Z","shell.execute_reply.started":"2024-01-11T13:25:01.245114Z","shell.execute_reply":"2024-01-11T13:25:01.464408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lets find the minimum and maximum frequency of these audios\n\nD = librosa.amplitude_to_db(np.abs(librosa.stft(amecro1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr1)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:01.468353Z","iopub.execute_input":"2024-01-11T13:25:01.468738Z","iopub.status.idle":"2024-01-11T13:25:01.489669Z","shell.execute_reply.started":"2024-01-11T13:25:01.468711Z","shell.execute_reply":"2024-01-11T13:25:01.488684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(amecro2_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr2)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:01.629830Z","iopub.execute_input":"2024-01-11T13:25:01.630210Z","iopub.status.idle":"2024-01-11T13:25:01.660432Z","shell.execute_reply.started":"2024-01-11T13:25:01.630182Z","shell.execute_reply":"2024-01-11T13:25:01.658488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(coohaw1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr3)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:01.859628Z","iopub.execute_input":"2024-01-11T13:25:01.860091Z","iopub.status.idle":"2024-01-11T13:25:01.903178Z","shell.execute_reply.started":"2024-01-11T13:25:01.860057Z","shell.execute_reply":"2024-01-11T13:25:01.901270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(coohaw2_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr4)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:02.091530Z","iopub.execute_input":"2024-01-11T13:25:02.092770Z","iopub.status.idle":"2024-01-11T13:25:02.125484Z","shell.execute_reply.started":"2024-01-11T13:25:02.092728Z","shell.execute_reply":"2024-01-11T13:25:02.123689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(merlin1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr5)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:02.221460Z","iopub.execute_input":"2024-01-11T13:25:02.221884Z","iopub.status.idle":"2024-01-11T13:25:02.254394Z","shell.execute_reply.started":"2024-01-11T13:25:02.221852Z","shell.execute_reply":"2024-01-11T13:25:02.253103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(merlin2_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr6)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:02.423210Z","iopub.execute_input":"2024-01-11T13:25:02.423571Z","iopub.status.idle":"2024-01-11T13:25:02.458793Z","shell.execute_reply.started":"2024-01-11T13:25:02.423548Z","shell.execute_reply":"2024-01-11T13:25:02.456674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(veery1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr7)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:02.605278Z","iopub.execute_input":"2024-01-11T13:25:02.605676Z","iopub.status.idle":"2024-01-11T13:25:02.635767Z","shell.execute_reply.started":"2024-01-11T13:25:02.605646Z","shell.execute_reply":"2024-01-11T13:25:02.633618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(veery2_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr8)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:02.820472Z","iopub.execute_input":"2024-01-11T13:25:02.820987Z","iopub.status.idle":"2024-01-11T13:25:02.881634Z","shell.execute_reply.started":"2024-01-11T13:25:02.820948Z","shell.execute_reply":"2024-01-11T13:25:02.878765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(aldfly1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr9)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:03.023738Z","iopub.execute_input":"2024-01-11T13:25:03.025577Z","iopub.status.idle":"2024-01-11T13:25:03.065565Z","shell.execute_reply.started":"2024-01-11T13:25:03.025519Z","shell.execute_reply":"2024-01-11T13:25:03.064469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(aldfly1_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr9)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:03.215960Z","iopub.execute_input":"2024-01-11T13:25:03.216710Z","iopub.status.idle":"2024-01-11T13:25:03.254373Z","shell.execute_reply.started":"2024-01-11T13:25:03.216672Z","shell.execute_reply":"2024-01-11T13:25:03.252971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(aldfly2_audio)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr10)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:03.399505Z","iopub.execute_input":"2024-01-11T13:25:03.399967Z","iopub.status.idle":"2024-01-11T13:25:03.426403Z","shell.execute_reply.started":"2024-01-11T13:25:03.399934Z","shell.execute_reply":"2024-01-11T13:25:03.425382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_features(file_path):\n\n    y, sr = librosa.load(file_path)\n\n\n    mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)\n    zero_crossings = librosa.feature.zero_crossing_rate(y)\n    spectral_centroid = librosa.feature.spectral_centroid(y=y, sr=sr)[0]\n    rms_energy = librosa.feature.rms(y=y)[0]\n    spectral_rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)[0]\n    pitches, magnitudes = librosa.core.pitch.piptrack(y=y, sr=sr)\n\n\n    pitch = np.mean(pitches[pitches > 0])\n\n\n    spectral_flux = librosa.onset.onset_strength(y=y, sr=sr)\n\n    return mfccs, zero_crossings, spectral_centroid, rms_energy, spectral_rolloff, pitch, spectral_flux\n\n\nfile_paths = [\"/kaggle/input/bird-voice/bird_voices/XC114551.mp3\", \"/kaggle/input/bird-voice/bird_voices/XC114552.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC123581.mp3\",\n              \"/kaggle/input/bird-voice/bird_voices/XC123582.mp3\", \"/kaggle/input/bird-voice/bird_voices/XC145140.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC137975.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC142682.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC120869.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC137570.mp3\",\"/kaggle/input/bird-voice/bird_voices/XC142068.mp3\"]\n\n\n\nfeatures_list = [extract_features(file_path) for file_path in file_paths]\n\ndef descriptive_stats(feature_index):\n    amecro_feature = [feature_set[feature_index].mean() for feature_set in features_list[:2]]\n    coohaw_feature= [feature_set[feature_index].mean() for feature_set in features_list[2:4]]\n    merlin_feature= [feature_set[feature_index].mean() for feature_set in features_list[4:6]]\n    veery_feature= [feature_set[feature_index].mean() for feature_set in features_list[6:8]]\n    aldfly_feature= [feature_set[feature_index].mean() for feature_set in features_list[8:10]]\n   \n    mean_amecro = np.mean(amecro_feature)\n    std_amecro = np.std(amecro_feature)\n    \n    mean_coohaw = np.mean(coohaw_feature)\n    std_coohaw = np.std(coohaw_feature)\n    \n    mean_merlin = np.mean(merlin_feature)\n    std_merlin = np.std(merlin_feature)\n    \n    mean_veery = np.mean(veery_feature)\n    std_veery = np.std(veery_feature)\n    \n    mean_aldfly = np.mean(aldfly_feature)\n    std_aldfly = np.std(aldfly_feature)\n\n    return amecro_feature, coohaw_feature,merlin_feature,veery_feature, aldfly_feature, mean_amecro, std_amecro, mean_coohaw, std_coohaw, mean_merlin , std_merlin, mean_veery, std_veery,  mean_aldfly, std_aldfly\n\n\nfeature_names = [\"MFCCs\", \"Zero Crossing Rate\", \"Spectral Centroid\", \"RMS Energy\", \"Spectral Rolloff\", \"Pitch\", \"Spectral Flux\"]\n\nfor i, feature_name in enumerate(feature_names):\n    amecro_feature, coohaw_feature,merlin_feature,veery_feature, aldfly_feature, mean_amecro, std_amecro, mean_coohaw, std_coohaw, mean_merlin , std_merlin, mean_veery, std_veery,  mean_aldfly, std_aldfly = descriptive_stats(i)\n\n    print(f\"Comparison for {feature_name}:\")\n    print(f\"Mean of 'amecro' category: {mean_amecro}, Standard Deviation: {std_amecro}\")\n    print(f\"Mean of 'coohaw' category: {mean_coohaw}, Standard Deviation: {std_coohaw}\")\n    print(f\"Mean of 'merlin' category: {mean_merlin}, Standard Deviation: {std_merlin}\")\n    print(f\"Mean of 'veery' category: {mean_veery}, Standard Deviation: {std_veery}\")\n    print(f\"Mean of 'aldfly' category: {mean_aldfly}, Standard Deviation: {std_aldfly}\")\n    \n    plt.hist(amecro_feature, bins=20, alpha=0.9, label='amecro')\n    plt.hist(coohaw_feature, bins=20, alpha=0.9, label='coohaw')\n    plt.hist(merlin_feature, bins=20, alpha=0.9, label='merlin')\n    plt.hist(veery_feature, bins=20, alpha=0.9, label='veery')\n    plt.hist(aldfly_feature, bins=20, alpha=0.9, label='aldfly')\n    \n    plt.title(f'Histogram Comparison for {feature_name}')\n    plt.xlabel('Values')\n    plt.ylabel('Frequency')\n    plt.legend()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:03.592320Z","iopub.execute_input":"2024-01-11T13:25:03.593778Z","iopub.status.idle":"2024-01-11T13:25:09.926269Z","shell.execute_reply.started":"2024-01-11T13:25:03.593719Z","shell.execute_reply":"2024-01-11T13:25:09.924659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport audioread\nimport logging\nimport os\nimport random\nimport time\nimport warnings\n\nimport soundfile as sf\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.utils.data as data\n\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Optional\nfrom fastprogress import progress_bar\nfrom sklearn.metrics import f1_score\nfrom torchvision import models","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:09.929871Z","iopub.execute_input":"2024-01-11T13:25:09.930251Z","iopub.status.idle":"2024-01-11T13:25:09.940619Z","shell.execute_reply.started":"2024-01-11T13:25:09.930219Z","shell.execute_reply":"2024-01-11T13:25:09.938549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_seed(seed: int=42):\n        random.seed(seed)\n        np.random.seed(seed)\n        os.environ[\"PYTHONHASHSEED\"]=str(seed)\n        torch.manual_seed(seed)\n        torch.cuda.manual_seed(seed)\n        torch.backends.cudnn.deterministic = True\n        torch.backends.cudnn.benchmark= True","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:09.942650Z","iopub.execute_input":"2024-01-11T13:25:09.942985Z","iopub.status.idle":"2024-01-11T13:25:09.964494Z","shell.execute_reply.started":"2024-01-11T13:25:09.942955Z","shell.execute_reply":"2024-01-11T13:25:09.962572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_logger(out_file=None):\n    logger= logging.getLogger()\n    formatter= logging.Formatter(\"%(asctime)s - %(levelname)s - %(message)s\")\n    logger.handlers = []\n    logger.setLevel(logging.INFO)\n    \n    handler = logging.StreamHandler()\n    handler.setFormatter(formatter)\n    handler.setLevel(logging.INFO)\n    logger.addHandler(handler)\n    \n    if out_file is not None:\n        fh= logging.FileHandler(out_file)\n        fh.setFormatter(formatter)\n        fh.setLevel(logging.INFO)\n        logger.addHandler(fh)\n    logger.info(\"logger set up\")\n    return logger\n\n@contextmanager #measure execution time\ndef timer(name: str, logger: Optional[logging.Logger]= None):\n    t0= time.time()\n    msg= f\"[{name}] start\"\n    if logger is None:\n        print(msg)\n    else:\n        logger.info(msg)    \n    yield\n    \n    msg=f\"[{name}] done in {time.time() - t0:.2f} s\"\n    if logger is None:\n        print(msg)\n    else:\n        logger.info(msg)    \n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:09.968389Z","iopub.execute_input":"2024-01-11T13:25:09.968950Z","iopub.status.idle":"2024-01-11T13:25:09.983769Z","shell.execute_reply.started":"2024-01-11T13:25:09.968903Z","shell.execute_reply":"2024-01-11T13:25:09.981642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logger =get_logger(\"main.log\")\nset_seed(1213)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:09.985211Z","iopub.execute_input":"2024-01-11T13:25:09.985954Z","iopub.status.idle":"2024-01-11T13:25:09.998627Z","shell.execute_reply.started":"2024-01-11T13:25:09.985915Z","shell.execute_reply":"2024-01-11T13:25:09.996723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TARGET_SR=32000","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.000705Z","iopub.execute_input":"2024-01-11T13:25:10.001239Z","iopub.status.idle":"2024-01-11T13:25:10.007537Z","shell.execute_reply.started":"2024-01-11T13:25:10.001197Z","shell.execute_reply":"2024-01-11T13:25:10.006392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/birdcall-check/test.csv\")\ntest_audio = \"/kaggle/input/birdcall-check/test_audio\"\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.008785Z","iopub.execute_input":"2024-01-11T13:25:10.009126Z","iopub.status.idle":"2024-01-11T13:25:10.033300Z","shell.execute_reply.started":"2024-01-11T13:25:10.009094Z","shell.execute_reply":"2024-01-11T13:25:10.032166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ResNet(nn.Module): #base class\n    def __init__(self, base_model_name: str, pretrained=False, #constructor #weights \n                 num_classes=264): #constructor method\n        super().__init__()\n        base_model = models.__getattribute__(base_model_name)(\n              pretrained=pretrained)\n        layers= list(base_model.children())[:-2]\n        layers.append(nn.AdaptiveMaxPool2d(1))\n        self.encoder = nn.Sequential(*layers)\n        \n        in_features=base_model.fc.in_features  #number of input features\n        \n        self.classifier = nn.Sequential(\n          nn.Linear(in_features,1024), nn.ReLU(), nn.Dropout(p=0.2),\n          nn.Linear(1024,1024), nn.ReLU(), nn.Dropout(p=0.2),\n          nn.Linear(1024, num_classes))\n        \n    def forward(self,x):\n        batch_size= x.size(0)\n        x= self.encoder(x).view(batch_size, -1)\n        x= self.classifier(x)\n        multiclass_proba = F.softmax(x, dim=1)\n        multilabel_proba = F.sigmoid(x)\n        \n        return {\n            \"logits\":x,\n            \"multiclass_proba\": multiclass_proba,\n            \"multilabel_proba\": multilabel_proba\n        }","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.034530Z","iopub.execute_input":"2024-01-11T13:25:10.034986Z","iopub.status.idle":"2024-01-11T13:25:10.048412Z","shell.execute_reply.started":"2024-01-11T13:25:10.034953Z","shell.execute_reply":"2024-01-11T13:25:10.046055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_config ={\n    \"base_model_name\": \"resnet50\",\n    \"pretrained\": False,\n    \"num_classes\": 264   \n}\n\nmelspectrogram_parameters ={\n    \"n_mels\": 128,\n    \"fmin\": 0,\n    \"fmax\":12000\n}\nweights_path = \"../input/birdcall-resnet50-init-weights/best.pth\"","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.050411Z","iopub.execute_input":"2024-01-11T13:25:10.050884Z","iopub.status.idle":"2024-01-11T13:25:10.067316Z","shell.execute_reply.started":"2024-01-11T13:25:10.050850Z","shell.execute_reply":"2024-01-11T13:25:10.066232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\ndf=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")\n\nunique_bird_names = df['ebird_code'].unique()\nlabel_encoder = LabelEncoder()\nencoded_labels = label_encoder.fit_transform(unique_bird_names)\n\nBIRD_CODE = dict(zip(unique_bird_names,encoded_labels))\n\n# for bird_name, label in BIRD_CODE.items():\n#     print(f\"{bird_name}: {label}\")\n\nINV_BIRD_CODE={v: k for k, v in BIRD_CODE.items()}","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.070704Z","iopub.execute_input":"2024-01-11T13:25:10.071179Z","iopub.status.idle":"2024-01-11T13:25:10.365551Z","shell.execute_reply.started":"2024-01-11T13:25:10.071138Z","shell.execute_reply":"2024-01-11T13:25:10.363246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def mono_to_color(X:np.ndarray,mean=None,std=None,norm_max=None,norm_min= None,eps=1e-6):\n    X=np.stack([X,X,X],axis=-1)\n    \n    mean = mean or X.mean()\n    X=X-mean\n    std=std or X.std()\n    Xstd= X/(std+eps)\n    \n    _min,_max= Xstd.min(),Xstd.max()\n    norm_max= norm_max or _max\n    norm_min= norm_min or _min\n    \n    if(_max - _min)>eps:\n        V=Xstd\n        V[V<norm_min]=norm_min\n        V[V>norm_max]=norm_max\n        \n        V=255*(V-norm_min)/(norm_max - norm_min)\n        V=V.astype(np.uint8)\n    else:\n        V=np.zeroes_like(Xstd, dtype=np.uint8)\n    return V\n\nclass TestDataset(data.Dataset):\n    def __init__(self,df:pd.DataFrame, clip:np.array,img_size=224,melspectrogram_parameters={}):\n        self.df=df\n        self.clip=clip\n        self.img_size= img_size\n        self.melspectrogram_parameters = melspectrogram_parameters\n        \n    def __len__(self):\n        return len(self.df)\n    \n    def __getitem__(self, idx: int):\n        SR = 32000\n\n        sample = self.df.loc[idx, :]  # return row\n        site = sample.site\n        row_id = sample.row_id\n\n        if site == \"site_3\":\n            y = self.clip.astype(np.float32)\n            len_y = len(y)\n            start = 0\n            end = SR * 5\n\n            images = []\n\n            while len_y > start:\n                y_batch = y[start:end].astype(np.float32)\n\n                if len(y_batch) != (SR * 5):\n                    break\n                start = end\n                end = end + SR * 5\n\n                melspec = librosa.feature.melspectrogram(y=y_batch, sr=SR, **self.melspectrogram_parameters)\n                melspec = librosa.power_to_db(melspec).astype(np.float32)\n\n                image = mono_to_color(melspec)\n\n                height, width, _ =image.shape\n\n                image = cv2.resize(image, (int(width * self.img_size / height), self.img_size))\n\n                image = np.moveaxis(image, 2, 0)  # color channel axis to the first dimension\n\n                image = (image / 255.0).astype(np.float32)\n                images.append(image)\n\n            images = np.asarray(images)\n\n            return images, row_id, site\n\n        else:\n\n            end_seconds = int(sample.seconds)\n            start_seconds = int(end_seconds - 5)\n            start_index = SR * start_seconds\n            end_index = SR * end_seconds\n\n            y = self.clip[start_index:end_index].astype(np.float32)\n\n            melspec = librosa.feature.melspectrogram(y=y, sr=SR, **self.melspectrogram_parameters)\n\n            melspec = librosa.power_to_db(melspec).astype(np.float32)\n\n            image = mono_to_color(melspec)\n            height, width, _ =image.shape\n            image = cv2.resize(image,(int(width * self.img_size / height),self.img_size))\n            image = np.moveaxis(image, 2, 0)\n            image = (image / 255.0).astype(np.float32)\n            \n            return image, row_id, site\n        \n        \n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.367047Z","iopub.execute_input":"2024-01-11T13:25:10.367531Z","iopub.status.idle":"2024-01-11T13:25:10.390213Z","shell.execute_reply.started":"2024-01-11T13:25:10.367477Z","shell.execute_reply":"2024-01-11T13:25:10.388038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model(config: dict, weights_path: str):\n    model = ResNet(**config)\n\n    # Load the checkpoint and map the tensors to the CPU if CUDA is not available\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n    checkpoint = torch.load(weights_path, map_location=device)\n\n    # Load the model's learned parameters\n    model.load_state_dict(checkpoint[\"model_state_dict\"])\n\n    # Move the model to the specified device\n    model.to(device)\n\n    # Set the model to evaluation mode\n    model.eval()\n\n    return model\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.391561Z","iopub.execute_input":"2024-01-11T13:25:10.392020Z","iopub.status.idle":"2024-01-11T13:25:10.408960Z","shell.execute_reply.started":"2024-01-11T13:25:10.391984Z","shell.execute_reply":"2024-01-11T13:25:10.406977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prediction_for_clip(test_df: pd.DataFrame,\n                        clip: np.ndarray,\n                        model: ResNet,\n                        mel_params: dict,\n                        threshold=0.5):\n\n\n    dataset = TestDataset(df=test_df,\n                          clip=clip,\n                          img_size=224,\n                          melspectrogram_parameters=mel_params)\n\n    loader = data.DataLoader(dataset, batch_size=1, shuffle=False)\n\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n    model.eval()\n\n    prediction_dict = {}\n\n    for image, row_id, site in progress_bar(loader):\n        site = site[0]\n        row_id = row_id[0]\n\n        if site in {\"site_1\", \"site_2\"}:\n            image = image.to(device)\n\n            with torch.no_grad():\n                prediction = model(image)\n                proba = prediction[\"multilabel_proba\"].detach().cpu().numpy().reshape(-1)\n                \n            events = proba >= threshold\n            labels = np.argwhere(events).reshape(-1).tolist()\n            \n        else:\n    # to avoid prediction on large batch\n            image = image.squeeze(0)\n            batch_size = 16\n            whole_size = image.size(0)\n\n            if whole_size % batch_size == 0:\n                n_iter = whole_size // batch_size\n            else:\n                n_iter = whole_size // batch_size + 1\n\n            all_events = set()\n\n            for batch_i in range(n_iter):\n                batch = image[batch_i * batch_size: (batch_i + 1) * batch_size]\n\n                if batch.ndim == 3:\n                    batch = batch.unsqueeze(0)\n                    \n                batch = batch.to(device)\n                with torch.no_grad():\n                    prediction = model(batch)\n\n                    proba = prediction[\"multilabel_proba\"].detach().cpu().numpy()\n                events = proba >= threshold\n\n                for i in range(len(events)):\n                    event = events[i, :]\n                    labels = np.argwhere(event).reshape(-1).tolist()\n\n                    for label in labels:\n                        all_events.add(label)\n\n            labels=list(all_events)\n            \n        if len(labels)==0:\n            prediction_dict[row_id]=\"nocall\"\n        else:\n            labels_str_list=list(map(lambda x: INV_BIRD_CODE[x], labels))\n            label_string=\" \".join(labels_str_list)\n            prediction_dict[row_id]= label_string\n            \n    return prediction_dict\n            # Rest of the code for this section (not provided in the question)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.410979Z","iopub.execute_input":"2024-01-11T13:25:10.412435Z","iopub.status.idle":"2024-01-11T13:25:10.427429Z","shell.execute_reply.started":"2024-01-11T13:25:10.412383Z","shell.execute_reply":"2024-01-11T13:25:10.426125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prediction(test_df: pd.DataFrame,\n              test_audio: Path,\n              model_config: dict,\n              mel_params: dict,\n              weights_path: str,\n              threshold=0.5):\n    \n    model = get_model(model_config, weights_path)\n    unique_audio_id = test_df.audio_id.unique()\n\n    warnings.filterwarnings(\"ignore\")\n\n    prediction_dfs = []\n\n    for audio_id in unique_audio_id:\n        with timer(f\"Loading {audio_id}\", logger):\n            clip, _ = librosa.load(test_audio + \"/\" + (audio_id + \".mp3\"),\n                                   sr=TARGET_SR,\n                                   mono=True,\n                                   res_type=\"scipy\")\n\n        test_df_for_audio_id = test_df.query(\n            f\"audio_id == '{audio_id}'\").reset_index(drop=True)\n        with timer(f\"Prediction on {audio_id}\", logger):\n            prediction_dict = prediction_for_clip(test_df_for_audio_id,\n                                                  clip=clip,\n                                                  model=model,\n                                                  mel_params=mel_params,\n                                                  threshold=threshold)\n        row_id = list(prediction_dict.keys())\n        birds = list(prediction_dict.values())\n\n        prediction_df = pd.DataFrame({\n           \"row_id\": row_id,\n           \"birds\": birds\n        })\n\n        prediction_dfs.append(prediction_df)\n\n    prediction_df = pd.concat(prediction_dfs, axis=0, sort=False).reset_index(drop=True)\n\n    return prediction_df\n\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.429148Z","iopub.execute_input":"2024-01-11T13:25:10.429487Z","iopub.status.idle":"2024-01-11T13:25:10.449224Z","shell.execute_reply.started":"2024-01-11T13:25:10.429457Z","shell.execute_reply":"2024-01-11T13:25:10.447020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = prediction(test_df=test,\n                        test_audio=test_audio,\n                        model_config=model_config,\n                        mel_params=melspectrogram_parameters,\n                        weights_path=weights_path,\n                        threshold=0.8)\n\nsubmission.to_csv(\"submission.csv\", index=False)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T13:25:10.451737Z","iopub.execute_input":"2024-01-11T13:25:10.452159Z","iopub.status.idle":"2024-01-11T13:25:49.319826Z","shell.execute_reply.started":"2024-01-11T13:25:10.452127Z","shell.execute_reply":"2024-01-11T13:25:49.318020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}