{"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":"gpu","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424},{"sourceId":1264575,"sourceType":"datasetVersion","datasetId":725893}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the re.cad-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-14T13:41:16.211320Z","iopub.execute_input":"2024-01-14T13:41:16.211581Z","iopub.status.idle":"2024-01-14T13:41:24.385662Z","shell.execute_reply.started":"2024-01-14T13:41:16.211553Z","shell.execute_reply":"2024-01-14T13:41:24.384719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt # for visualising data\n%matplotlib inline\nimport seaborn as sns\n\nimport IPython.display as ipd # for playing audio files\nimport soundfile as sf # for reading and writing audio files\nimport audioread # reading and processing audio files\nimport os # file and directory manipulation \nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:41:24.387587Z","iopub.execute_input":"2024-01-14T13:41:24.387979Z","iopub.status.idle":"2024-01-14T13:41:24.890563Z","shell.execute_reply.started":"2024-01-14T13:41:24.387953Z","shell.execute_reply":"2024-01-14T13:41:24.889717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n!pip install librosa==0.9.2","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:41:24.891670Z","iopub.execute_input":"2024-01-14T13:41:24.891957Z","iopub.status.idle":"2024-01-14T13:41:38.199425Z","shell.execute_reply.started":"2024-01-14T13:41:24.891932Z","shell.execute_reply":"2024-01-14T13:41:38.198461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:39.604279Z","iopub.execute_input":"2024-01-14T13:46:39.604669Z","iopub.status.idle":"2024-01-14T13:46:39.608865Z","shell.execute_reply.started":"2024-01-14T13:46:39.604638Z","shell.execute_reply":"2024-01-14T13:46:39.607985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")\ndf","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:42.556961Z","iopub.execute_input":"2024-01-14T13:46:42.557336Z","iopub.status.idle":"2024-01-14T13:46:42.888972Z","shell.execute_reply.started":"2024-01-14T13:46:42.557306Z","shell.execute_reply":"2024-01-14T13:46:42.888053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To see all the columns in the dataframe, setting max limit for dispalying column as 'None'.","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:44.984034Z","iopub.execute_input":"2024-01-14T13:46:44.984388Z","iopub.status.idle":"2024-01-14T13:46:44.988793Z","shell.execute_reply.started":"2024-01-14T13:46:44.984361Z","shell.execute_reply":"2024-01-14T13:46:44.987824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:45.431205Z","iopub.execute_input":"2024-01-14T13:46:45.432066Z","iopub.status.idle":"2024-01-14T13:46:45.460958Z","shell.execute_reply.started":"2024-01-14T13:46:45.432034Z","shell.execute_reply":"2024-01-14T13:46:45.460000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:45.571366Z","iopub.execute_input":"2024-01-14T13:46:45.572271Z","iopub.status.idle":"2024-01-14T13:46:45.577960Z","shell.execute_reply.started":"2024-01-14T13:46:45.572232Z","shell.execute_reply":"2024-01-14T13:46:45.577048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:45.883532Z","iopub.execute_input":"2024-01-14T13:46:45.883905Z","iopub.status.idle":"2024-01-14T13:46:45.890455Z","shell.execute_reply.started":"2024-01-14T13:46:45.883873Z","shell.execute_reply":"2024-01-14T13:46:45.889529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:46.178852Z","iopub.execute_input":"2024-01-14T13:46:46.179765Z","iopub.status.idle":"2024-01-14T13:46:46.254855Z","shell.execute_reply.started":"2024-01-14T13:46:46.179730Z","shell.execute_reply":"2024-01-14T13:46:46.253907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:46.639203Z","iopub.execute_input":"2024-01-14T13:46:46.640071Z","iopub.status.idle":"2024-01-14T13:46:46.647129Z","shell.execute_reply.started":"2024-01-14T13:46:46.640035Z","shell.execute_reply":"2024-01-14T13:46:46.646160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:46.859852Z","iopub.execute_input":"2024-01-14T13:46:46.860495Z","iopub.status.idle":"2024-01-14T13:46:46.869917Z","shell.execute_reply.started":"2024-01-14T13:46:46.860462Z","shell.execute_reply":"2024-01-14T13:46:46.868981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'] = df['playback_used'].replace(np.nan, 'no')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:47.052381Z","iopub.execute_input":"2024-01-14T13:46:47.052721Z","iopub.status.idle":"2024-01-14T13:46:47.062526Z","shell.execute_reply.started":"2024-01-14T13:46:47.052697Z","shell.execute_reply":"2024-01-14T13:46:47.061572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:47.313455Z","iopub.execute_input":"2024-01-14T13:46:47.314456Z","iopub.status.idle":"2024-01-14T13:46:47.321975Z","shell.execute_reply.started":"2024-01-14T13:46:47.314422Z","shell.execute_reply":"2024-01-14T13:46:47.320984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'] = df['playback_used'].replace('yes', '1')\ndf['playback_used'] = df['playback_used'].replace('no', '0')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:47.478612Z","iopub.execute_input":"2024-01-14T13:46:47.479468Z","iopub.status.idle":"2024-01-14T13:46:47.491817Z","shell.execute_reply.started":"2024-01-14T13:46:47.479436Z","shell.execute_reply":"2024-01-14T13:46:47.490942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'] = df['playback_used'].astype(int)\ndf['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:47.677107Z","iopub.execute_input":"2024-01-14T13:46:47.677845Z","iopub.status.idle":"2024-01-14T13:46:47.687791Z","shell.execute_reply.started":"2024-01-14T13:46:47.677815Z","shell.execute_reply":"2024-01-14T13:46:47.686921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I have tried to convert into int so replaced yes and no by 0,1\n","metadata":{}},{"cell_type":"code","source":"df['ebird_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:48.073505Z","iopub.execute_input":"2024-01-14T13:46:48.074441Z","iopub.status.idle":"2024-01-14T13:46:48.084253Z","shell.execute_reply.started":"2024-01-14T13:46:48.074407Z","shell.execute_reply":"2024-01-14T13:46:48.083307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn\nfrom sklearn.preprocessing import LabelEncoder\nle= LabelEncoder()\ndf['ebird_code_encoded']=le.fit_transform(df['ebird_code'])\ndf['ebird_code_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:48.271736Z","iopub.execute_input":"2024-01-14T13:46:48.272539Z","iopub.status.idle":"2024-01-14T13:46:48.286411Z","shell.execute_reply.started":"2024-01-14T13:46:48.272507Z","shell.execute_reply":"2024-01-14T13:46:48.285470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here i have used label encoder to encode this and also ebird code coloumn is there if someone wants a reference so not dropping it.","metadata":{}},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:48.663454Z","iopub.execute_input":"2024-01-14T13:46:48.664360Z","iopub.status.idle":"2024-01-14T13:46:48.671837Z","shell.execute_reply.started":"2024-01-14T13:46:48.664326Z","shell.execute_reply":"2024-01-14T13:46:48.670955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'] = df['channels'].apply(lambda x: x.split(' ')[0])\ndf['channels'] = df['channels'].astype(int)\ndf['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:48.838984Z","iopub.execute_input":"2024-01-14T13:46:48.839897Z","iopub.status.idle":"2024-01-14T13:46:48.859711Z","shell.execute_reply.started":"2024-01-14T13:46:48.839861Z","shell.execute_reply":"2024-01-14T13:46:48.858647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"here i have split the data and convert to int ","metadata":{}},{"cell_type":"code","source":"df['year'] = df['date'].apply(lambda x: x.split('-')[0])","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:49.401747Z","iopub.execute_input":"2024-01-14T13:46:49.402659Z","iopub.status.idle":"2024-01-14T13:46:49.419664Z","shell.execute_reply.started":"2024-01-14T13:46:49.402623Z","shell.execute_reply":"2024-01-14T13:46:49.418742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year'].value_counts()\ndf['year'] = df['year'].replace('0000', '2014')\ndf['year'] = df['year'].replace('0201', '2014')\ndf['year'] = df['year'].replace('1012', '2014')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:49.617005Z","iopub.execute_input":"2024-01-14T13:46:49.617870Z","iopub.status.idle":"2024-01-14T13:46:49.640537Z","shell.execute_reply.started":"2024-01-14T13:46:49.617833Z","shell.execute_reply":"2024-01-14T13:46:49.639648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:49.927087Z","iopub.execute_input":"2024-01-14T13:46:49.927791Z","iopub.status.idle":"2024-01-14T13:46:49.938322Z","shell.execute_reply.started":"2024-01-14T13:46:49.927758Z","shell.execute_reply":"2024-01-14T13:46:49.937448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:50.011933Z","iopub.execute_input":"2024-01-14T13:46:50.012281Z","iopub.status.idle":"2024-01-14T13:46:50.020190Z","shell.execute_reply.started":"2024-01-14T13:46:50.012253Z","shell.execute_reply":"2024-01-14T13:46:50.019236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['month'] = df['date'].apply(lambda x: x.split('-')[1])\ndf['month'].value_counts()\ndf['month'] = df['month'].replace('00', '05')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:50.150125Z","iopub.execute_input":"2024-01-14T13:46:50.150555Z","iopub.status.idle":"2024-01-14T13:46:50.178319Z","shell.execute_reply.started":"2024-01-14T13:46:50.150524Z","shell.execute_reply":"2024-01-14T13:46:50.177319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndf['month']=df['month'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:50.360346Z","iopub.execute_input":"2024-01-14T13:46:50.360715Z","iopub.status.idle":"2024-01-14T13:46:50.369375Z","shell.execute_reply.started":"2024-01-14T13:46:50.360687Z","shell.execute_reply":"2024-01-14T13:46:50.368344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.month.unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:50.728736Z","iopub.execute_input":"2024-01-14T13:46:50.729706Z","iopub.status.idle":"2024-01-14T13:46:50.736453Z","shell.execute_reply.started":"2024-01-14T13:46:50.729669Z","shell.execute_reply":"2024-01-14T13:46:50.735342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here I have extract the month  and year from date as they are more helpful in study.","metadata":{}},{"cell_type":"code","source":"df=df.drop('date',axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:51.140748Z","iopub.execute_input":"2024-01-14T13:46:51.141571Z","iopub.status.idle":"2024-01-14T13:46:51.152940Z","shell.execute_reply.started":"2024-01-14T13:46:51.141540Z","shell.execute_reply":"2024-01-14T13:46:51.152116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:51.409255Z","iopub.execute_input":"2024-01-14T13:46:51.409779Z","iopub.status.idle":"2024-01-14T13:46:51.417792Z","shell.execute_reply.started":"2024-01-14T13:46:51.409749Z","shell.execute_reply":"2024-01-14T13:46:51.416721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:51.643744Z","iopub.execute_input":"2024-01-14T13:46:51.644404Z","iopub.status.idle":"2024-01-14T13:46:51.654431Z","shell.execute_reply.started":"2024-01-14T13:46:51.644371Z","shell.execute_reply":"2024-01-14T13:46:51.653386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.drop('pitch',axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:51.737697Z","iopub.execute_input":"2024-01-14T13:46:51.738413Z","iopub.status.idle":"2024-01-14T13:46:51.752436Z","shell.execute_reply.started":"2024-01-14T13:46:51.738382Z","shell.execute_reply":"2024-01-14T13:46:51.751643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have drop pitch as there is so much not specified values are there.","metadata":{}},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:52.120941Z","iopub.execute_input":"2024-01-14T13:46:52.121674Z","iopub.status.idle":"2024-01-14T13:46:52.127815Z","shell.execute_reply.started":"2024-01-14T13:46:52.121643Z","shell.execute_reply":"2024-01-14T13:46:52.126820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:52.311975Z","iopub.execute_input":"2024-01-14T13:46:52.312718Z","iopub.status.idle":"2024-01-14T13:46:52.323062Z","shell.execute_reply.started":"2024-01-14T13:46:52.312684Z","shell.execute_reply":"2024-01-14T13:46:52.322160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.drop('speed',axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:52.671977Z","iopub.execute_input":"2024-01-14T13:46:52.672380Z","iopub.status.idle":"2024-01-14T13:46:52.686917Z","shell.execute_reply.started":"2024-01-14T13:46:52.672346Z","shell.execute_reply":"2024-01-14T13:46:52.686048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"i have dropped speed as so much not specied value .","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"df['species'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:53.282021Z","iopub.execute_input":"2024-01-14T13:46:53.282741Z","iopub.status.idle":"2024-01-14T13:46:53.292078Z","shell.execute_reply.started":"2024-01-14T13:46:53.282710Z","shell.execute_reply":"2024-01-14T13:46:53.291046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['species'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:53.449626Z","iopub.execute_input":"2024-01-14T13:46:53.449968Z","iopub.status.idle":"2024-01-14T13:46:53.461179Z","shell.execute_reply.started":"2024-01-14T13:46:53.449944Z","shell.execute_reply":"2024-01-14T13:46:53.460235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le= LabelEncoder()\ndf['species_encoded']=le.fit_transform(df['species'])\ndf['species_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:53.644303Z","iopub.execute_input":"2024-01-14T13:46:53.645005Z","iopub.status.idle":"2024-01-14T13:46:53.659231Z","shell.execute_reply.started":"2024-01-14T13:46:53.644972Z","shell.execute_reply":"2024-01-14T13:46:53.658236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have label encoded the species value and conver to int .","metadata":{}},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:54.038290Z","iopub.execute_input":"2024-01-14T13:46:54.038657Z","iopub.status.idle":"2024-01-14T13:46:54.046417Z","shell.execute_reply.started":"2024-01-14T13:46:54.038621Z","shell.execute_reply":"2024-01-14T13:46:54.045422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:54.266294Z","iopub.execute_input":"2024-01-14T13:46:54.266667Z","iopub.status.idle":"2024-01-14T13:46:54.276724Z","shell.execute_reply.started":"2024-01-14T13:46:54.266638Z","shell.execute_reply":"2024-01-14T13:46:54.275730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'] = df['bird_seen'].replace(np.nan, 'yes')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:54.408465Z","iopub.execute_input":"2024-01-14T13:46:54.409181Z","iopub.status.idle":"2024-01-14T13:46:54.419509Z","shell.execute_reply.started":"2024-01-14T13:46:54.409141Z","shell.execute_reply":"2024-01-14T13:46:54.417580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'] = df['bird_seen'].replace('yes', '1')\ndf['bird_seen'] = df['bird_seen'].replace('no', '0')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:54.591251Z","iopub.execute_input":"2024-01-14T13:46:54.591613Z","iopub.status.idle":"2024-01-14T13:46:54.606102Z","shell.execute_reply.started":"2024-01-14T13:46:54.591579Z","shell.execute_reply":"2024-01-14T13:46:54.604938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:54.789551Z","iopub.execute_input":"2024-01-14T13:46:54.789904Z","iopub.status.idle":"2024-01-14T13:46:54.799837Z","shell.execute_reply.started":"2024-01-14T13:46:54.789875Z","shell.execute_reply":"2024-01-14T13:46:54.798635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen']=df['bird_seen'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:46:55.088005Z","iopub.execute_input":"2024-01-14T13:46:55.088875Z","iopub.status.idle":"2024-01-14T13:46:55.096481Z","shell.execute_reply.started":"2024-01-14T13:46:55.088841Z","shell.execute_reply":"2024-01-14T13:46:55.095408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:17.394516Z","iopub.execute_input":"2024-01-14T13:47:17.395208Z","iopub.status.idle":"2024-01-14T13:47:17.401769Z","shell.execute_reply.started":"2024-01-14T13:47:17.395178Z","shell.execute_reply":"2024-01-14T13:47:17.400828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"here i have replaced nan values by \"yes\" as more values are yes so i can fill it and then conver to int ","metadata":{}},{"cell_type":"code","source":"df['sci_name'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:17.915061Z","iopub.execute_input":"2024-01-14T13:47:17.915436Z","iopub.status.idle":"2024-01-14T13:47:17.924329Z","shell.execute_reply.started":"2024-01-14T13:47:17.915407Z","shell.execute_reply":"2024-01-14T13:47:17.923433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:18.072462Z","iopub.execute_input":"2024-01-14T13:47:18.072820Z","iopub.status.idle":"2024-01-14T13:47:18.083347Z","shell.execute_reply.started":"2024-01-14T13:47:18.072792Z","shell.execute_reply":"2024-01-14T13:47:18.082406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le= LabelEncoder()\ndf['sci_name_encoded']=le.fit_transform(df['sci_name'])\ndf['sci_name_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:18.300657Z","iopub.execute_input":"2024-01-14T13:47:18.301348Z","iopub.status.idle":"2024-01-14T13:47:18.314962Z","shell.execute_reply.started":"2024-01-14T13:47:18.301313Z","shell.execute_reply":"2024-01-14T13:47:18.314009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name_encoded']= df['sci_name_encoded'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:18.485901Z","iopub.execute_input":"2024-01-14T13:47:18.486889Z","iopub.status.idle":"2024-01-14T13:47:18.491416Z","shell.execute_reply.started":"2024-01-14T13:47:18.486853Z","shell.execute_reply":"2024-01-14T13:47:18.490492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name_encoded'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:18.688860Z","iopub.execute_input":"2024-01-14T13:47:18.689244Z","iopub.status.idle":"2024-01-14T13:47:18.697076Z","shell.execute_reply.started":"2024-01-14T13:47:18.689213Z","shell.execute_reply":"2024-01-14T13:47:18.696120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"i have label encoded the scientific names of the birds .","metadata":{}},{"cell_type":"code","source":"df['latitude'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:19.412841Z","iopub.execute_input":"2024-01-14T13:47:19.413554Z","iopub.status.idle":"2024-01-14T13:47:19.421339Z","shell.execute_reply.started":"2024-01-14T13:47:19.413524Z","shell.execute_reply":"2024-01-14T13:47:19.420319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:19.534069Z","iopub.execute_input":"2024-01-14T13:47:19.534427Z","iopub.status.idle":"2024-01-14T13:47:19.548991Z","shell.execute_reply.started":"2024-01-14T13:47:19.534401Z","shell.execute_reply":"2024-01-14T13:47:19.547992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'] = df['latitude'].replace('Not specified', '31.906')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:19.736109Z","iopub.execute_input":"2024-01-14T13:47:19.736473Z","iopub.status.idle":"2024-01-14T13:47:19.745101Z","shell.execute_reply.started":"2024-01-14T13:47:19.736447Z","shell.execute_reply":"2024-01-14T13:47:19.744223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude']= df['latitude'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:19.913969Z","iopub.execute_input":"2024-01-14T13:47:19.914352Z","iopub.status.idle":"2024-01-14T13:47:19.923236Z","shell.execute_reply.started":"2024-01-14T13:47:19.914321Z","shell.execute_reply":"2024-01-14T13:47:19.922241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:20.104733Z","iopub.execute_input":"2024-01-14T13:47:20.105087Z","iopub.status.idle":"2024-01-14T13:47:20.118551Z","shell.execute_reply.started":"2024-01-14T13:47:20.105060Z","shell.execute_reply":"2024-01-14T13:47:20.117558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have filled nan values then convert the latitudes part to float ","metadata":{}},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:20.487073Z","iopub.execute_input":"2024-01-14T13:47:20.487454Z","iopub.status.idle":"2024-01-14T13:47:20.495672Z","shell.execute_reply.started":"2024-01-14T13:47:20.487424Z","shell.execute_reply":"2024-01-14T13:47:20.494551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'] = df['sampling_rate'].apply(lambda x: x.split(' ')[0])","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:20.682333Z","iopub.execute_input":"2024-01-14T13:47:20.683017Z","iopub.status.idle":"2024-01-14T13:47:20.701111Z","shell.execute_reply.started":"2024-01-14T13:47:20.682984Z","shell.execute_reply":"2024-01-14T13:47:20.700188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"df['sampling_rate']=df['sampling_rate'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:21.092784Z","iopub.execute_input":"2024-01-14T13:47:21.093482Z","iopub.status.idle":"2024-01-14T13:47:21.101909Z","shell.execute_reply.started":"2024-01-14T13:47:21.093448Z","shell.execute_reply":"2024-01-14T13:47:21.100941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:21.298865Z","iopub.execute_input":"2024-01-14T13:47:21.300021Z","iopub.status.idle":"2024-01-14T13:47:21.306444Z","shell.execute_reply.started":"2024-01-14T13:47:21.299985Z","shell.execute_reply":"2024-01-14T13:47:21.305489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate_encoded']=le.fit_transform(df['sampling_rate'])\ndf['sampling_rate_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:21.641059Z","iopub.execute_input":"2024-01-14T13:47:21.641453Z","iopub.status.idle":"2024-01-14T13:47:21.653017Z","shell.execute_reply.started":"2024-01-14T13:47:21.641423Z","shell.execute_reply":"2024-01-14T13:47:21.652184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have extract the sampling rate and then encoded it .","metadata":{}},{"cell_type":"code","source":"df=df.drop('sampling_rate',axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:21.853073Z","iopub.execute_input":"2024-01-14T13:47:21.853914Z","iopub.status.idle":"2024-01-14T13:47:21.868976Z","shell.execute_reply.started":"2024-01-14T13:47:21.853882Z","shell.execute_reply":"2024-01-14T13:47:21.867821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:22.080792Z","iopub.execute_input":"2024-01-14T13:47:22.081661Z","iopub.status.idle":"2024-01-14T13:47:22.090516Z","shell.execute_reply.started":"2024-01-14T13:47:22.081624Z","shell.execute_reply":"2024-01-14T13:47:22.089454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:22.242458Z","iopub.execute_input":"2024-01-14T13:47:22.243298Z","iopub.status.idle":"2024-01-14T13:47:22.254541Z","shell.execute_reply.started":"2024-01-14T13:47:22.243261Z","shell.execute_reply":"2024-01-14T13:47:22.253634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:22.435033Z","iopub.execute_input":"2024-01-14T13:47:22.435416Z","iopub.status.idle":"2024-01-14T13:47:22.444389Z","shell.execute_reply.started":"2024-01-14T13:47:22.435386Z","shell.execute_reply":"2024-01-14T13:47:22.443481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].apply(lambda x: x.split(' m')[0])\ndf['elevation'] = df['elevation'].apply(lambda x: x.split('m')[0])\ndf['elevation'] = df['elevation'].apply(lambda x: x.split('-')[0])\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:22.639495Z","iopub.execute_input":"2024-01-14T13:47:22.639868Z","iopub.status.idle":"2024-01-14T13:47:22.675550Z","shell.execute_reply.started":"2024-01-14T13:47:22.639841Z","shell.execute_reply":"2024-01-14T13:47:22.674598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:22.844666Z","iopub.execute_input":"2024-01-14T13:47:22.845513Z","iopub.status.idle":"2024-01-14T13:47:22.854383Z","shell.execute_reply.started":"2024-01-14T13:47:22.845481Z","shell.execute_reply":"2024-01-14T13:47:22.853469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].dropna()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:23.045901Z","iopub.execute_input":"2024-01-14T13:47:23.046301Z","iopub.status.idle":"2024-01-14T13:47:23.054244Z","shell.execute_reply.started":"2024-01-14T13:47:23.046271Z","shell.execute_reply":"2024-01-14T13:47:23.053368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].replace('Unknown', '0')\ndf['elevation'] = df['elevation'].replace('~950', '950')\ndf['elevation'] = df['elevation'].replace('', '0')\ndf['elevation'] = df['elevation'].replace('?', '0')\ndf['elevation'] = df['elevation'].replace('??', '0')\ndf['elevation'] = df['elevation'].str.replace(',', '')\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:23.369664Z","iopub.execute_input":"2024-01-14T13:47:23.370020Z","iopub.status.idle":"2024-01-14T13:47:23.405062Z","shell.execute_reply.started":"2024-01-14T13:47:23.369991Z","shell.execute_reply":"2024-01-14T13:47:23.404172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:23.770665Z","iopub.execute_input":"2024-01-14T13:47:23.771016Z","iopub.status.idle":"2024-01-14T13:47:23.779920Z","shell.execute_reply.started":"2024-01-14T13:47:23.770989Z","shell.execute_reply":"2024-01-14T13:47:23.778939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:24.178101Z","iopub.execute_input":"2024-01-14T13:47:24.178483Z","iopub.status.idle":"2024-01-14T13:47:24.187712Z","shell.execute_reply.started":"2024-01-14T13:47:24.178455Z","shell.execute_reply":"2024-01-14T13:47:24.186554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have cleaned the elevation data coloumn convert to float type","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:25.207582Z","iopub.execute_input":"2024-01-14T13:47:25.207956Z","iopub.status.idle":"2024-01-14T13:47:25.216239Z","shell.execute_reply.started":"2024-01-14T13:47:25.207928Z","shell.execute_reply":"2024-01-14T13:47:25.215011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('bitrate_of_mp3', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:25.550875Z","iopub.execute_input":"2024-01-14T13:47:25.551221Z","iopub.status.idle":"2024-01-14T13:47:25.595815Z","shell.execute_reply.started":"2024-01-14T13:47:25.551194Z","shell.execute_reply":"2024-01-14T13:47:25.594892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have drpped bitrate coloumn as i dont find useful in my eda","metadata":{}},{"cell_type":"code","source":"df['file_type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:26.353907Z","iopub.execute_input":"2024-01-14T13:47:26.354852Z","iopub.status.idle":"2024-01-14T13:47:26.363798Z","shell.execute_reply.started":"2024-01-14T13:47:26.354810Z","shell.execute_reply":"2024-01-14T13:47:26.362634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['file_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:26.673470Z","iopub.execute_input":"2024-01-14T13:47:26.673834Z","iopub.status.idle":"2024-01-14T13:47:26.684187Z","shell.execute_reply.started":"2024-01-14T13:47:26.673805Z","shell.execute_reply":"2024-01-14T13:47:26.683123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['file_type_encoded']=le.fit_transform(df['file_type'])\ndf['file_type_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:26.998942Z","iopub.execute_input":"2024-01-14T13:47:26.999321Z","iopub.status.idle":"2024-01-14T13:47:27.012772Z","shell.execute_reply.started":"2024-01-14T13:47:26.999291Z","shell.execute_reply":"2024-01-14T13:47:27.011849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:27.348537Z","iopub.execute_input":"2024-01-14T13:47:27.349393Z","iopub.status.idle":"2024-01-14T13:47:27.357184Z","shell.execute_reply.started":"2024-01-14T13:47:27.349357Z","shell.execute_reply":"2024-01-14T13:47:27.356213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:27.645556Z","iopub.execute_input":"2024-01-14T13:47:27.646228Z","iopub.status.idle":"2024-01-14T13:47:27.656717Z","shell.execute_reply.started":"2024-01-14T13:47:27.646191Z","shell.execute_reply":"2024-01-14T13:47:27.655685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country_encoded']=le.fit_transform(df['country'])\ndf['country_encoded'].unique","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:27.972584Z","iopub.execute_input":"2024-01-14T13:47:27.973392Z","iopub.status.idle":"2024-01-14T13:47:27.986442Z","shell.execute_reply.started":"2024-01-14T13:47:27.973359Z","shell.execute_reply":"2024-01-14T13:47:27.985415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['number_of_notes'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:28.390422Z","iopub.execute_input":"2024-01-14T13:47:28.391100Z","iopub.status.idle":"2024-01-14T13:47:28.398760Z","shell.execute_reply.started":"2024-01-14T13:47:28.391069Z","shell.execute_reply":"2024-01-14T13:47:28.397849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['number_of_notes'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:28.858320Z","iopub.execute_input":"2024-01-14T13:47:28.858925Z","iopub.status.idle":"2024-01-14T13:47:28.868966Z","shell.execute_reply.started":"2024-01-14T13:47:28.858894Z","shell.execute_reply":"2024-01-14T13:47:28.868008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('number_of_notes', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:29.334248Z","iopub.execute_input":"2024-01-14T13:47:29.335025Z","iopub.status.idle":"2024-01-14T13:47:29.380531Z","shell.execute_reply.started":"2024-01-14T13:47:29.334994Z","shell.execute_reply":"2024-01-14T13:47:29.379576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have dropped number of notes as there is so many not specified values .","metadata":{}},{"cell_type":"code","source":"df['longitude'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:30.681520Z","iopub.execute_input":"2024-01-14T13:47:30.682350Z","iopub.status.idle":"2024-01-14T13:47:30.690061Z","shell.execute_reply.started":"2024-01-14T13:47:30.682316Z","shell.execute_reply":"2024-01-14T13:47:30.689124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['longitude'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:31.248773Z","iopub.execute_input":"2024-01-14T13:47:31.249589Z","iopub.status.idle":"2024-01-14T13:47:31.262926Z","shell.execute_reply.started":"2024-01-14T13:47:31.249557Z","shell.execute_reply":"2024-01-14T13:47:31.262076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:31.581639Z","iopub.execute_input":"2024-01-14T13:47:31.582433Z","iopub.status.idle":"2024-01-14T13:47:31.589836Z","shell.execute_reply.started":"2024-01-14T13:47:31.582399Z","shell.execute_reply":"2024-01-14T13:47:31.588742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['length'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:31.808732Z","iopub.execute_input":"2024-01-14T13:47:31.809093Z","iopub.status.idle":"2024-01-14T13:47:31.818957Z","shell.execute_reply.started":"2024-01-14T13:47:31.809055Z","shell.execute_reply":"2024-01-14T13:47:31.818032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('length', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:32.044660Z","iopub.execute_input":"2024-01-14T13:47:32.045429Z","iopub.status.idle":"2024-01-14T13:47:32.092917Z","shell.execute_reply.started":"2024-01-14T13:47:32.045397Z","shell.execute_reply":"2024-01-14T13:47:32.092056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:32.218293Z","iopub.execute_input":"2024-01-14T13:47:32.218636Z","iopub.status.idle":"2024-01-14T13:47:32.226303Z","shell.execute_reply.started":"2024-01-14T13:47:32.218610Z","shell.execute_reply":"2024-01-14T13:47:32.225432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:32.379124Z","iopub.execute_input":"2024-01-14T13:47:32.379510Z","iopub.status.idle":"2024-01-14T13:47:32.391459Z","shell.execute_reply.started":"2024-01-14T13:47:32.379482Z","shell.execute_reply":"2024-01-14T13:47:32.390477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'] = df['time'].apply(lambda x: x.split(':')[0])\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:32.671780Z","iopub.execute_input":"2024-01-14T13:47:32.672473Z","iopub.status.idle":"2024-01-14T13:47:32.686816Z","shell.execute_reply.started":"2024-01-14T13:47:32.672441Z","shell.execute_reply":"2024-01-14T13:47:32.685715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].unique()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:33.093411Z","iopub.execute_input":"2024-01-14T13:47:33.093767Z","iopub.status.idle":"2024-01-14T13:47:33.101758Z","shell.execute_reply.started":"2024-01-14T13:47:33.093739Z","shell.execute_reply":"2024-01-14T13:47:33.100781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:33.703608Z","iopub.execute_input":"2024-01-14T13:47:33.703954Z","iopub.status.idle":"2024-01-14T13:47:33.715453Z","shell.execute_reply.started":"2024-01-14T13:47:33.703925Z","shell.execute_reply":"2024-01-14T13:47:33.714491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'] = df['time'].replace('?', '8')\ndf['time'] = df['time'].replace('xx', '8')\ndf['time'] = df['time'].replace('am', '8')\ndf['time'] = df['time'].replace('pm', '8')\ndf['time'] = df['time'].replace('.', '8')\ndf['time'] = df['time'].replace('Dawn', '8')\ndf['time'] = df['time'].replace('Sunset', '8')\ndf['time'] = df['time'].replace('??', '8')\ndf['time'] = df['time'].replace('Dawn (at dusk)', '8')\ndf['time'] = df['time'].replace('xx.xx', '8')\ndf['time'] = df['time'].replace('x', '8')","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:34.147646Z","iopub.execute_input":"2024-01-14T13:47:34.148431Z","iopub.status.idle":"2024-01-14T13:47:34.195231Z","shell.execute_reply.started":"2024-01-14T13:47:34.148400Z","shell.execute_reply":"2024-01-14T13:47:34.194330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:34.592361Z","iopub.execute_input":"2024-01-14T13:47:34.593206Z","iopub.status.idle":"2024-01-14T13:47:34.600861Z","shell.execute_reply.started":"2024-01-14T13:47:34.593151Z","shell.execute_reply":"2024-01-14T13:47:34.599938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"i have converted time to hour so we can make analysis on time when bird is seen ","metadata":{}},{"cell_type":"code","source":"df.drop('author', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:35.664066Z","iopub.execute_input":"2024-01-14T13:47:35.664604Z","iopub.status.idle":"2024-01-14T13:47:35.711858Z","shell.execute_reply.started":"2024-01-14T13:47:35.664576Z","shell.execute_reply":"2024-01-14T13:47:35.710915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('filename', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:38:28.219990Z","iopub.execute_input":"2024-01-14T13:38:28.220361Z","iopub.status.idle":"2024-01-14T13:38:28.265198Z","shell.execute_reply.started":"2024-01-14T13:38:28.220328Z","shell.execute_reply":"2024-01-14T13:38:28.264310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('title', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:50.694439Z","iopub.execute_input":"2024-01-14T13:47:50.694944Z","iopub.status.idle":"2024-01-14T13:47:50.741849Z","shell.execute_reply.started":"2024-01-14T13:47:50.694908Z","shell.execute_reply":"2024-01-14T13:47:50.740932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('bitrate_of_mp3', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:51.195944Z","iopub.execute_input":"2024-01-14T13:47:51.196658Z","iopub.status.idle":"2024-01-14T13:47:51.246100Z","shell.execute_reply.started":"2024-01-14T13:47:51.196622Z","shell.execute_reply":"2024-01-14T13:47:51.245131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('url', axis=1)\n\ndf.drop('title', axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:52.022155Z","iopub.execute_input":"2024-01-14T13:47:52.022561Z","iopub.status.idle":"2024-01-14T13:47:52.086599Z","shell.execute_reply.started":"2024-01-14T13:47:52.022529Z","shell.execute_reply":"2024-01-14T13:47:52.085654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:53.159352Z","iopub.execute_input":"2024-01-14T13:47:53.160012Z","iopub.status.idle":"2024-01-14T13:47:53.199993Z","shell.execute_reply.started":"2024-01-14T13:47:53.159979Z","shell.execute_reply":"2024-01-14T13:47:53.199033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:54.152672Z","iopub.execute_input":"2024-01-14T13:47:54.153063Z","iopub.status.idle":"2024-01-14T13:47:54.184513Z","shell.execute_reply.started":"2024-01-14T13:47:54.153033Z","shell.execute_reply":"2024-01-14T13:47:54.183623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:54.870736Z","iopub.execute_input":"2024-01-14T13:47:54.871409Z","iopub.status.idle":"2024-01-14T13:47:54.877067Z","shell.execute_reply.started":"2024-01-14T13:47:54.871380Z","shell.execute_reply":"2024-01-14T13:47:54.876226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:55.578142Z","iopub.execute_input":"2024-01-14T13:47:55.578491Z","iopub.status.idle":"2024-01-14T13:47:55.634656Z","shell.execute_reply.started":"2024-01-14T13:47:55.578466Z","shell.execute_reply":"2024-01-14T13:47:55.633364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:47:56.162937Z","iopub.execute_input":"2024-01-14T13:47:56.163702Z","iopub.status.idle":"2024-01-14T13:47:56.223994Z","shell.execute_reply.started":"2024-01-14T13:47:56.163667Z","shell.execute_reply":"2024-01-14T13:47:56.223078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,6))\n\nsns.countplot( x='rating', data = df, order = df['rating'].value_counts().index, palette = 'magma')\nplt.title(\"Ratings distribution\")\nplt.xlabel(\"Ratings\")\nplt.ylabel(\"Count\")\nplt.xticks(rotation = 45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:48:26.672909Z","iopub.execute_input":"2024-01-14T13:48:26.673311Z","iopub.status.idle":"2024-01-14T13:48:27.168943Z","shell.execute_reply.started":"2024-01-14T13:48:26.673279Z","shell.execute_reply":"2024-01-14T13:48:27.168035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,6))\n\nsns.countplot( x='month', data = df, order = df['month'].value_counts().index, palette = 'viridis')\nplt.title(\"month distribution\")\nplt.xlabel(\"month\")\nplt.ylabel(\"Count\")\nplt.xticks(rotation = 45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:48:30.410459Z","iopub.execute_input":"2024-01-14T13:48:30.410828Z","iopub.status.idle":"2024-01-14T13:48:30.709671Z","shell.execute_reply.started":"2024-01-14T13:48:30.410799Z","shell.execute_reply":"2024-01-14T13:48:30.708903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,6))\n\nsns.countplot( x='year', data = df, order = df['year'].value_counts().nlargest(10).index, palette = 'viridis')\nplt.title(\"Year distribution\")\nplt.xlabel(\"Year\")\nplt.ylabel(\"Count\")\nplt.xticks(rotation = 45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T14:20:45.866083Z","iopub.execute_input":"2024-01-14T14:20:45.867210Z","iopub.status.idle":"2024-01-14T14:20:46.137342Z","shell.execute_reply.started":"2024-01-14T14:20:45.867144Z","shell.execute_reply":"2024-01-14T14:20:46.136383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_counts = df.groupby(['month', 'species']).size().reset_index(name='Count')\n\n# Find the top 10 birds based on overall sightings\ntop_birds = bird_counts.groupby('species')['Count'].sum().nlargest(5).index\n\n# Filter the data for the top 10 birds\nmonth_count = bird_counts[bird_counts['species'].isin(top_birds)]\n\n# Create a line plot using Seaborn\nplt.figure(figsize=(14, 8))\nsns.lineplot(x='month', y='Count', hue='species', data=month_count, palette='muted')\nplt.xlabel('Month')\nplt.ylabel('Count')\nplt.title('Top 10 Bird Appeared Over Time')\nplt.legend(title='species', bbox_to_anchor=(1, 1))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:06.321744Z","iopub.execute_input":"2024-01-14T13:50:06.322331Z","iopub.status.idle":"2024-01-14T13:50:06.734535Z","shell.execute_reply.started":"2024-01-14T13:50:06.322299Z","shell.execute_reply":"2024-01-14T13:50:06.733632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_country_counts = df.groupby(['country', 'species']).size().reset_index(name='Count')\n\n# Find the top 10 birds based on overall sightings\ntop_birds = bird_country_counts.groupby('species')['Count'].sum().nlargest(5).index\n\n# Filter the data for the top 10 birds\ntop_bird_country_counts = bird_country_counts[bird_country_counts['species'].isin(top_birds)]\n\n# Create a line plot using Seaborn\nplt.figure(figsize=(14, 8))\nsns.lineplot(x='country', y='Count', hue='species', data=top_bird_country_counts, marker='o', palette='muted')\nplt.xlabel('Country')\nplt.ylabel('Count')\nplt.title('Top 10 Bird Sightings Over country')\nplt.legend(title='species', bbox_to_anchor=(1, 1))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:06.861501Z","iopub.execute_input":"2024-01-14T13:50:06.862142Z","iopub.status.idle":"2024-01-14T13:50:07.306439Z","shell.execute_reply.started":"2024-01-14T13:50:06.862108Z","shell.execute_reply":"2024-01-14T13:50:07.305529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count = df['number_of_notes'].value_counts()\n\ncustom_colors = [(239/255, 71/255, 111/255, 1),\n                 (247/255,140/255,107/255, 1),\n                 (255/255, 209/255, 102//255, 1),\n                 (6/255, 214/255, 160/255, 1),\n                 (17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(6,6))\nplt.pie(values_count, labels= None, autopct='%1.1f%%', startangle=90, colors=custom_colors, wedgeprops=dict(width=0.3))\n\nplt.gca().set_facecolor('#07384C')\n\nplt.title(f'Distribution of number of notes', fontsize=15)\n\nplt.legend(values_count.index, title='categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:07.348810Z","iopub.execute_input":"2024-01-14T13:50:07.349108Z","iopub.status.idle":"2024-01-14T13:50:07.629713Z","shell.execute_reply.started":"2024-01-14T13:50:07.349083Z","shell.execute_reply":"2024-01-14T13:50:07.628050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count = df['bird_seen'].value_counts()\n\ncustom_colors = [(239/255, 71/255, 111/255, 1),\n                 (247/255,140/255,107/255, 1),\n                 (255/255, 209/255, 102//255, 1),\n                 (6/255, 214/255, 160/255, 1),\n                 (17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(6,6))\nplt.pie(values_count, labels= None, autopct='%1.1f%%', startangle=90, colors=custom_colors, wedgeprops=dict(width=0.3))\n\nplt.gca().set_facecolor('#07384C')\n\nplt.title(f'Distribution of bird seen', fontsize=15)\n\nplt.legend(values_count.index, title='categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:07.667307Z","iopub.execute_input":"2024-01-14T13:50:07.667605Z","iopub.status.idle":"2024-01-14T13:50:07.883844Z","shell.execute_reply.started":"2024-01-14T13:50:07.667581Z","shell.execute_reply":"2024-01-14T13:50:07.879333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.year.value_counts().nlargest(5)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:08.064670Z","iopub.execute_input":"2024-01-14T13:50:08.065262Z","iopub.status.idle":"2024-01-14T13:50:08.076802Z","shell.execute_reply.started":"2024-01-14T13:50:08.065230Z","shell.execute_reply":"2024-01-14T13:50:08.075829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count = df['year'].value_counts().nlargest(5)\n\ncustom_colors = [(239/255, 71/255, 111/255, 1),\n                 (247/255,140/255,107/255, 1),\n                 (255/255, 209/255, 102//255, 1),\n                 (6/255, 214/255, 160/255, 1),\n                 (17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(6,6))\nplt.pie(values_count, labels= None, autopct='%1.1f%%', startangle=90, colors=custom_colors, wedgeprops=dict(width=0.3))\n\nplt.gca().set_facecolor('#07384C')\n\nplt.title(f'Distribution of year', fontsize=15)\n\nplt.legend(values_count.index, title='categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:08.496299Z","iopub.execute_input":"2024-01-14T13:50:08.496989Z","iopub.status.idle":"2024-01-14T13:50:08.683924Z","shell.execute_reply.started":"2024-01-14T13:50:08.496958Z","shell.execute_reply":"2024-01-14T13:50:08.683032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count = df['time'].value_counts().nlargest(10)\n\ncustom_colors = [(239/255, 71/255, 111/255, 1),\n                 (247/255,140/255,107/255, 1),\n                 (255/255, 209/255, 102//255, 1),\n                 (6/255, 214/255, 160/255, 1),\n                 (17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(6,6))\nplt.pie(values_count, labels= None, autopct='%1.1f%%', startangle=90, colors=custom_colors, wedgeprops=dict(width=0.3))\n\nplt.gca().set_facecolor('#07384C')\n\nplt.title(f'Distribution of time of bird seen', fontsize=15)\n\nplt.legend(values_count.index, title='categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:09.064287Z","iopub.execute_input":"2024-01-14T13:50:09.064642Z","iopub.status.idle":"2024-01-14T13:50:09.405210Z","shell.execute_reply.started":"2024-01-14T13:50:09.064617Z","shell.execute_reply":"2024-01-14T13:50:09.404314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**FEATURE EXTRACTION **","metadata":{}},{"cell_type":"code","source":"unique_values = df['species'].unique()[:5]\nunique_values","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:10.073468Z","iopub.execute_input":"2024-01-14T13:50:10.073831Z","iopub.status.idle":"2024-01-14T13:50:10.082099Z","shell.execute_reply.started":"2024-01-14T13:50:10.073801Z","shell.execute_reply":"2024-01-14T13:50:10.081219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs = []\n\n# Extract 2 rows for each unique value\nfor value in unique_values:\n    # Filter rows based on the unique value\n    subset = df[df['species'] == value].head(2)\n    \n    # Append the subset to the result DataFrame\n    dfs.append(subset)\n\ndf_for_FE = pd.concat(dfs, ignore_index=True)\ndf_for_FE","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:10.726064Z","iopub.execute_input":"2024-01-14T13:50:10.726891Z","iopub.status.idle":"2024-01-14T13:50:10.788197Z","shell.execute_reply.started":"2024-01-14T13:50:10.726858Z","shell.execute_reply":"2024-01-14T13:50:10.787329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1,sr1 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/aldfly/XC134874.mp3\")\ny2,sr2 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/aldfly/XC135454.mp3\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:11.304128Z","iopub.execute_input":"2024-01-14T13:50:11.304811Z","iopub.status.idle":"2024-01-14T13:50:13.239399Z","shell.execute_reply.started":"2024-01-14T13:50:11.304782Z","shell.execute_reply":"2024-01-14T13:50:13.238566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Audio1\")\nipd.Audio(y1, rate=sr1)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:13.241310Z","iopub.execute_input":"2024-01-14T13:50:13.241914Z","iopub.status.idle":"2024-01-14T13:50:13.269087Z","shell.execute_reply.started":"2024-01-14T13:50:13.241879Z","shell.execute_reply":"2024-01-14T13:50:13.268220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y3,sr3 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/ameavo/XC133080.mp3\")\ny4,sr4 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/ameavo/XC139829.mp3\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:13.270268Z","iopub.execute_input":"2024-01-14T13:50:13.270551Z","iopub.status.idle":"2024-01-14T13:50:14.151936Z","shell.execute_reply.started":"2024-01-14T13:50:13.270527Z","shell.execute_reply":"2024-01-14T13:50:14.151024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Audio3\")\nipd.Audio(y3, rate=sr3)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:14.154288Z","iopub.execute_input":"2024-01-14T13:50:14.154742Z","iopub.status.idle":"2024-01-14T13:50:14.171374Z","shell.execute_reply.started":"2024-01-14T13:50:14.154707Z","shell.execute_reply":"2024-01-14T13:50:14.170509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y5,sr5 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amebit/XC127371.mp3\")\ny6,sr6 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amebit/XC130058.mp3\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:14.172585Z","iopub.execute_input":"2024-01-14T13:50:14.172927Z","iopub.status.idle":"2024-01-14T13:50:15.565933Z","shell.execute_reply.started":"2024-01-14T13:50:14.172895Z","shell.execute_reply":"2024-01-14T13:50:15.564955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Audio5\")\nipd.Audio(y5, rate=sr5)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:15.567715Z","iopub.execute_input":"2024-01-14T13:50:15.568020Z","iopub.status.idle":"2024-01-14T13:50:15.591348Z","shell.execute_reply.started":"2024-01-14T13:50:15.567993Z","shell.execute_reply":"2024-01-14T13:50:15.590515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y7,sr7 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amecro/XC109768.mp3\")\ny8,sr8 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amecro/XC112598.mp3\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:15.592443Z","iopub.execute_input":"2024-01-14T13:50:15.592744Z","iopub.status.idle":"2024-01-14T13:50:19.963743Z","shell.execute_reply.started":"2024-01-14T13:50:15.592717Z","shell.execute_reply":"2024-01-14T13:50:19.962955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Audio7\")\nipd.Audio(y7, rate=sr7)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:19.965384Z","iopub.execute_input":"2024-01-14T13:50:19.965723Z","iopub.status.idle":"2024-01-14T13:50:19.985818Z","shell.execute_reply.started":"2024-01-14T13:50:19.965694Z","shell.execute_reply":"2024-01-14T13:50:19.984903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y9,sr9 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amegfi/XC109299.mp3\")\ny10,sr10 = librosa.load(\"/kaggle/input/birdsong-recognition/train_audio/amegfi/XC109300.mp3\")","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:19.986948Z","iopub.execute_input":"2024-01-14T13:50:19.987256Z","iopub.status.idle":"2024-01-14T13:50:28.210002Z","shell.execute_reply.started":"2024-01-14T13:50:19.987231Z","shell.execute_reply":"2024-01-14T13:50:28.209202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Audio9\")\nipd.Audio(y9, rate=sr9)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.211183Z","iopub.execute_input":"2024-01-14T13:50:28.211544Z","iopub.status.idle":"2024-01-14T13:50:28.313251Z","shell.execute_reply.started":"2024-01-14T13:50:28.211510Z","shell.execute_reply":"2024-01-14T13:50:28.311727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ZERO CROSSING RATE","metadata":{}},{"cell_type":"code","source":"zcr1 = librosa.feature.zero_crossing_rate(y1)\nprint(zcr1)\nprint(\"zcr1\")\nprint('max:',zcr1.max())\nprint('min:',zcr1.min())\nprint(\"-------------------------------\")\nzcr2 = librosa.feature.zero_crossing_rate(y2)\nprint(\"zcr2\")\nprint('max:',zcr2.max())\nprint('min:',zcr2.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.316968Z","iopub.execute_input":"2024-01-14T13:50:28.317473Z","iopub.status.idle":"2024-01-14T13:50:28.364885Z","shell.execute_reply.started":"2024-01-14T13:50:28.317427Z","shell.execute_reply":"2024-01-14T13:50:28.364035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zcr3 = librosa.feature.zero_crossing_rate(y3)\nprint(\"zcr3\")\nprint('max:',zcr3.max())\nprint('min:',zcr3.min())\nprint(\"-------------------------------\")\nzcr4 = librosa.feature.zero_crossing_rate(y4)\nprint(\"zcr4\")\nprint('max:',zcr4.max())\nprint('min:',zcr4.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.365935Z","iopub.execute_input":"2024-01-14T13:50:28.366218Z","iopub.status.idle":"2024-01-14T13:50:28.388570Z","shell.execute_reply.started":"2024-01-14T13:50:28.366194Z","shell.execute_reply":"2024-01-14T13:50:28.387723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zcr5 = librosa.feature.zero_crossing_rate(y5)\nprint(\"zcr5\")\nprint('max:',zcr5.max())\nprint('min:',zcr5.min())\nprint(\"-------------------------------\")\nzcr6 = librosa.feature.zero_crossing_rate(y6)\nprint(\"zcr6\")\nprint('max:',zcr6.max())\nprint('min:',zcr6.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.389720Z","iopub.execute_input":"2024-01-14T13:50:28.390024Z","iopub.status.idle":"2024-01-14T13:50:28.422416Z","shell.execute_reply.started":"2024-01-14T13:50:28.389999Z","shell.execute_reply":"2024-01-14T13:50:28.421553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zcr7 = librosa.feature.zero_crossing_rate(y7)\nprint(\"zcr7\")\nprint('max:',zcr7.max())\nprint('min:',zcr7.min())\nprint(\"-------------------------------\")\nzcr8 = librosa.feature.zero_crossing_rate(y8)\nprint(\"zcr8\")\nprint('max:',zcr8.max())\nprint('min:',zcr8.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.423511Z","iopub.execute_input":"2024-01-14T13:50:28.423782Z","iopub.status.idle":"2024-01-14T13:50:28.554075Z","shell.execute_reply.started":"2024-01-14T13:50:28.423759Z","shell.execute_reply":"2024-01-14T13:50:28.553151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zcr9 = librosa.feature.zero_crossing_rate(y9)\nprint(\"zcr9\")\nprint('max:',zcr9.max())\nprint('min:',zcr9.min())\nprint(\"-------------------------------\")\nzcr10 = librosa.feature.zero_crossing_rate(y10)\nprint(\"zcr10\")\nprint('max:',zcr10.max())\nprint('min:',zcr10.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.555435Z","iopub.execute_input":"2024-01-14T13:50:28.555791Z","iopub.status.idle":"2024-01-14T13:50:28.800743Z","shell.execute_reply.started":"2024-01-14T13:50:28.555758Z","shell.execute_reply":"2024-01-14T13:50:28.799815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"in 3 bird we see low range of zero crossing rate while others have same types so but we cant use this feature as factor because these are only two voices so we cannot use Zero Crossing Rate as a factor","metadata":{}},{"cell_type":"markdown","source":"**RMS ENERGY**","metadata":{}},{"cell_type":"code","source":"#energy (rms)\nenergy1 = librosa.feature.rms(y=y1)\nprint(energy1)\nprint('energy1')\nprint('max:',energy1.max())\nprint('min:',energy1.min())\nprint('mean:',energy1.mean())\nprint(\"----------------------------\")\nenergy2 = librosa.feature.rms(y=y2)\nprint('energy2')\nprint('max:',energy2.max())\nprint('min:',energy2.min())\nprint('mean:',energy2.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.802123Z","iopub.execute_input":"2024-01-14T13:50:28.802432Z","iopub.status.idle":"2024-01-14T13:50:28.817820Z","shell.execute_reply.started":"2024-01-14T13:50:28.802407Z","shell.execute_reply":"2024-01-14T13:50:28.816945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#energy (rms)\nenergy3 = librosa.feature.rms(y=y3)\nprint('energy3')\nprint('max:',energy3.max())\nprint('min:',energy3.min())\nprint('mean:',energy3.mean())\nprint(\"-------------------------------\")\nenergy4 = librosa.feature.rms(y=y4)\nprint('energy4')\nprint('max:',energy4.max())\nprint('min:',energy4.min())\nprint('mean:',energy4.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.818884Z","iopub.execute_input":"2024-01-14T13:50:28.819198Z","iopub.status.idle":"2024-01-14T13:50:28.830738Z","shell.execute_reply.started":"2024-01-14T13:50:28.819155Z","shell.execute_reply":"2024-01-14T13:50:28.829768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#energy (rms)\nenergy5 = librosa.feature.rms(y=y5)\nprint('energy5')\nprint('max:',energy5.max())\nprint('min:',energy5.min())\nprint('mean:',energy5.mean())\nprint(\"-------------------------------\")\nenergy6 = librosa.feature.rms(y=y6)\nprint('energy6')\nprint('max:',energy6.max())\nprint('min:',energy6.min())\nprint('mean:',energy6.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.833965Z","iopub.execute_input":"2024-01-14T13:50:28.834281Z","iopub.status.idle":"2024-01-14T13:50:28.846006Z","shell.execute_reply.started":"2024-01-14T13:50:28.834257Z","shell.execute_reply":"2024-01-14T13:50:28.845043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#energy (rms)\nenergy7 = librosa.feature.rms(y=y7)\nprint('energy7')\nprint('max:',energy7.max())\nprint('min:',energy7.min())\nprint('mean:',energy7.mean())\nprint(\"-------------------------------\")\nenergy8 = librosa.feature.rms(y=y8)\nprint('energy8')\nprint('max:',energy8.max())\nprint('min:',energy8.min())\nprint('mean:',energy8.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.847204Z","iopub.execute_input":"2024-01-14T13:50:28.847521Z","iopub.status.idle":"2024-01-14T13:50:28.882513Z","shell.execute_reply.started":"2024-01-14T13:50:28.847497Z","shell.execute_reply":"2024-01-14T13:50:28.881503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"energy9 = librosa.feature.rms(y=y9)\nprint('energy9')\nprint('max:',energy9.max())\nprint('min:',energy9.min())\nprint('mean:',energy9.mean())\nprint(\"-------------------------------\")\nenergy10 = librosa.feature.rms(y=y10)\nprint('energy10')\nprint('max:',energy10.max())\nprint('min:',energy10.min())\nprint('mean:',energy10.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.883746Z","iopub.execute_input":"2024-01-14T13:50:28.884083Z","iopub.status.idle":"2024-01-14T13:50:28.938763Z","shell.execute_reply.started":"2024-01-14T13:50:28.884055Z","shell.execute_reply":"2024-01-14T13:50:28.937783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Energy value ranges are always similar so cannot used as a distinguishable factor.","metadata":{}},{"cell_type":"markdown","source":"**SPECTRAL ROLL  OFF**","metadata":{}},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y1))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr1, roll_percent=0.85)\nprint(\"audio1 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.939895Z","iopub.execute_input":"2024-01-14T13:50:28.940198Z","iopub.status.idle":"2024-01-14T13:50:28.985997Z","shell.execute_reply.started":"2024-01-14T13:50:28.940154Z","shell.execute_reply":"2024-01-14T13:50:28.985046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y2))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr2, roll_percent=0.85)\nprint(\"audio2 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:28.987155Z","iopub.execute_input":"2024-01-14T13:50:28.987473Z","iopub.status.idle":"2024-01-14T13:50:29.049295Z","shell.execute_reply.started":"2024-01-14T13:50:28.987448Z","shell.execute_reply":"2024-01-14T13:50:29.048363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y3))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr3, roll_percent=0.85)\nprint(\"audio3 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.050674Z","iopub.execute_input":"2024-01-14T13:50:29.051038Z","iopub.status.idle":"2024-01-14T13:50:29.074722Z","shell.execute_reply.started":"2024-01-14T13:50:29.051003Z","shell.execute_reply":"2024-01-14T13:50:29.073814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y4))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr4, roll_percent=0.85)\nprint(\"audio4 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.075768Z","iopub.execute_input":"2024-01-14T13:50:29.076053Z","iopub.status.idle":"2024-01-14T13:50:29.110084Z","shell.execute_reply.started":"2024-01-14T13:50:29.076029Z","shell.execute_reply":"2024-01-14T13:50:29.109162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y5))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr5, roll_percent=0.85)\nprint(\"audio5 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.111416Z","iopub.execute_input":"2024-01-14T13:50:29.112061Z","iopub.status.idle":"2024-01-14T13:50:29.149480Z","shell.execute_reply.started":"2024-01-14T13:50:29.112025Z","shell.execute_reply":"2024-01-14T13:50:29.148461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y6))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr6, roll_percent=0.85)\nprint(\"audio6 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.150859Z","iopub.execute_input":"2024-01-14T13:50:29.151160Z","iopub.status.idle":"2024-01-14T13:50:29.193606Z","shell.execute_reply.started":"2024-01-14T13:50:29.151133Z","shell.execute_reply":"2024-01-14T13:50:29.192636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y7))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr7, roll_percent=0.85)\nprint(\"audio7 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.194737Z","iopub.execute_input":"2024-01-14T13:50:29.195022Z","iopub.status.idle":"2024-01-14T13:50:29.226148Z","shell.execute_reply.started":"2024-01-14T13:50:29.194998Z","shell.execute_reply":"2024-01-14T13:50:29.225239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y8))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr8, roll_percent=0.85)\nprint(\"audio8 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.227284Z","iopub.execute_input":"2024-01-14T13:50:29.227566Z","iopub.status.idle":"2024-01-14T13:50:29.444182Z","shell.execute_reply.started":"2024-01-14T13:50:29.227542Z","shell.execute_reply":"2024-01-14T13:50:29.443240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y9))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr9, roll_percent=0.85)\nprint(\"audio9 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.445374Z","iopub.execute_input":"2024-01-14T13:50:29.445694Z","iopub.status.idle":"2024-01-14T13:50:29.666987Z","shell.execute_reply.started":"2024-01-14T13:50:29.445668Z","shell.execute_reply":"2024-01-14T13:50:29.666019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spectral roll-off\nS, phase = librosa.magphase(librosa.stft(y10))\nrolloff = librosa.feature.spectral_rolloff(S=S, sr=sr10, roll_percent=0.85)\nprint(\"audio10 spectral rolloff:\",rolloff.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:29.668185Z","iopub.execute_input":"2024-01-14T13:50:29.668467Z","iopub.status.idle":"2024-01-14T13:50:29.948407Z","shell.execute_reply.started":"2024-01-14T13:50:29.668442Z","shell.execute_reply":"2024-01-14T13:50:29.947464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"raw","source":"Spectral roll off mean value can be used as a factor in audio 5 it lies in 5200 to 5900 ,audio 4 lies between 4300to 4800 , audio 3 lies between 2000-3000. for these 3 we can use this but we have to make more steps so we can ensure it.","metadata":{}},{"cell_type":"markdown","source":"**MFCCs****\n","metadata":{}},{"cell_type":"code","source":"mfcc1 = librosa.feature.mfcc(y=y1, sr=sr1)\nprint(mfcc1)\nprint(\"mfcc1\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc1, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc1, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:30.103675Z","iopub.execute_input":"2024-01-14T13:50:30.104512Z","iopub.status.idle":"2024-01-14T13:50:30.148214Z","shell.execute_reply.started":"2024-01-14T13:50:30.104478Z","shell.execute_reply":"2024-01-14T13:50:30.146884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc2 = librosa.feature.mfcc(y=y2, sr=sr2)\nprint(\"mfcc2\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc2, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc2, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:30.506266Z","iopub.execute_input":"2024-01-14T13:50:30.507186Z","iopub.status.idle":"2024-01-14T13:50:30.556720Z","shell.execute_reply.started":"2024-01-14T13:50:30.507125Z","shell.execute_reply":"2024-01-14T13:50:30.555397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc3 = librosa.feature.mfcc(y=y3, sr=sr3)\nprint(\"mfcc3\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc3, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc3, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:30.891289Z","iopub.execute_input":"2024-01-14T13:50:30.891634Z","iopub.status.idle":"2024-01-14T13:50:30.914752Z","shell.execute_reply.started":"2024-01-14T13:50:30.891598Z","shell.execute_reply":"2024-01-14T13:50:30.913563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc4 = librosa.feature.mfcc(y=y4, sr=sr4)\nprint(\"mfcc4\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc4, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc4, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:31.502098Z","iopub.execute_input":"2024-01-14T13:50:31.502483Z","iopub.status.idle":"2024-01-14T13:50:31.535776Z","shell.execute_reply.started":"2024-01-14T13:50:31.502455Z","shell.execute_reply":"2024-01-14T13:50:31.534549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc5 = librosa.feature.mfcc(y=y5, sr=sr5)\nprint(\"mfcc5\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc5, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc5, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:31.830336Z","iopub.execute_input":"2024-01-14T13:50:31.830694Z","iopub.status.idle":"2024-01-14T13:50:31.865184Z","shell.execute_reply.started":"2024-01-14T13:50:31.830666Z","shell.execute_reply":"2024-01-14T13:50:31.863823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc6 = librosa.feature.mfcc(y=y6, sr=sr6)\nprint(\"mfcc6\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc6, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc6, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:32.235591Z","iopub.execute_input":"2024-01-14T13:50:32.236424Z","iopub.status.idle":"2024-01-14T13:50:32.269920Z","shell.execute_reply.started":"2024-01-14T13:50:32.236391Z","shell.execute_reply":"2024-01-14T13:50:32.268549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc7 = librosa.feature.mfcc(y=y7, sr=sr7)\nprint(\"mfcc7\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc7, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc7, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:32.410473Z","iopub.execute_input":"2024-01-14T13:50:32.411132Z","iopub.status.idle":"2024-01-14T13:50:32.440556Z","shell.execute_reply.started":"2024-01-14T13:50:32.411101Z","shell.execute_reply":"2024-01-14T13:50:32.439325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc8 = librosa.feature.mfcc(y=y8, sr=sr8)\nprint(\"mfcc8\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc8, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc8, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:32.619677Z","iopub.execute_input":"2024-01-14T13:50:32.620379Z","iopub.status.idle":"2024-01-14T13:50:32.763505Z","shell.execute_reply.started":"2024-01-14T13:50:32.620344Z","shell.execute_reply":"2024-01-14T13:50:32.762132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc9 = librosa.feature.mfcc(y=y9, sr=sr9)\nprint(\"mfcc9\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc9, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc9, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:32.856214Z","iopub.execute_input":"2024-01-14T13:50:32.856867Z","iopub.status.idle":"2024-01-14T13:50:33.029400Z","shell.execute_reply.started":"2024-01-14T13:50:32.856814Z","shell.execute_reply":"2024-01-14T13:50:33.028015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mfcc10 = librosa.feature.mfcc(y=y10, sr=sr10)\nprint(\"mfcc10\")\nprint(\"max of mean-mfcc:\",np.mean(mfcc10, axis=1).max())\nprint(\"min of mean-mfcc:\",np.mean(mfcc10, axis=1).min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:33.032278Z","iopub.execute_input":"2024-01-14T13:50:33.033198Z","iopub.status.idle":"2024-01-14T13:50:33.267600Z","shell.execute_reply.started":"2024-01-14T13:50:33.033137Z","shell.execute_reply":"2024-01-14T13:50:33.264324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Spectral Flux\n**","metadata":{}},{"cell_type":"markdown","source":"MFCC value are almost in a similar range so that we cannot  used it .","metadata":{}},{"cell_type":"code","source":"#spectral flux\nonset_env = librosa.onset.onset_strength(y=y1, sr=sr1)\nprint(\"spectral flux for Audio1\")\nprint(onset_env)\nprint(onset_env.mean())\nprint(\"----------------------------------------\")\nonset_env = librosa.onset.onset_strength(y=y2, sr=sr2)\nprint(\"spectral flux for Audio2\")\nprint(onset_env.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:34.419687Z","iopub.execute_input":"2024-01-14T13:50:34.420787Z","iopub.status.idle":"2024-01-14T13:50:34.546749Z","shell.execute_reply.started":"2024-01-14T13:50:34.420744Z","shell.execute_reply":"2024-01-14T13:50:34.545683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"onset_env = librosa.onset.onset_strength(y=y3, sr=sr3)\nprint(\"spectral flux for Audio3\")\nprint(onset_env.mean())\nprint(\"----------------------------------------\")\nonset_env = librosa.onset.onset_strength(y=y4, sr=sr4)\nprint(\"spectral flux for Audio4\")\nprint(onset_env.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:34.632839Z","iopub.execute_input":"2024-01-14T13:50:34.634219Z","iopub.status.idle":"2024-01-14T13:50:34.768284Z","shell.execute_reply.started":"2024-01-14T13:50:34.634147Z","shell.execute_reply":"2024-01-14T13:50:34.766869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"onset_env = librosa.onset.onset_strength(y=y5, sr=sr5)\nprint(\"spectral flux for Audio5\")\nprint(onset_env.mean())\nprint(\"----------------------------------------\")\nonset_env = librosa.onset.onset_strength(y=y6, sr=sr6)\nprint(\"spectral flux for Audio6\")\nprint(onset_env.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:34.820224Z","iopub.execute_input":"2024-01-14T13:50:34.820740Z","iopub.status.idle":"2024-01-14T13:50:34.947072Z","shell.execute_reply.started":"2024-01-14T13:50:34.820696Z","shell.execute_reply":"2024-01-14T13:50:34.946237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"onset_env = librosa.onset.onset_strength(y=y7, sr=sr7)\nprint(\"spectral flux for Audio7\")\nprint(onset_env.mean())\nprint(\"----------------------------------------\")\nonset_env = librosa.onset.onset_strength(y=y8, sr=sr8)\nprint(\"spectral flux for Audio6\")\nprint(onset_env.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:35.027236Z","iopub.execute_input":"2024-01-14T13:50:35.027813Z","iopub.status.idle":"2024-01-14T13:50:35.354442Z","shell.execute_reply.started":"2024-01-14T13:50:35.027780Z","shell.execute_reply":"2024-01-14T13:50:35.352999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"onset_env = librosa.onset.onset_strength(y=y9, sr=sr9)\nprint(\"spectral flux for Audio9\")\nprint(onset_env.mean())\nprint(\"----------------------------------------\")\nonset_env = librosa.onset.onset_strength(y=y10, sr=sr10)\nprint(\"spectral flux for Audio10\")\nprint(onset_env.mean())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:35.363254Z","iopub.execute_input":"2024-01-14T13:50:35.368208Z","iopub.status.idle":"2024-01-14T13:50:35.831216Z","shell.execute_reply.started":"2024-01-14T13:50:35.368137Z","shell.execute_reply":"2024-01-14T13:50:35.829965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Spectogram**","metadata":{}},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y1))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:36.552218Z","iopub.execute_input":"2024-01-14T13:50:36.552882Z","iopub.status.idle":"2024-01-14T13:50:36.582805Z","shell.execute_reply.started":"2024-01-14T13:50:36.552849Z","shell.execute_reply":"2024-01-14T13:50:36.581874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y2))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:37.315654Z","iopub.execute_input":"2024-01-14T13:50:37.316340Z","iopub.status.idle":"2024-01-14T13:50:37.355938Z","shell.execute_reply.started":"2024-01-14T13:50:37.316306Z","shell.execute_reply":"2024-01-14T13:50:37.355045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y3))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:39.601115Z","iopub.execute_input":"2024-01-14T13:50:39.601950Z","iopub.status.idle":"2024-01-14T13:50:39.617712Z","shell.execute_reply.started":"2024-01-14T13:50:39.601920Z","shell.execute_reply":"2024-01-14T13:50:39.616908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y4))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:40.543913Z","iopub.execute_input":"2024-01-14T13:50:40.544759Z","iopub.status.idle":"2024-01-14T13:50:40.570453Z","shell.execute_reply.started":"2024-01-14T13:50:40.544728Z","shell.execute_reply":"2024-01-14T13:50:40.569504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y5))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:40.889053Z","iopub.execute_input":"2024-01-14T13:50:40.889711Z","iopub.status.idle":"2024-01-14T13:50:40.916793Z","shell.execute_reply.started":"2024-01-14T13:50:40.889676Z","shell.execute_reply":"2024-01-14T13:50:40.915861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y6))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:41.787429Z","iopub.execute_input":"2024-01-14T13:50:41.787780Z","iopub.status.idle":"2024-01-14T13:50:41.813051Z","shell.execute_reply.started":"2024-01-14T13:50:41.787754Z","shell.execute_reply":"2024-01-14T13:50:41.812147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y7))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:42.080554Z","iopub.execute_input":"2024-01-14T13:50:42.081182Z","iopub.status.idle":"2024-01-14T13:50:42.101826Z","shell.execute_reply.started":"2024-01-14T13:50:42.081141Z","shell.execute_reply":"2024-01-14T13:50:42.100940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y8))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:42.930256Z","iopub.execute_input":"2024-01-14T13:50:42.930656Z","iopub.status.idle":"2024-01-14T13:50:43.052114Z","shell.execute_reply.started":"2024-01-14T13:50:42.930625Z","shell.execute_reply":"2024-01-14T13:50:43.051195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y9))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:43.119042Z","iopub.execute_input":"2024-01-14T13:50:43.119844Z","iopub.status.idle":"2024-01-14T13:50:43.240038Z","shell.execute_reply.started":"2024-01-14T13:50:43.119812Z","shell.execute_reply":"2024-01-14T13:50:43.239044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spec = np.abs(librosa.stft(y10))\nmean_per_bin = np.mean(spec, axis=1)\nprint(mean_per_bin.max())\nprint(mean_per_bin.min())","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:50:43.869723Z","iopub.execute_input":"2024-01-14T13:50:43.870539Z","iopub.status.idle":"2024-01-14T13:50:44.015105Z","shell.execute_reply.started":"2024-01-14T13:50:43.870505Z","shell.execute_reply":"2024-01-14T13:50:44.014128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa.display","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:09.874623Z","iopub.execute_input":"2024-01-14T13:51:09.875001Z","iopub.status.idle":"2024-01-14T13:51:09.880628Z","shell.execute_reply.started":"2024-01-14T13:51:09.874971Z","shell.execute_reply":"2024-01-14T13:51:09.879681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Spectrogram for Audio 1\nD1 = librosa.amplitude_to_db(np.abs(librosa.stft(y1)), ref=np.max)\n\n# Spectrogram for Audio 2\nD2 = librosa.amplitude_to_db(np.abs(librosa.stft(y2)), ref=np.max)\n\n# Create subplots\nplt.figure(figsize=(16, 4))\n\n# Plot for Audio 1\nplt.subplot(1, 2, 1)\nlibrosa.display.specshow(D1, sr=sr1, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 1')\n\n# Plot for Audio 2\nplt.subplot(1, 2, 2)\nlibrosa.display.specshow(D2, sr=sr2, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 2')\n\n# Adjust layout for better visualization\nplt.tight_layout()\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:10.543031Z","iopub.execute_input":"2024-01-14T13:51:10.543417Z","iopub.status.idle":"2024-01-14T13:51:12.961466Z","shell.execute_reply.started":"2024-01-14T13:51:10.543388Z","shell.execute_reply":"2024-01-14T13:51:12.960544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D1 = librosa.amplitude_to_db(np.abs(librosa.stft(y3)), ref=np.max)\nD2 = librosa.amplitude_to_db(np.abs(librosa.stft(y4)), ref=np.max)\n\nplt.figure(figsize=(16, 4))\n\nplt.subplot(1, 2, 1)\nlibrosa.display.specshow(D1, sr=sr3, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 3')\n\nplt.subplot(1, 2, 2)\nlibrosa.display.specshow(D2, sr=sr4, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 4')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:12.963250Z","iopub.execute_input":"2024-01-14T13:51:12.963583Z","iopub.status.idle":"2024-01-14T13:51:14.446011Z","shell.execute_reply.started":"2024-01-14T13:51:12.963552Z","shell.execute_reply":"2024-01-14T13:51:14.445060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D1 = librosa.amplitude_to_db(np.abs(librosa.stft(y5)), ref=np.max)\nD2 = librosa.amplitude_to_db(np.abs(librosa.stft(y6)), ref=np.max)\n\nplt.figure(figsize=(16, 4))\n\nplt.subplot(1, 2, 1)\nlibrosa.display.specshow(D1, sr=sr5, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 5')\n\nplt.subplot(1, 2, 2)\nlibrosa.display.specshow(D2, sr=sr6, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 6')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:16.126516Z","iopub.execute_input":"2024-01-14T13:51:16.127276Z","iopub.status.idle":"2024-01-14T13:51:18.005184Z","shell.execute_reply.started":"2024-01-14T13:51:16.127242Z","shell.execute_reply":"2024-01-14T13:51:18.004238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D1 = librosa.amplitude_to_db(np.abs(librosa.stft(y7)), ref=np.max)\nD2 = librosa.amplitude_to_db(np.abs(librosa.stft(y8)), ref=np.max)\n\nplt.figure(figsize=(16, 4))\n\nplt.subplot(1, 2, 1)\nlibrosa.display.specshow(D1, sr=sr7, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 7')\n\nplt.subplot(1, 2, 2)\nlibrosa.display.specshow(D2, sr=sr8, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 8')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:18.006866Z","iopub.execute_input":"2024-01-14T13:51:18.007211Z","iopub.status.idle":"2024-01-14T13:51:22.633395Z","shell.execute_reply.started":"2024-01-14T13:51:18.007161Z","shell.execute_reply":"2024-01-14T13:51:22.632429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D1 = librosa.amplitude_to_db(np.abs(librosa.stft(y9)), ref=np.max)\nD2 = librosa.amplitude_to_db(np.abs(librosa.stft(y10)), ref=np.max)\n\nplt.figure(figsize=(16, 4))\n\nplt.subplot(1, 2, 1)\nlibrosa.display.specshow(D1, sr=sr9, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 9')\n\nplt.subplot(1, 2, 2)\nlibrosa.display.specshow(D2, sr=sr10, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Audio 10')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:51:22.634646Z","iopub.execute_input":"2024-01-14T13:51:22.634968Z","iopub.status.idle":"2024-01-14T13:51:30.706889Z","shell.execute_reply.started":"2024-01-14T13:51:22.634940Z","shell.execute_reply":"2024-01-14T13:51:30.705946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**MODEL**","metadata":{}},{"cell_type":"code","source":"import cv2\nimport audioread\nimport logging\nimport os\nimport random\nimport time\nimport warnings\n\nimport numpy as np\nimport pandas as pd\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\n\nfrom fastprogress import progress_bar\nfrom sklearn.metrics import f1_score\nfrom torchvision import models","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:35.611128Z","iopub.execute_input":"2024-01-14T13:44:35.612042Z","iopub.status.idle":"2024-01-14T13:44:40.277520Z","shell.execute_reply.started":"2024-01-14T13:44:35.612009Z","shell.execute_reply":"2024-01-14T13:44:40.276540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"****UTILITIES","metadata":{}},{"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)  # type: ignore\n    torch.backends.cudnn.deterministic = True  # type: ignore\n    torch.backends.cudnn.benchmark = True  # type: ignore\n    \n    \ndef 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    \n@contextmanager\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)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.279102Z","iopub.execute_input":"2024-01-14T13:44:40.279569Z","iopub.status.idle":"2024-01-14T13:44:40.289531Z","shell.execute_reply.started":"2024-01-14T13:44:40.279543Z","shell.execute_reply":"2024-01-14T13:44:40.288722Z"},"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-14T13:44:40.290733Z","iopub.execute_input":"2024-01-14T13:44:40.290993Z","iopub.status.idle":"2024-01-14T13:44:40.309738Z","shell.execute_reply.started":"2024-01-14T13:44:40.290970Z","shell.execute_reply":"2024-01-14T13:44:40.308938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Data Loading","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"TARGET_SR = 32000\nTEST = Path(\"../input/birdsong-recognition/test_audio\").exists()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.312277Z","iopub.execute_input":"2024-01-14T13:44:40.312903Z","iopub.status.idle":"2024-01-14T13:44:40.317485Z","shell.execute_reply.started":"2024-01-14T13:44:40.312866Z","shell.execute_reply":"2024-01-14T13:44:40.316588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if TEST:\n    DATA_DIR = Path(\"../input/birdsong-recognition/\")\nelse:\n    # dataset created by @shonenkov, thanks!\n    DATA_DIR = Path(\"../input/birdcall-check/\")\n    \n\ntest = pd.read_csv(DATA_DIR / \"test.csv\")\ntest_audio = DATA_DIR / \"test_audio\"\n\n\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.318639Z","iopub.execute_input":"2024-01-14T13:44:40.318971Z","iopub.status.idle":"2024-01-14T13:44:40.364122Z","shell.execute_reply.started":"2024-01-14T13:44:40.318941Z","shell.execute_reply":"2024-01-14T13:44:40.363142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv(\"../input/birdsong-recognition/sample_submission.csv\")\nsub.to_csv(\"submission.csv\", index=False)  # this will be overwritten if everything goes well","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.365295Z","iopub.execute_input":"2024-01-14T13:44:40.365590Z","iopub.status.idle":"2024-01-14T13:44:40.375983Z","shell.execute_reply.started":"2024-01-14T13:44:40.365566Z","shell.execute_reply":"2024-01-14T13:44:40.375098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ResNet(nn.Module):\n    def __init__(self, base_model_name: str, pretrained=False,\n                 num_classes=264):\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\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        return {\n            \"logits\": x,\n            \"multiclass_proba\": multiclass_proba,\n            \"multilabel_proba\": multilabel_proba\n        }\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.377131Z","iopub.execute_input":"2024-01-14T13:44:40.377428Z","iopub.status.idle":"2024-01-14T13:44:40.386878Z","shell.execute_reply.started":"2024-01-14T13:44:40.377404Z","shell.execute_reply":"2024-01-14T13:44:40.385971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**PARAMETER**","metadata":{}},{"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\": 20,\n    \"fmax\": 16000\n}\n\nweights_path = \"/kaggle/input/birdcall-resnet50-init-weights/best.pth\"","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.387944Z","iopub.execute_input":"2024-01-14T13:44:40.388285Z","iopub.status.idle":"2024-01-14T13:44:40.399716Z","shell.execute_reply.started":"2024-01-14T13:44:40.388258Z","shell.execute_reply":"2024-01-14T13:44:40.398834Z"},"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)\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()}\n#for bird_name, label in INV_BIRD_CODE.items():\n#    print(f\"{bird_name}:{label}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.401081Z","iopub.execute_input":"2024-01-14T13:44:40.401388Z","iopub.status.idle":"2024-01-14T13:44:40.909888Z","shell.execute_reply.started":"2024-01-14T13:44:40.401364Z","shell.execute_reply":"2024-01-14T13:44:40.909075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"****DEFINE DATASET****","metadata":{}},{"cell_type":"code","source":"def mono_to_color(X: np.ndarray,\n                  mean=None,\n                  std=None,\n                  norm_max=None,\n                  norm_min=None,\n                  eps=1e-6):\n    \n    # Stack X as [X,X,X]\n    X = np.stack([X, X, X], axis=-1)\n\n    # Standardize\n    mean = mean or X.mean()\n    X = X - mean\n    std = std or X.std()\n    Xstd = X / (std + eps)\n    _min, _max = Xstd.min(), Xstd.max()\n    norm_max = norm_max or _max\n    norm_min = norm_min or _min\n    if (_max - _min) > eps:\n        # Normalize to [0, 255]\n        V = Xstd\n        V[V < norm_min] = norm_min\n        V[V > norm_max] = norm_max\n        V = 255 * (V - norm_min) / (norm_max - norm_min)\n        V = V.astype(np.uint8)\n    else:\n        # Just zero\n        V = np.zeros_like(Xstd, dtype=np.uint8)\n    return V\n\n\nclass TestDataset(data.Dataset):\n    def __init__(self, df: pd.DataFrame, clip: np.ndarray,\n                 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        sample = self.df.loc[idx, :]\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            images = []\n            while len_y > start:\n                y_batch = y[start:end].astype(np.float32)\n                if len(y_batch) != (SR * 5):\n                    break\n                start = end\n                end = end + SR * 5\n                \n                melspec = librosa.feature.melspectrogram(y_batch,\n                                                         sr=SR,\n                                                         **self.melspectrogram_parameters)\n                melspec = librosa.power_to_db(melspec).astype(np.float32)\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                images.append(image)\n            images = np.asarray(images)\n            return images, row_id, site\n        else:\n            end_seconds = int(sample.seconds)\n            start_seconds = int(end_seconds - 5)\n            \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, sr=SR, **self.melspectrogram_parameters)\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","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.913707Z","iopub.execute_input":"2024-01-14T13:44:40.914122Z","iopub.status.idle":"2024-01-14T13:44:40.931846Z","shell.execute_reply.started":"2024-01-14T13:44:40.914094Z","shell.execute_reply":"2024-01-14T13:44:40.930903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**PREDICTION LOOP**","metadata":{}},{"cell_type":"code","source":"def get_model(config: dict, weights_path: str):\n    model = ResNet(**config)\n    checkpoint = torch.load(weights_path)\n    model.load_state_dict(checkpoint[\"model_state_dict\"])\n    device = torch.device(\"cuda\")\n    model.to(device)\n    model.eval()\n    return model","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.932995Z","iopub.execute_input":"2024-01-14T13:44:40.933330Z","iopub.status.idle":"2024-01-14T13:44:40.944821Z","shell.execute_reply.started":"2024-01-14T13:44:40.933304Z","shell.execute_reply":"2024-01-14T13:44:40.943890Z"},"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    dataset = TestDataset(df=test_df, \n                          clip=clip,\n                          img_size=224,\n                          melspectrogram_parameters=mel_params)\n    loader = data.DataLoader(dataset, batch_size=1, shuffle=False)\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n    \n    model.eval()\n    prediction_dict = {}\n    for image, row_id, site in progress_bar(loader):\n        site = site[0]\n        row_id = row_id[0]\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            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            for batch_i in range(n_iter):\n                batch = image[batch_i * batch_size:(batch_i + 1) * batch_size]\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                    proba = prediction[\"multilabel_proba\"].detach().cpu().numpy()\n                    \n                events = proba >= threshold\n                for i in range(len(events)):\n                    event = events[i, :]\n                    labels = np.argwhere(event).reshape(-1).tolist()\n                    for label in labels:\n                        all_events.add(label)\n                        \n            labels = list(all_events)\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    return prediction_dict","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.946259Z","iopub.execute_input":"2024-01-14T13:44:40.946551Z","iopub.status.idle":"2024-01-14T13:44:40.961184Z","shell.execute_reply.started":"2024-01-14T13:44:40.946517Z","shell.execute_reply":"2024-01-14T13:44:40.960357Z"},"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    model = get_model(model_config, weights_path)\n    unique_audio_id = test_df.audio_id.unique()\n\n    warnings.filterwarnings(\"ignore\")\n    prediction_dfs = []\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        \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        prediction_df = pd.DataFrame({\n            \"row_id\": row_id,\n            \"birds\": birds\n        })\n        prediction_dfs.append(prediction_df)\n    \n    prediction_df = pd.concat(prediction_dfs, axis=0, sort=False).reset_index(drop=True)\n    return prediction_df","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.962208Z","iopub.execute_input":"2024-01-14T13:44:40.964449Z","iopub.status.idle":"2024-01-14T13:44:40.974909Z","shell.execute_reply.started":"2024-01-14T13:44:40.964422Z","shell.execute_reply":"2024-01-14T13:44:40.974136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**PREDICTION**","metadata":{}},{"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)\nsubmission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:44:40.975945Z","iopub.execute_input":"2024-01-14T13:44:40.976235Z","iopub.status.idle":"2024-01-14T13:45:24.609195Z","shell.execute_reply.started":"2024-01-14T13:44:40.976208Z","shell.execute_reply":"2024-01-14T13:45:24.607869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:45:24.611404Z","iopub.execute_input":"2024-01-14T13:45:24.612608Z","iopub.status.idle":"2024-01-14T13:45:24.632705Z","shell.execute_reply.started":"2024-01-14T13:45:24.612561Z","shell.execute_reply":"2024-01-14T13:45:24.631309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.row_id.unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:45:24.634693Z","iopub.execute_input":"2024-01-14T13:45:24.635500Z","iopub.status.idle":"2024-01-14T13:45:24.648011Z","shell.execute_reply.started":"2024-01-14T13:45:24.635453Z","shell.execute_reply":"2024-01-14T13:45:24.646839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.read_csv(\"/kaggle/working/submission.csv\")\n\n# Remove trailing numbers and duplicates from 'row_id' column\nsubmission_df['row_id'] = submission_df['row_id'].replace(to_replace=r'_[0-9]+$', value='', regex=True)\nsubmission_df = submission_df.drop_duplicates()\nrows = submission_df[submission_df.duplicated(subset=['row_id'], keep=False) & (submission_df['birds'] == 'nocall')]\nno_duplicates = submission_df.drop(rows.index)\n\nno_duplicates = no_duplicates.reset_index(drop=True)\n\nno_duplicates","metadata":{"execution":{"iopub.status.busy":"2024-01-14T13:45:24.650305Z","iopub.execute_input":"2024-01-14T13:45:24.651165Z","iopub.status.idle":"2024-01-14T13:45:24.683551Z","shell.execute_reply.started":"2024-01-14T13:45:24.651106Z","shell.execute_reply":"2024-01-14T13:45:24.682608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}