{"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424},{"sourceId":1264575,"sourceType":"datasetVersion","datasetId":725893}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.12"},"papermill":{"default_parameters":{},"duration":120.406682,"end_time":"2024-01-11T17:13:43.555077","environment_variables":{},"exception":true,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-01-11T17:11:43.148395","version":"2.4.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-01-11T17:11:47.40018Z","iopub.status.busy":"2024-01-11T17:11:47.39895Z","iopub.status.idle":"2024-01-11T17:11:51.482978Z","shell.execute_reply":"2024-01-11T17:11:51.481863Z"},"papermill":{"duration":4.11922,"end_time":"2024-01-11T17:11:51.487685","exception":false,"start_time":"2024-01-11T17:11:47.368465","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"papermill":{"duration":0.060131,"end_time":"2024-01-11T17:11:51.610403","exception":false,"start_time":"2024-01-11T17:11:51.550272","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"","metadata":{"papermill":{"duration":0.145422,"end_time":"2024-01-11T17:11:51.815282","exception":false,"start_time":"2024-01-11T17:11:51.66986","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"EDA","metadata":{"papermill":{"duration":0.059467,"end_time":"2024-01-11T17:11:51.934522","exception":false,"start_time":"2024-01-11T17:11:51.875055","status":"completed"},"tags":[]}},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:52.06142Z","iopub.status.busy":"2024-01-11T17:11:52.060902Z","iopub.status.idle":"2024-01-11T17:11:52.641596Z","shell.execute_reply":"2024-01-11T17:11:52.640278Z"},"papermill":{"duration":0.647109,"end_time":"2024-01-11T17:11:52.644687","exception":false,"start_time":"2024-01-11T17:11:51.997578","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:52.770888Z","iopub.status.busy":"2024-01-11T17:11:52.769923Z","iopub.status.idle":"2024-01-11T17:11:54.446633Z","shell.execute_reply":"2024-01-11T17:11:54.445667Z"},"papermill":{"duration":1.74356,"end_time":"2024-01-11T17:11:54.449404","exception":false,"start_time":"2024-01-11T17:11:52.705844","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\npd.set_option('display.expand_frame_repr', False)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:54.573222Z","iopub.status.busy":"2024-01-11T17:11:54.572436Z","iopub.status.idle":"2024-01-11T17:11:54.577184Z","shell.execute_reply":"2024-01-11T17:11:54.576174Z"},"papermill":{"duration":0.069478,"end_time":"2024-01-11T17:11:54.579452","exception":false,"start_time":"2024-01-11T17:11:54.509974","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:54.707604Z","iopub.status.busy":"2024-01-11T17:11:54.706824Z","iopub.status.idle":"2024-01-11T17:11:54.714102Z","shell.execute_reply":"2024-01-11T17:11:54.713156Z"},"papermill":{"duration":0.075785,"end_time":"2024-01-11T17:11:54.71634","exception":false,"start_time":"2024-01-11T17:11:54.640555","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:54.841341Z","iopub.status.busy":"2024-01-11T17:11:54.840865Z","iopub.status.idle":"2024-01-11T17:11:54.90989Z","shell.execute_reply":"2024-01-11T17:11:54.908652Z"},"papermill":{"duration":0.134959,"end_time":"2024-01-11T17:11:54.912995","exception":false,"start_time":"2024-01-11T17:11:54.778036","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns_with_nulls = df.columns[df.isnull().any()]\nprint(columns_with_nulls)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.038531Z","iopub.status.busy":"2024-01-11T17:11:55.038094Z","iopub.status.idle":"2024-01-11T17:11:55.077099Z","shell.execute_reply":"2024-01-11T17:11:55.075899Z"},"papermill":{"duration":0.106362,"end_time":"2024-01-11T17:11:55.07975","exception":false,"start_time":"2024-01-11T17:11:54.973388","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.215839Z","iopub.status.busy":"2024-01-11T17:11:55.215437Z","iopub.status.idle":"2024-01-11T17:11:55.221885Z","shell.execute_reply":"2024-01-11T17:11:55.221011Z"},"papermill":{"duration":0.084108,"end_time":"2024-01-11T17:11:55.223807","exception":false,"start_time":"2024-01-11T17:11:55.139699","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.348052Z","iopub.status.busy":"2024-01-11T17:11:55.347595Z","iopub.status.idle":"2024-01-11T17:11:55.376832Z","shell.execute_reply":"2024-01-11T17:11:55.375978Z"},"papermill":{"duration":0.094675,"end_time":"2024-01-11T17:11:55.378859","exception":false,"start_time":"2024-01-11T17:11:55.284184","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.50289Z","iopub.status.busy":"2024-01-11T17:11:55.502438Z","iopub.status.idle":"2024-01-11T17:11:55.509335Z","shell.execute_reply":"2024-01-11T17:11:55.508449Z"},"papermill":{"duration":0.072583,"end_time":"2024-01-11T17:11:55.512031","exception":false,"start_time":"2024-01-11T17:11:55.439448","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.634923Z","iopub.status.busy":"2024-01-11T17:11:55.6345Z","iopub.status.idle":"2024-01-11T17:11:55.64296Z","shell.execute_reply":"2024-01-11T17:11:55.641535Z"},"papermill":{"duration":0.072495,"end_time":"2024-01-11T17:11:55.645298","exception":false,"start_time":"2024-01-11T17:11:55.572803","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.768393Z","iopub.status.busy":"2024-01-11T17:11:55.767835Z","iopub.status.idle":"2024-01-11T17:11:55.778258Z","shell.execute_reply":"2024-01-11T17:11:55.777165Z"},"papermill":{"duration":0.074556,"end_time":"2024-01-11T17:11:55.780414","exception":false,"start_time":"2024-01-11T17:11:55.705858","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].fillna('no', inplace=True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:55.904305Z","iopub.status.busy":"2024-01-11T17:11:55.903903Z","iopub.status.idle":"2024-01-11T17:11:55.913668Z","shell.execute_reply":"2024-01-11T17:11:55.912608Z"},"papermill":{"duration":0.075082,"end_time":"2024-01-11T17:11:55.915806","exception":false,"start_time":"2024-01-11T17:11:55.840724","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.040612Z","iopub.status.busy":"2024-01-11T17:11:56.040201Z","iopub.status.idle":"2024-01-11T17:11:56.048695Z","shell.execute_reply":"2024-01-11T17:11:56.047584Z"},"papermill":{"duration":0.074459,"end_time":"2024-01-11T17:11:56.050987","exception":false,"start_time":"2024-01-11T17:11:55.976528","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\ndf['playback_used_encoded'] = le.fit_transform(df['playback_used'])\nprint(df[['playback_used', 'playback_used_encoded']])","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.176933Z","iopub.status.busy":"2024-01-11T17:11:56.176426Z","iopub.status.idle":"2024-01-11T17:11:56.197163Z","shell.execute_reply":"2024-01-11T17:11:56.195969Z"},"papermill":{"duration":0.086508,"end_time":"2024-01-11T17:11:56.19958","exception":false,"start_time":"2024-01-11T17:11:56.113072","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.326172Z","iopub.status.busy":"2024-01-11T17:11:56.32575Z","iopub.status.idle":"2024-01-11T17:11:56.351504Z","shell.execute_reply":"2024-01-11T17:11:56.350355Z"},"papermill":{"duration":0.092829,"end_time":"2024-01-11T17:11:56.353672","exception":false,"start_time":"2024-01-11T17:11:56.260843","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('playback_used', axis=1, inplace=True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.478214Z","iopub.status.busy":"2024-01-11T17:11:56.477787Z","iopub.status.idle":"2024-01-11T17:11:56.499107Z","shell.execute_reply":"2024-01-11T17:11:56.497895Z"},"papermill":{"duration":0.08645,"end_time":"2024-01-11T17:11:56.501518","exception":false,"start_time":"2024-01-11T17:11:56.415068","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.629725Z","iopub.status.busy":"2024-01-11T17:11:56.62919Z","iopub.status.idle":"2024-01-11T17:11:56.661189Z","shell.execute_reply":"2024-01-11T17:11:56.65995Z"},"papermill":{"duration":0.100499,"end_time":"2024-01-11T17:11:56.6638","exception":false,"start_time":"2024-01-11T17:11:56.563301","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ebird_code'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.794418Z","iopub.status.busy":"2024-01-11T17:11:56.794014Z","iopub.status.idle":"2024-01-11T17:11:56.803864Z","shell.execute_reply":"2024-01-11T17:11:56.802701Z"},"papermill":{"duration":0.078641,"end_time":"2024-01-11T17:11:56.806439","exception":false,"start_time":"2024-01-11T17:11:56.727798","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ebird_code'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:56.934595Z","iopub.status.busy":"2024-01-11T17:11:56.93376Z","iopub.status.idle":"2024-01-11T17:11:56.942179Z","shell.execute_reply":"2024-01-11T17:11:56.941114Z"},"papermill":{"duration":0.075593,"end_time":"2024-01-11T17:11:56.944537","exception":false,"start_time":"2024-01-11T17:11:56.868944","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.07342Z","iopub.status.busy":"2024-01-11T17:11:57.072964Z","iopub.status.idle":"2024-01-11T17:11:57.082599Z","shell.execute_reply":"2024-01-11T17:11:57.081307Z"},"papermill":{"duration":0.077029,"end_time":"2024-01-11T17:11:57.085288","exception":false,"start_time":"2024-01-11T17:11:57.008259","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'] = df['channels'].astype(str).str[0].astype(int)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.213336Z","iopub.status.busy":"2024-01-11T17:11:57.212903Z","iopub.status.idle":"2024-01-11T17:11:57.234061Z","shell.execute_reply":"2024-01-11T17:11:57.232957Z"},"papermill":{"duration":0.088048,"end_time":"2024-01-11T17:11:57.236522","exception":false,"start_time":"2024-01-11T17:11:57.148474","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.365518Z","iopub.status.busy":"2024-01-11T17:11:57.365118Z","iopub.status.idle":"2024-01-11T17:11:57.373733Z","shell.execute_reply":"2024-01-11T17:11:57.372895Z"},"papermill":{"duration":0.07632,"end_time":"2024-01-11T17:11:57.376146","exception":false,"start_time":"2024-01-11T17:11:57.299826","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.503562Z","iopub.status.busy":"2024-01-11T17:11:57.503017Z","iopub.status.idle":"2024-01-11T17:11:57.512429Z","shell.execute_reply":"2024-01-11T17:11:57.511351Z"},"papermill":{"duration":0.076354,"end_time":"2024-01-11T17:11:57.514669","exception":false,"start_time":"2024-01-11T17:11:57.438315","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.641349Z","iopub.status.busy":"2024-01-11T17:11:57.640963Z","iopub.status.idle":"2024-01-11T17:11:57.650521Z","shell.execute_reply":"2024-01-11T17:11:57.649442Z"},"papermill":{"duration":0.076125,"end_time":"2024-01-11T17:11:57.653136","exception":false,"start_time":"2024-01-11T17:11:57.577011","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year'] = df['date'].apply(lambda x: x.split('-')[0]).astype(int)\ndf['month'] = df['date'].apply(lambda x: x.split('-')[1]).astype(int)\ndf['day_of_month'] = df['date'].apply(lambda x: x.split('-')[2]).astype(int)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.787552Z","iopub.status.busy":"2024-01-11T17:11:57.78667Z","iopub.status.idle":"2024-01-11T17:11:57.831667Z","shell.execute_reply":"2024-01-11T17:11:57.830262Z"},"papermill":{"duration":0.118426,"end_time":"2024-01-11T17:11:57.835187","exception":false,"start_time":"2024-01-11T17:11:57.716761","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('date', axis=1, inplace=True)\ndf.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:57.973156Z","iopub.status.busy":"2024-01-11T17:11:57.972321Z","iopub.status.idle":"2024-01-11T17:11:58.016044Z","shell.execute_reply":"2024-01-11T17:11:58.014836Z"},"papermill":{"duration":0.116989,"end_time":"2024-01-11T17:11:58.018594","exception":false,"start_time":"2024-01-11T17:11:57.901605","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.146165Z","iopub.status.busy":"2024-01-11T17:11:58.145062Z","iopub.status.idle":"2024-01-11T17:11:58.190532Z","shell.execute_reply":"2024-01-11T17:11:58.189739Z"},"papermill":{"duration":0.112148,"end_time":"2024-01-11T17:11:58.193269","exception":false,"start_time":"2024-01-11T17:11:58.081121","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.322328Z","iopub.status.busy":"2024-01-11T17:11:58.321282Z","iopub.status.idle":"2024-01-11T17:11:58.329745Z","shell.execute_reply":"2024-01-11T17:11:58.328969Z"},"papermill":{"duration":0.074968,"end_time":"2024-01-11T17:11:58.331613","exception":false,"start_time":"2024-01-11T17:11:58.256645","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.460702Z","iopub.status.busy":"2024-01-11T17:11:58.460002Z","iopub.status.idle":"2024-01-11T17:11:58.469274Z","shell.execute_reply":"2024-01-11T17:11:58.468339Z"},"papermill":{"duration":0.075827,"end_time":"2024-01-11T17:11:58.47147","exception":false,"start_time":"2024-01-11T17:11:58.395643","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['duration'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.601553Z","iopub.status.busy":"2024-01-11T17:11:58.600908Z","iopub.status.idle":"2024-01-11T17:11:58.609163Z","shell.execute_reply":"2024-01-11T17:11:58.608086Z"},"papermill":{"duration":0.075561,"end_time":"2024-01-11T17:11:58.611466","exception":false,"start_time":"2024-01-11T17:11:58.535905","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.743579Z","iopub.status.busy":"2024-01-11T17:11:58.742953Z","iopub.status.idle":"2024-01-11T17:11:58.75052Z","shell.execute_reply":"2024-01-11T17:11:58.749675Z"},"papermill":{"duration":0.076522,"end_time":"2024-01-11T17:11:58.752583","exception":false,"start_time":"2024-01-11T17:11:58.676061","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:58.88162Z","iopub.status.busy":"2024-01-11T17:11:58.880509Z","iopub.status.idle":"2024-01-11T17:11:58.89161Z","shell.execute_reply":"2024-01-11T17:11:58.890474Z"},"papermill":{"duration":0.077807,"end_time":"2024-01-11T17:11:58.893978","exception":false,"start_time":"2024-01-11T17:11:58.816171","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['species'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.025449Z","iopub.status.busy":"2024-01-11T17:11:59.024812Z","iopub.status.idle":"2024-01-11T17:11:59.033382Z","shell.execute_reply":"2024-01-11T17:11:59.032193Z"},"papermill":{"duration":0.077983,"end_time":"2024-01-11T17:11:59.035804","exception":false,"start_time":"2024-01-11T17:11:58.957821","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.167433Z","iopub.status.busy":"2024-01-11T17:11:59.166207Z","iopub.status.idle":"2024-01-11T17:11:59.176467Z","shell.execute_reply":"2024-01-11T17:11:59.175146Z"},"papermill":{"duration":0.079423,"end_time":"2024-01-11T17:11:59.179018","exception":false,"start_time":"2024-01-11T17:11:59.099595","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['number_of_notes'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.30966Z","iopub.status.busy":"2024-01-11T17:11:59.308895Z","iopub.status.idle":"2024-01-11T17:11:59.318006Z","shell.execute_reply":"2024-01-11T17:11:59.316807Z"},"papermill":{"duration":0.077204,"end_time":"2024-01-11T17:11:59.320456","exception":false,"start_time":"2024-01-11T17:11:59.243252","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['title'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.452735Z","iopub.status.busy":"2024-01-11T17:11:59.452315Z","iopub.status.idle":"2024-01-11T17:11:59.465461Z","shell.execute_reply":"2024-01-11T17:11:59.464333Z"},"papermill":{"duration":0.082561,"end_time":"2024-01-11T17:11:59.468238","exception":false,"start_time":"2024-01-11T17:11:59.385677","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('title', axis=1, inplace=True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.602313Z","iopub.status.busy":"2024-01-11T17:11:59.601578Z","iopub.status.idle":"2024-01-11T17:11:59.618824Z","shell.execute_reply":"2024-01-11T17:11:59.617708Z"},"papermill":{"duration":0.088051,"end_time":"2024-01-11T17:11:59.621533","exception":false,"start_time":"2024-01-11T17:11:59.533482","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['secondary_labels'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.755533Z","iopub.status.busy":"2024-01-11T17:11:59.755121Z","iopub.status.idle":"2024-01-11T17:11:59.76707Z","shell.execute_reply":"2024-01-11T17:11:59.765933Z"},"papermill":{"duration":0.081429,"end_time":"2024-01-11T17:11:59.769817","exception":false,"start_time":"2024-01-11T17:11:59.688388","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:11:59.906604Z","iopub.status.busy":"2024-01-11T17:11:59.906164Z","iopub.status.idle":"2024-01-11T17:11:59.91495Z","shell.execute_reply":"2024-01-11T17:11:59.913838Z"},"papermill":{"duration":0.080268,"end_time":"2024-01-11T17:11:59.917274","exception":false,"start_time":"2024-01-11T17:11:59.837006","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.050026Z","iopub.status.busy":"2024-01-11T17:12:00.049572Z","iopub.status.idle":"2024-01-11T17:12:00.05956Z","shell.execute_reply":"2024-01-11T17:12:00.05824Z"},"papermill":{"duration":0.079632,"end_time":"2024-01-11T17:12:00.06206","exception":false,"start_time":"2024-01-11T17:11:59.982428","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.196077Z","iopub.status.busy":"2024-01-11T17:12:00.195611Z","iopub.status.idle":"2024-01-11T17:12:00.205225Z","shell.execute_reply":"2024-01-11T17:12:00.204048Z"},"papermill":{"duration":0.079364,"end_time":"2024-01-11T17:12:00.207694","exception":false,"start_time":"2024-01-11T17:12:00.12833","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['location'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.343954Z","iopub.status.busy":"2024-01-11T17:12:00.343492Z","iopub.status.idle":"2024-01-11T17:12:00.353708Z","shell.execute_reply":"2024-01-11T17:12:00.3529Z"},"papermill":{"duration":0.082131,"end_time":"2024-01-11T17:12:00.355895","exception":false,"start_time":"2024-01-11T17:12:00.273764","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.488197Z","iopub.status.busy":"2024-01-11T17:12:00.487762Z","iopub.status.idle":"2024-01-11T17:12:00.497788Z","shell.execute_reply":"2024-01-11T17:12:00.496939Z"},"papermill":{"duration":0.077675,"end_time":"2024-01-11T17:12:00.499969","exception":false,"start_time":"2024-01-11T17:12:00.422294","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df[df['latitude'] != 'Not specified']\ndf = df[df['longitude'] != 'Not specified']","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.633359Z","iopub.status.busy":"2024-01-11T17:12:00.632426Z","iopub.status.idle":"2024-01-11T17:12:00.696952Z","shell.execute_reply":"2024-01-11T17:12:00.695532Z"},"papermill":{"duration":0.133389,"end_time":"2024-01-11T17:12:00.700108","exception":false,"start_time":"2024-01-11T17:12:00.566719","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'] = df['latitude'].astype(float)\ndf['longitude'] = df['longitude'].astype(float)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.830701Z","iopub.status.busy":"2024-01-11T17:12:00.830236Z","iopub.status.idle":"2024-01-11T17:12:00.843041Z","shell.execute_reply":"2024-01-11T17:12:00.841894Z"},"papermill":{"duration":0.0802,"end_time":"2024-01-11T17:12:00.84515","exception":false,"start_time":"2024-01-11T17:12:00.76495","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:00.980561Z","iopub.status.busy":"2024-01-11T17:12:00.979319Z","iopub.status.idle":"2024-01-11T17:12:01.031515Z","shell.execute_reply":"2024-01-11T17:12:01.030685Z"},"papermill":{"duration":0.123708,"end_time":"2024-01-11T17:12:01.035112","exception":false,"start_time":"2024-01-11T17:12:00.911404","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.185856Z","iopub.status.busy":"2024-01-11T17:12:01.184796Z","iopub.status.idle":"2024-01-11T17:12:01.193121Z","shell.execute_reply":"2024-01-11T17:12:01.19223Z"},"papermill":{"duration":0.077017,"end_time":"2024-01-11T17:12:01.195536","exception":false,"start_time":"2024-01-11T17:12:01.118519","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'] = df['sampling_rate'].apply(lambda x:x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.328226Z","iopub.status.busy":"2024-01-11T17:12:01.327558Z","iopub.status.idle":"2024-01-11T17:12:01.345154Z","shell.execute_reply":"2024-01-11T17:12:01.34416Z"},"papermill":{"duration":0.087272,"end_time":"2024-01-11T17:12:01.347886","exception":false,"start_time":"2024-01-11T17:12:01.260614","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.483161Z","iopub.status.busy":"2024-01-11T17:12:01.482695Z","iopub.status.idle":"2024-01-11T17:12:01.492145Z","shell.execute_reply":"2024-01-11T17:12:01.491044Z"},"papermill":{"duration":0.080102,"end_time":"2024-01-11T17:12:01.494526","exception":false,"start_time":"2024-01-11T17:12:01.414424","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.627153Z","iopub.status.busy":"2024-01-11T17:12:01.626392Z","iopub.status.idle":"2024-01-11T17:12:01.634928Z","shell.execute_reply":"2024-01-11T17:12:01.633935Z"},"papermill":{"duration":0.077134,"end_time":"2024-01-11T17:12:01.63719","exception":false,"start_time":"2024-01-11T17:12:01.560056","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.77214Z","iopub.status.busy":"2024-01-11T17:12:01.771464Z","iopub.status.idle":"2024-01-11T17:12:01.779422Z","shell.execute_reply":"2024-01-11T17:12:01.778594Z"},"papermill":{"duration":0.076901,"end_time":"2024-01-11T17:12:01.781514","exception":false,"start_time":"2024-01-11T17:12:01.704613","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adjusted_type = df['type'].apply(lambda x:x.split(',')).reset_index().explode(\"type\")\nadjusted_type = adjusted_type['type'].apply(lambda x: x.strip().lower()).reset_index()\nadjusted_type['type'] = adjusted_type['type'].replace('calls','call')\nadjusted_type['type'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:01.91593Z","iopub.status.busy":"2024-01-11T17:12:01.91526Z","iopub.status.idle":"2024-01-11T17:12:01.973169Z","shell.execute_reply":"2024-01-11T17:12:01.971951Z"},"papermill":{"duration":0.129649,"end_time":"2024-01-11T17:12:01.97617","exception":false,"start_time":"2024-01-11T17:12:01.846521","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.118964Z","iopub.status.busy":"2024-01-11T17:12:02.118251Z","iopub.status.idle":"2024-01-11T17:12:02.148008Z","shell.execute_reply":"2024-01-11T17:12:02.146837Z"},"papermill":{"duration":0.104361,"end_time":"2024-01-11T17:12:02.150954","exception":false,"start_time":"2024-01-11T17:12:02.046593","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.291329Z","iopub.status.busy":"2024-01-11T17:12:02.290145Z","iopub.status.idle":"2024-01-11T17:12:02.300814Z","shell.execute_reply":"2024-01-11T17:12:02.299718Z"},"papermill":{"duration":0.084791,"end_time":"2024-01-11T17:12:02.303158","exception":false,"start_time":"2024-01-11T17:12:02.218367","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.441767Z","iopub.status.busy":"2024-01-11T17:12:02.441039Z","iopub.status.idle":"2024-01-11T17:12:02.453526Z","shell.execute_reply":"2024-01-11T17:12:02.452346Z"},"papermill":{"duration":0.084905,"end_time":"2024-01-11T17:12:02.455822","exception":false,"start_time":"2024-01-11T17:12:02.370917","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].replace(['? m','Unknown m', ' m'], '99999')\n","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.594304Z","iopub.status.busy":"2024-01-11T17:12:02.593859Z","iopub.status.idle":"2024-01-11T17:12:02.605593Z","shell.execute_reply":"2024-01-11T17:12:02.604278Z"},"papermill":{"duration":0.084766,"end_time":"2024-01-11T17:12:02.608782","exception":false,"start_time":"2024-01-11T17:12:02.524016","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].str.replace(',','')","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.747837Z","iopub.status.busy":"2024-01-11T17:12:02.747099Z","iopub.status.idle":"2024-01-11T17:12:02.76413Z","shell.execute_reply":"2024-01-11T17:12:02.762937Z"},"papermill":{"duration":0.089906,"end_time":"2024-01-11T17:12:02.767164","exception":false,"start_time":"2024-01-11T17:12:02.677258","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].str.replace('.','')","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:02.912012Z","iopub.status.busy":"2024-01-11T17:12:02.911186Z","iopub.status.idle":"2024-01-11T17:12:02.925931Z","shell.execute_reply":"2024-01-11T17:12:02.924687Z"},"papermill":{"duration":0.090866,"end_time":"2024-01-11T17:12:02.928794","exception":false,"start_time":"2024-01-11T17:12:02.837928","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = pd.to_numeric(df['elevation'],errors='coerce')\nsum_elevation = 0\ncount_valid_values = 0\n\nfor index, row in df.iterrows():\n  if row['elevation']!= 99999:\n    sum_elevation != row['elevation']\n    count_valid_values +=1\n    mean_elevation = sum_elevation / count_valid_values\n    mean_elevation","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:03.072115Z","iopub.status.busy":"2024-01-11T17:12:03.071287Z","iopub.status.idle":"2024-01-11T17:12:04.452666Z","shell.execute_reply":"2024-01-11T17:12:04.451448Z"},"papermill":{"duration":1.457412,"end_time":"2024-01-11T17:12:04.455595","exception":false,"start_time":"2024-01-11T17:12:02.998183","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].mean()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:04.594863Z","iopub.status.busy":"2024-01-11T17:12:04.594142Z","iopub.status.idle":"2024-01-11T17:12:04.601906Z","shell.execute_reply":"2024-01-11T17:12:04.600807Z"},"papermill":{"duration":0.079948,"end_time":"2024-01-11T17:12:04.604131","exception":false,"start_time":"2024-01-11T17:12:04.524183","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].replace(['99999'],mean_elevation)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:04.742261Z","iopub.status.busy":"2024-01-11T17:12:04.741451Z","iopub.status.idle":"2024-01-11T17:12:04.747696Z","shell.execute_reply":"2024-01-11T17:12:04.746654Z"},"papermill":{"duration":0.078922,"end_time":"2024-01-11T17:12:04.750619","exception":false,"start_time":"2024-01-11T17:12:04.671697","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('description', axis=1, inplace = True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:04.889762Z","iopub.status.busy":"2024-01-11T17:12:04.889043Z","iopub.status.idle":"2024-01-11T17:12:04.900984Z","shell.execute_reply":"2024-01-11T17:12:04.900068Z"},"papermill":{"duration":0.084899,"end_time":"2024-01-11T17:12:04.903512","exception":false,"start_time":"2024-01-11T17:12:04.818613","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.041888Z","iopub.status.busy":"2024-01-11T17:12:05.040707Z","iopub.status.idle":"2024-01-11T17:12:05.049429Z","shell.execute_reply":"2024-01-11T17:12:05.04836Z"},"papermill":{"duration":0.081465,"end_time":"2024-01-11T17:12:05.051557","exception":false,"start_time":"2024-01-11T17:12:04.970092","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.188124Z","iopub.status.busy":"2024-01-11T17:12:05.187705Z","iopub.status.idle":"2024-01-11T17:12:05.199575Z","shell.execute_reply":"2024-01-11T17:12:05.198499Z"},"papermill":{"duration":0.083424,"end_time":"2024-01-11T17:12:05.201972","exception":false,"start_time":"2024-01-11T17:12:05.118548","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3'] == 0]","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.340671Z","iopub.status.busy":"2024-01-11T17:12:05.339844Z","iopub.status.idle":"2024-01-11T17:12:05.357282Z","shell.execute_reply":"2024-01-11T17:12:05.356469Z"},"papermill":{"duration":0.089074,"end_time":"2024-01-11T17:12:05.359682","exception":false,"start_time":"2024-01-11T17:12:05.270608","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(df[df['bitrate_of_mp3']==3].index, inplace =True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.498313Z","iopub.status.busy":"2024-01-11T17:12:05.49782Z","iopub.status.idle":"2024-01-11T17:12:05.518405Z","shell.execute_reply":"2024-01-11T17:12:05.517125Z"},"papermill":{"duration":0.092749,"end_time":"2024-01-11T17:12:05.521346","exception":false,"start_time":"2024-01-11T17:12:05.428597","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3'].isna()]","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.659091Z","iopub.status.busy":"2024-01-11T17:12:05.65863Z","iopub.status.idle":"2024-01-11T17:12:05.692596Z","shell.execute_reply":"2024-01-11T17:12:05.691449Z"},"papermill":{"duration":0.105865,"end_time":"2024-01-11T17:12:05.695124","exception":false,"start_time":"2024-01-11T17:12:05.589259","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'] =df['bitrate_of_mp3'].fillna('0')","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.844096Z","iopub.status.busy":"2024-01-11T17:12:05.843076Z","iopub.status.idle":"2024-01-11T17:12:05.850499Z","shell.execute_reply":"2024-01-11T17:12:05.849597Z"},"papermill":{"duration":0.084853,"end_time":"2024-01-11T17:12:05.852864","exception":false,"start_time":"2024-01-11T17:12:05.768011","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'] = df['bitrate_of_mp3'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:05.994905Z","iopub.status.busy":"2024-01-11T17:12:05.994266Z","iopub.status.idle":"2024-01-11T17:12:06.012854Z","shell.execute_reply":"2024-01-11T17:12:06.011863Z"},"papermill":{"duration":0.091621,"end_time":"2024-01-11T17:12:06.015479","exception":false,"start_time":"2024-01-11T17:12:05.923858","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = df['bitrate_of_mp3'].mean()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.156443Z","iopub.status.busy":"2024-01-11T17:12:06.156032Z","iopub.status.idle":"2024-01-11T17:12:06.161716Z","shell.execute_reply":"2024-01-11T17:12:06.160645Z"},"papermill":{"duration":0.079438,"end_time":"2024-01-11T17:12:06.164041","exception":false,"start_time":"2024-01-11T17:12:06.084603","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'] = df['bitrate_of_mp3'].replace(0,m)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.308257Z","iopub.status.busy":"2024-01-11T17:12:06.307412Z","iopub.status.idle":"2024-01-11T17:12:06.313484Z","shell.execute_reply":"2024-01-11T17:12:06.312579Z"},"papermill":{"duration":0.081711,"end_time":"2024-01-11T17:12:06.315753","exception":false,"start_time":"2024-01-11T17:12:06.234042","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.45797Z","iopub.status.busy":"2024-01-11T17:12:06.457208Z","iopub.status.idle":"2024-01-11T17:12:06.485927Z","shell.execute_reply":"2024-01-11T17:12:06.484833Z"},"papermill":{"duration":0.102996,"end_time":"2024-01-11T17:12:06.488285","exception":false,"start_time":"2024-01-11T17:12:06.385289","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['file_type'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.632525Z","iopub.status.busy":"2024-01-11T17:12:06.632082Z","iopub.status.idle":"2024-01-11T17:12:06.640255Z","shell.execute_reply":"2024-01-11T17:12:06.639322Z"},"papermill":{"duration":0.082287,"end_time":"2024-01-11T17:12:06.642496","exception":false,"start_time":"2024-01-11T17:12:06.560209","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['volume'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.78851Z","iopub.status.busy":"2024-01-11T17:12:06.788073Z","iopub.status.idle":"2024-01-11T17:12:06.796382Z","shell.execute_reply":"2024-01-11T17:12:06.795496Z"},"papermill":{"duration":0.083098,"end_time":"2024-01-11T17:12:06.798442","exception":false,"start_time":"2024-01-11T17:12:06.715344","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['background'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:06.941979Z","iopub.status.busy":"2024-01-11T17:12:06.941528Z","iopub.status.idle":"2024-01-11T17:12:06.952125Z","shell.execute_reply":"2024-01-11T17:12:06.950849Z"},"papermill":{"duration":0.085801,"end_time":"2024-01-11T17:12:06.954556","exception":false,"start_time":"2024-01-11T17:12:06.868755","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['background'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.101747Z","iopub.status.busy":"2024-01-11T17:12:07.100683Z","iopub.status.idle":"2024-01-11T17:12:07.114771Z","shell.execute_reply":"2024-01-11T17:12:07.113559Z"},"papermill":{"duration":0.091318,"end_time":"2024-01-11T17:12:07.117391","exception":false,"start_time":"2024-01-11T17:12:07.026073","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('background', axis=1, inplace= True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.262663Z","iopub.status.busy":"2024-01-11T17:12:07.262259Z","iopub.status.idle":"2024-01-11T17:12:07.274898Z","shell.execute_reply":"2024-01-11T17:12:07.27379Z"},"papermill":{"duration":0.087487,"end_time":"2024-01-11T17:12:07.277585","exception":false,"start_time":"2024-01-11T17:12:07.190098","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['xc_id'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.422956Z","iopub.status.busy":"2024-01-11T17:12:07.42179Z","iopub.status.idle":"2024-01-11T17:12:07.430146Z","shell.execute_reply":"2024-01-11T17:12:07.429117Z"},"papermill":{"duration":0.084451,"end_time":"2024-01-11T17:12:07.432392","exception":false,"start_time":"2024-01-11T17:12:07.347941","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('xc_id',axis=1, inplace= True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.575194Z","iopub.status.busy":"2024-01-11T17:12:07.57389Z","iopub.status.idle":"2024-01-11T17:12:07.590928Z","shell.execute_reply":"2024-01-11T17:12:07.589986Z"},"papermill":{"duration":0.091059,"end_time":"2024-01-11T17:12:07.593497","exception":false,"start_time":"2024-01-11T17:12:07.502438","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['url'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.738509Z","iopub.status.busy":"2024-01-11T17:12:07.737688Z","iopub.status.idle":"2024-01-11T17:12:07.750662Z","shell.execute_reply":"2024-01-11T17:12:07.749458Z"},"papermill":{"duration":0.088299,"end_time":"2024-01-11T17:12:07.753152","exception":false,"start_time":"2024-01-11T17:12:07.664853","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('url', axis=1, inplace= True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:07.9036Z","iopub.status.busy":"2024-01-11T17:12:07.902816Z","iopub.status.idle":"2024-01-11T17:12:07.915886Z","shell.execute_reply":"2024-01-11T17:12:07.914968Z"},"papermill":{"duration":0.093696,"end_time":"2024-01-11T17:12:07.918621","exception":false,"start_time":"2024-01-11T17:12:07.824925","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.069073Z","iopub.status.busy":"2024-01-11T17:12:08.068582Z","iopub.status.idle":"2024-01-11T17:12:08.078362Z","shell.execute_reply":"2024-01-11T17:12:08.077231Z"},"papermill":{"duration":0.087451,"end_time":"2024-01-11T17:12:08.080637","exception":false,"start_time":"2024-01-11T17:12:07.993186","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['author'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.225863Z","iopub.status.busy":"2024-01-11T17:12:08.225047Z","iopub.status.idle":"2024-01-11T17:12:08.23826Z","shell.execute_reply":"2024-01-11T17:12:08.237147Z"},"papermill":{"duration":0.087839,"end_time":"2024-01-11T17:12:08.241213","exception":false,"start_time":"2024-01-11T17:12:08.153374","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['author'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.386542Z","iopub.status.busy":"2024-01-11T17:12:08.385658Z","iopub.status.idle":"2024-01-11T17:12:08.395239Z","shell.execute_reply":"2024-01-11T17:12:08.394224Z"},"papermill":{"duration":0.084507,"end_time":"2024-01-11T17:12:08.397461","exception":false,"start_time":"2024-01-11T17:12:08.312954","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['recordist'].nunique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.546551Z","iopub.status.busy":"2024-01-11T17:12:08.545807Z","iopub.status.idle":"2024-01-11T17:12:08.555259Z","shell.execute_reply":"2024-01-11T17:12:08.554088Z"},"papermill":{"duration":0.08613,"end_time":"2024-01-11T17:12:08.557523","exception":false,"start_time":"2024-01-11T17:12:08.471393","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['author'] != df['recordist']]","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.70298Z","iopub.status.busy":"2024-01-11T17:12:08.702529Z","iopub.status.idle":"2024-01-11T17:12:08.720912Z","shell.execute_reply":"2024-01-11T17:12:08.719747Z"},"papermill":{"duration":0.092988,"end_time":"2024-01-11T17:12:08.723261","exception":false,"start_time":"2024-01-11T17:12:08.630273","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('author', axis=1, inplace=True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:08.867931Z","iopub.status.busy":"2024-01-11T17:12:08.867283Z","iopub.status.idle":"2024-01-11T17:12:08.88007Z","shell.execute_reply":"2024-01-11T17:12:08.879142Z"},"papermill":{"duration":0.087834,"end_time":"2024-01-11T17:12:08.882567","exception":false,"start_time":"2024-01-11T17:12:08.794733","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['primary_label'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.030589Z","iopub.status.busy":"2024-01-11T17:12:09.030202Z","iopub.status.idle":"2024-01-11T17:12:09.041789Z","shell.execute_reply":"2024-01-11T17:12:09.040085Z"},"papermill":{"duration":0.089601,"end_time":"2024-01-11T17:12:09.044751","exception":false,"start_time":"2024-01-11T17:12:08.95515","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['length'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.192016Z","iopub.status.busy":"2024-01-11T17:12:09.191578Z","iopub.status.idle":"2024-01-11T17:12:09.199645Z","shell.execute_reply":"2024-01-11T17:12:09.198787Z"},"papermill":{"duration":0.083674,"end_time":"2024-01-11T17:12:09.201937","exception":false,"start_time":"2024-01-11T17:12:09.118263","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value'] = df['length'].str.extract(r'(\\d+)')\ndf['min_value'] = pd.to_numeric(df['min_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.347106Z","iopub.status.busy":"2024-01-11T17:12:09.346411Z","iopub.status.idle":"2024-01-11T17:12:09.405033Z","shell.execute_reply":"2024-01-11T17:12:09.403942Z"},"papermill":{"duration":0.133589,"end_time":"2024-01-11T17:12:09.407325","exception":false,"start_time":"2024-01-11T17:12:09.273736","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value'] = df['length'].str.extract(r'(\\d+)')\ndf['max_value'] = pd.to_numeric(df['max_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.558685Z","iopub.status.busy":"2024-01-11T17:12:09.558298Z","iopub.status.idle":"2024-01-11T17:12:09.619474Z","shell.execute_reply":"2024-01-11T17:12:09.618208Z"},"papermill":{"duration":0.13841,"end_time":"2024-01-11T17:12:09.622012","exception":false,"start_time":"2024-01-11T17:12:09.483602","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.770324Z","iopub.status.busy":"2024-01-11T17:12:09.769922Z","iopub.status.idle":"2024-01-11T17:12:09.777583Z","shell.execute_reply":"2024-01-11T17:12:09.776553Z"},"papermill":{"duration":0.083945,"end_time":"2024-01-11T17:12:09.77967","exception":false,"start_time":"2024-01-11T17:12:09.695725","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:09.925979Z","iopub.status.busy":"2024-01-11T17:12:09.925542Z","iopub.status.idle":"2024-01-11T17:12:09.934432Z","shell.execute_reply":"2024-01-11T17:12:09.933326Z"},"papermill":{"duration":0.084976,"end_time":"2024-01-11T17:12:09.936611","exception":false,"start_time":"2024-01-11T17:12:09.851635","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.088228Z","iopub.status.busy":"2024-01-11T17:12:10.08779Z","iopub.status.idle":"2024-01-11T17:12:10.096864Z","shell.execute_reply":"2024-01-11T17:12:10.095773Z"},"papermill":{"duration":0.087166,"end_time":"2024-01-11T17:12:10.099199","exception":false,"start_time":"2024-01-11T17:12:10.012033","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('time', axis=1, inplace= True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.246644Z","iopub.status.busy":"2024-01-11T17:12:10.246257Z","iopub.status.idle":"2024-01-11T17:12:10.258111Z","shell.execute_reply":"2024-01-11T17:12:10.257135Z"},"papermill":{"duration":0.088516,"end_time":"2024-01-11T17:12:10.260612","exception":false,"start_time":"2024-01-11T17:12:10.172096","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['license'].unique()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.409213Z","iopub.status.busy":"2024-01-11T17:12:10.408086Z","iopub.status.idle":"2024-01-11T17:12:10.417566Z","shell.execute_reply":"2024-01-11T17:12:10.416776Z"},"papermill":{"duration":0.08589,"end_time":"2024-01-11T17:12:10.419821","exception":false,"start_time":"2024-01-11T17:12:10.333931","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\ndf['license_encoded'] = le.fit_transform(df['license'])\nencoded_unique_values = df['license_encoded'].unique()\nlabel_swaping = dict(zip(df['license'], df['license_encoded']))","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.57254Z","iopub.status.busy":"2024-01-11T17:12:10.572153Z","iopub.status.idle":"2024-01-11T17:12:10.589433Z","shell.execute_reply":"2024-01-11T17:12:10.588454Z"},"papermill":{"duration":0.096325,"end_time":"2024-01-11T17:12:10.592008","exception":false,"start_time":"2024-01-11T17:12:10.495683","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('license', axis=1, inplace= True)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.743714Z","iopub.status.busy":"2024-01-11T17:12:10.742887Z","iopub.status.idle":"2024-01-11T17:12:10.759414Z","shell.execute_reply":"2024-01-11T17:12:10.75834Z"},"papermill":{"duration":0.094372,"end_time":"2024-01-11T17:12:10.762021","exception":false,"start_time":"2024-01-11T17:12:10.667649","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:10.912143Z","iopub.status.busy":"2024-01-11T17:12:10.911717Z","iopub.status.idle":"2024-01-11T17:12:10.942098Z","shell.execute_reply":"2024-01-11T17:12:10.94104Z"},"papermill":{"duration":0.109135,"end_time":"2024-01-11T17:12:10.94453","exception":false,"start_time":"2024-01-11T17:12:10.835395","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:11.116236Z","iopub.status.busy":"2024-01-11T17:12:11.115837Z","iopub.status.idle":"2024-01-11T17:12:11.180897Z","shell.execute_reply":"2024-01-11T17:12:11.179821Z"},"papermill":{"duration":0.160616,"end_time":"2024-01-11T17:12:11.183349","exception":false,"start_time":"2024-01-11T17:12:11.022733","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"white\")\nplt.figure(figsize=(10,6))\n\nsns.countplot(x='rating', data=df, order=df['rating'].value_counts().index,palette='viridis')\n\nplt.title('Distribution Of Ratings')\nplt.xlabel('Rating')\nplt.ylabel('Count')\n\nplt.xticks(rotation=45)\n\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:11.338837Z","iopub.status.busy":"2024-01-11T17:12:11.33832Z","iopub.status.idle":"2024-01-11T17:12:11.750345Z","shell.execute_reply":"2024-01-11T17:12:11.74913Z"},"papermill":{"duration":0.492187,"end_time":"2024-01-11T17:12:11.752948","exception":false,"start_time":"2024-01-11T17:12:11.260761","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"ticks\")\nplt.figure(figsize=(10,6))\n\nsns.countplot(y='playback_used_encoded', data=df, palette='Set2')\n\nplt.title('Distribution Of Playback Used')\nplt.xlabel('Count')\nplt.ylabel('Playback Used')\n\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:11.910777Z","iopub.status.busy":"2024-01-11T17:12:11.90934Z","iopub.status.idle":"2024-01-11T17:12:12.138693Z","shell.execute_reply":"2024-01-11T17:12:12.137547Z"},"papermill":{"duration":0.310399,"end_time":"2024-01-11T17:12:12.1414","exception":false,"start_time":"2024-01-11T17:12:11.831001","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\n\nsns.countplot(x='rating', hue='playback_used_encoded', data=df, palette='pastel')\n\nplt.title('Ratings Versus Playback Used')\nplt.xlabel('Rating')\nplt.ylabel('Count')\n\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:12.301795Z","iopub.status.busy":"2024-01-11T17:12:12.300713Z","iopub.status.idle":"2024-01-11T17:12:12.630647Z","shell.execute_reply":"2024-01-11T17:12:12.62949Z"},"papermill":{"duration":0.411378,"end_time":"2024-01-11T17:12:12.633069","exception":false,"start_time":"2024-01-11T17:12:12.221691","status":"completed"},"tags":[]},"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.execute_input":"2024-01-11T17:12:12.790013Z","iopub.status.busy":"2024-01-11T17:12:12.789316Z","iopub.status.idle":"2024-01-11T17:12:13.018117Z","shell.execute_reply":"2024-01-11T17:12:13.016971Z"},"papermill":{"duration":0.310486,"end_time":"2024-01-11T17:12:13.021186","exception":false,"start_time":"2024-01-11T17:12:12.7107","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"FE","metadata":{"papermill":{"duration":0.081755,"end_time":"2024-01-11T17:12:13.191044","exception":false,"start_time":"2024-01-11T17:12:13.109289","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import librosa # for audio analysis\nimport librosa.display\nimport soundfile as sf # for reading and writing sound files\nimport IPython.display as ipd","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:13.433015Z","iopub.status.busy":"2024-01-11T17:12:13.431725Z","iopub.status.idle":"2024-01-11T17:12:13.494559Z","shell.execute_reply":"2024-01-11T17:12:13.493216Z"},"papermill":{"duration":0.226716,"end_time":"2024-01-11T17:12:13.497519","exception":false,"start_time":"2024-01-11T17:12:13.270803","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"audio1_1 = \"/kaggle/input/birdsong-recognition/train_audio/canwar/XC250587.mp3\"\naudio1_2 = \"/kaggle/input/birdsong-recognition/train_audio/canwar/XC421848.mp3\"\naudio2_1 = \"/kaggle/input/birdsong-recognition/train_audio/grnher/XC372647.mp3\"\naudio2_2 = \"/kaggle/input/birdsong-recognition/train_audio/grnher/XC218817.mp3\"\naudio3_1 = \"/kaggle/input/birdsong-recognition/train_audio/buggna/XC455035.mp3\"\naudio3_2 = \"/kaggle/input/birdsong-recognition/train_audio/buggna/XC302322.mp3\"\naudio4_1 = \"/kaggle/input/birdsong-recognition/train_audio/pilwoo/XC156471.mp3\"\naudio4_2 = \"/kaggle/input/birdsong-recognition/train_audio/pilwoo/XC113384.mp3\"\naudio5_1 = \"/kaggle/input/birdsong-recognition/train_audio/wesgre/XC387824.mp3\"\naudio5_2 = \"/kaggle/input/birdsong-recognition/train_audio/wesgre/XC292677.mp3\"","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:13.656546Z","iopub.status.busy":"2024-01-11T17:12:13.656127Z","iopub.status.idle":"2024-01-11T17:12:13.661945Z","shell.execute_reply":"2024-01-11T17:12:13.661063Z"},"papermill":{"duration":0.088303,"end_time":"2024-01-11T17:12:13.663971","exception":false,"start_time":"2024-01-11T17:12:13.575668","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1, sr1 = librosa.load(audio1_1) # y1 = np array of audio signals; sr = sample rate (no. of data points (samples) played back each second -- Hz)\ny2, sr2 = librosa.load(audio1_2)\ny3, sr3 = librosa.load(audio2_1)\ny4, sr4 = librosa.load(audio2_2)\ny5, sr5 = librosa.load(audio3_1)\ny6, sr6 = librosa.load(audio3_2)\ny7, sr7 = librosa.load(audio4_1)\ny8, sr8 = librosa.load(audio4_2)\ny9, sr9 = librosa.load(audio5_1)\ny10, sr10 = librosa.load(audio5_2)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:13.820514Z","iopub.status.busy":"2024-01-11T17:12:13.820125Z","iopub.status.idle":"2024-01-11T17:12:27.418512Z","shell.execute_reply":"2024-01-11T17:12:27.417111Z"},"papermill":{"duration":13.679612,"end_time":"2024-01-11T17:12:27.421466","exception":false,"start_time":"2024-01-11T17:12:13.741854","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y1)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr1, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:27.581051Z","iopub.status.busy":"2024-01-11T17:12:27.580354Z","iopub.status.idle":"2024-01-11T17:12:29.292445Z","shell.execute_reply":"2024-01-11T17:12:29.291258Z"},"papermill":{"duration":1.798067,"end_time":"2024-01-11T17:12:29.298807","exception":false,"start_time":"2024-01-11T17:12:27.50074","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y2)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr2, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:29.470663Z","iopub.status.busy":"2024-01-11T17:12:29.470244Z","iopub.status.idle":"2024-01-11T17:12:30.654345Z","shell.execute_reply":"2024-01-11T17:12:30.653242Z"},"papermill":{"duration":1.273581,"end_time":"2024-01-11T17:12:30.659135","exception":false,"start_time":"2024-01-11T17:12:29.385554","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y3)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr3, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:30.840208Z","iopub.status.busy":"2024-01-11T17:12:30.839313Z","iopub.status.idle":"2024-01-11T17:12:31.612719Z","shell.execute_reply":"2024-01-11T17:12:31.61132Z"},"papermill":{"duration":0.86799,"end_time":"2024-01-11T17:12:31.618071","exception":false,"start_time":"2024-01-11T17:12:30.750081","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y4)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr4, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:31.812997Z","iopub.status.busy":"2024-01-11T17:12:31.812557Z","iopub.status.idle":"2024-01-11T17:12:32.803849Z","shell.execute_reply":"2024-01-11T17:12:32.802553Z"},"papermill":{"duration":1.089935,"end_time":"2024-01-11T17:12:32.809261","exception":false,"start_time":"2024-01-11T17:12:31.719326","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y5)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr5, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:33.018747Z","iopub.status.busy":"2024-01-11T17:12:33.018304Z","iopub.status.idle":"2024-01-11T17:12:33.821411Z","shell.execute_reply":"2024-01-11T17:12:33.820438Z"},"papermill":{"duration":0.912417,"end_time":"2024-01-11T17:12:33.826308","exception":false,"start_time":"2024-01-11T17:12:32.913891","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y6)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr6, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:34.044387Z","iopub.status.busy":"2024-01-11T17:12:34.043584Z","iopub.status.idle":"2024-01-11T17:12:42.327219Z","shell.execute_reply":"2024-01-11T17:12:42.325719Z"},"papermill":{"duration":8.393301,"end_time":"2024-01-11T17:12:42.330459","exception":false,"start_time":"2024-01-11T17:12:33.937158","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y7)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr7, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:42.559915Z","iopub.status.busy":"2024-01-11T17:12:42.559483Z","iopub.status.idle":"2024-01-11T17:12:49.005766Z","shell.execute_reply":"2024-01-11T17:12:49.004443Z"},"papermill":{"duration":6.565015,"end_time":"2024-01-11T17:12:49.010666","exception":false,"start_time":"2024-01-11T17:12:42.445651","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y8)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr8, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:49.247151Z","iopub.status.busy":"2024-01-11T17:12:49.246687Z","iopub.status.idle":"2024-01-11T17:12:52.075777Z","shell.execute_reply":"2024-01-11T17:12:52.074799Z"},"papermill":{"duration":2.95079,"end_time":"2024-01-11T17:12:52.081273","exception":false,"start_time":"2024-01-11T17:12:49.130483","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y9)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr9, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:52.332944Z","iopub.status.busy":"2024-01-11T17:12:52.332093Z","iopub.status.idle":"2024-01-11T17:12:54.699403Z","shell.execute_reply":"2024-01-11T17:12:54.697964Z"},"papermill":{"duration":2.496593,"end_time":"2024-01-11T17:12:54.705457","exception":false,"start_time":"2024-01-11T17:12:52.208864","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y10)), ref=np.max)\n\n# Plot the spectrogram\nplt.figure(figsize=(8, 4))\nlibrosa.display.specshow(D, sr=sr10, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio Signal')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:54.962837Z","iopub.status.busy":"2024-01-11T17:12:54.962429Z","iopub.status.idle":"2024-01-11T17:12:56.153484Z","shell.execute_reply":"2024-01-11T17:12:56.152234Z"},"papermill":{"duration":1.320767,"end_time":"2024-01-11T17:12:56.158688","exception":false,"start_time":"2024-01-11T17:12:54.837921","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_signal = librosa.feature.melspectrogram(y=y3, sr=sr3, hop_length=2, n_fft=200)\nspectrogram = np.abs(mel_signal)\npower_to_db = librosa.power_to_db(spectrogram, ref=np.max)\nplt.figure(figsize=(7, 6))\nlibrosa.display.specshow(power_to_db, sr=sr3, x_axis='time', y_axis='mel', cmap='magma', hop_length=2)\n\nplt.colorbar(label='dB')\nplt.title('Mel-Spectrogram (dB)', fontdict=dict(size=18))\nplt.xlabel('Time', fontdict=dict(size=15))\nplt.ylabel('Frequency', fontdict=dict(size=15))\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:12:56.425682Z","iopub.status.busy":"2024-01-11T17:12:56.424762Z","iopub.status.idle":"2024-01-11T17:13:11.703928Z","shell.execute_reply":"2024-01-11T17:13:11.702569Z"},"papermill":{"duration":15.411707,"end_time":"2024-01-11T17:13:11.706527","exception":false,"start_time":"2024-01-11T17:12:56.29482","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_signal = librosa.feature.melspectrogram(y=y4, sr=sr4, hop_length=2, n_fft=200)\nspectrogram = np.abs(mel_signal)\npower_to_db = librosa.power_to_db(spectrogram, ref=np.max)\nplt.figure(figsize=(7, 6))\nlibrosa.display.specshow(power_to_db, sr=sr4, x_axis='time', y_axis='mel', cmap='magma', hop_length=2)\n\nplt.colorbar(label='dB')\nplt.title('Mel-Spectrogram (dB)', fontdict=dict(size=18))\nplt.xlabel('Time', fontdict=dict(size=15))\nplt.ylabel('Frequency', fontdict=dict(size=15))\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:13:11.983381Z","iopub.status.busy":"2024-01-11T17:13:11.982937Z","iopub.status.idle":"2024-01-11T17:13:35.175837Z","shell.execute_reply":"2024-01-11T17:13:35.174671Z"},"papermill":{"duration":23.333809,"end_time":"2024-01-11T17:13:35.179758","exception":false,"start_time":"2024-01-11T17:13:11.845949","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2 #image processing\nimport audioread #reading and processing audio files\nimport logging #record events and errors for debugging and monitoring\nimport os #file and directory manipulation\nimport random #shuffling data\nimport time #calculate time taken or introduce delays\nimport warnings #issuing warning messages about potential issues\nimport librosa\nimport numpy as np\nimport pandas as pd\nimport soundfile as sf #reading and writing audio files\nimport torch #core module of PyTorch\nimport torch.nn as nn #building and training neural networks\nimport torch.nn.functional as F #for element-wise functions\nimport torch.utils.data as data #for loading and batching data during training\nfrom contextlib import contextmanager #to ensure that resources are properly managed\nfrom pathlib import Path #for working with paths in a more object-oriented way\nfrom typing import Optional #type hint\nfrom fastprogress import progress_bar\nfrom sklearn.metrics import f1_score\nfrom torchvision import models #provides pre-trained models\nimport resampy","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:13:35.464959Z","iopub.status.busy":"2024-01-11T17:13:35.463973Z","iopub.status.idle":"2024-01-11T17:13:40.177152Z","shell.execute_reply":"2024-01-11T17:13:40.175238Z"},"papermill":{"duration":4.854122,"end_time":"2024-01-11T17:13:40.179353","exception":true,"start_time":"2024-01-11T17:13:35.325231","status":"failed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_seed (seed: int = 42): #sets random seed for different libraries\n    random.seed (seed)\n    np.random.seed (seed)\n    os.environ[ \"PYTHONHASHSEED\"] = str(seed) #for hash functions\n    torch.manual_seed (seed) #random of pytorch\n    torch.cuda.manual_seed (seed) #type: ignore #same but for GPU\n    torch.backends.cudnn.deterministic = True #type: ignore #deterministic mode\n    torch.backends. cudnn.benchmark = True # type: ignore #optimize performance\n\ndef get_logger (out_file=None) :\n    logger = logging.getLogger()\n    formatter = logging. Formatter(\"%(asctime)s - %(levelname)s - %(message)s\") #timestamp, log level, mess\n    logger.handlers = [] #object that transfers log\n    logger.setLevel (logging. INFO) #capture only INFO level\n    handler = logging. StreamHandler() #to the console\n    handler. setFormatter (formatter)\n    handler.setLevel (logging. INFO)\n    logger.addHandler (handler)\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","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:39.413305Z","iopub.status.busy":"2024-01-11T17:09:39.412866Z","iopub.status.idle":"2024-01-11T17:09:39.424277Z","shell.execute_reply":"2024-01-11T17:09:39.42313Z","shell.execute_reply.started":"2024-01-11T17:09:39.413272Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"@contextmanager #measure execution time\ndef timer (name: str, logger: Optional [logging.Logger] = None):\n    t0 = time.time() #current time\n    msg = f\"[{name}] start\"\n    if logger is None:\n        print (msg)\n    else:\n        logger.info (msg)\n    yield\n    \n    msg=f\" [{name}] done in {time.time() - t0:.2f} s\"\n    if logger is None:\n        print (msg)\n    else:\n        logger.info(msg)\n","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:39.739723Z","iopub.status.busy":"2024-01-11T17:09:39.739062Z","iopub.status.idle":"2024-01-11T17:09:39.74732Z","shell.execute_reply":"2024-01-11T17:09:39.74605Z","shell.execute_reply.started":"2024-01-11T17:09:39.739689Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logger = get_logger(\"main.log\")\nset_seed(1213)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:39.991315Z","iopub.status.busy":"2024-01-11T17:09:39.990851Z","iopub.status.idle":"2024-01-11T17:09:40.001106Z","shell.execute_reply":"2024-01-11T17:09:39.99964Z","shell.execute_reply.started":"2024-01-11T17:09:39.991277Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TARGET_SR = 32000","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:40.18138Z","iopub.status.busy":"2024-01-11T17:09:40.180936Z","iopub.status.idle":"2024-01-11T17:09:40.186334Z","shell.execute_reply":"2024-01-11T17:09:40.185347Z","shell.execute_reply.started":"2024-01-11T17:09:40.181347Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(\"/kaggle/input/birdcall-check/test.csv\")\ntest_audio = \"/kaggle/input/birdcall-check/test_audio\"\n\ntest.head()","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:40.390815Z","iopub.status.busy":"2024-01-11T17:09:40.390422Z","iopub.status.idle":"2024-01-11T17:09:40.409764Z","shell.execute_reply":"2024-01-11T17:09:40.408803Z","shell.execute_reply.started":"2024-01-11T17:09:40.390783Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ResNet (nn. Module): #base class\n    def __init__(self, base_model_name: str, pretrained=False, #constructor #weights\n                num_classes=264): #constructor method\n        super().__init__() #initializing the base class\n        base_model = models.__getattribute__(base_model_name) (\n            pretrained-pretrained)\n        layers = list (base_model.children())[:-2] #except pooling and dense\n        layers.append(nn.AdaptiveMaxPool2d(1))\n        self.encoder = nn.Sequential(*layers)\n\n        in_features = base_model.fc.in_features #number of input features\n\n        self.classifier = nn.Sequential(\n            nn.Linear (in_features, 1024), nn. ReLU(), nn. Dropout (p=0.2),\n            nn. Linear (1024, 1024), nn. ReLU(), nn. Dropout (p=0.2),\n            nn. Linear (1024, num_classes))\n    def forward(self,x):\n        batch_size = x.size(0)\n        x = self.encoder (x).view (batch_size, -1) #1D tensor\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.execute_input":"2024-01-11T17:09:40.56629Z","iopub.status.busy":"2024-01-11T17:09:40.565482Z","iopub.status.idle":"2024-01-11T17:09:40.577795Z","shell.execute_reply":"2024-01-11T17:09:40.576732Z","shell.execute_reply.started":"2024-01-11T17:09:40.566239Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Parameters","metadata":{"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]}},{"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 = \"../input/birdcall-resnet50-init-weights/best.pth\"","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:40.928944Z","iopub.status.busy":"2024-01-11T17:09:40.928557Z","iopub.status.idle":"2024-01-11T17:09:40.935204Z","shell.execute_reply":"2024-01-11T17:09:40.933873Z","shell.execute_reply.started":"2024-01-11T17:09:40.928913Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"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()\n\nlabel_encoder = LabelEncoder()\n\nencoded_labels = label_encoder.fit_transform(unique_bird_names)\n\nBIRD_CODE = dict(zip(unique_bird_names, encoded_labels))\n\n# for bird_name, label in BIRD_Code.items():\n#     print(f\"{bird_name}: {label}\")\n\nINV_BIRD_CODE = {v: k for k, v in BIRD_CODE.items()}\n# for bird_name, label in INV_BIRD_Code.items():\n#     print(f\"{bird_name}: {label}\")","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:41.049797Z","iopub.status.busy":"2024-01-11T17:09:41.04911Z","iopub.status.idle":"2024-01-11T17:09:41.517832Z","shell.execute_reply":"2024-01-11T17:09:41.516676Z","shell.execute_reply.started":"2024-01-11T17:09:41.049763Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Define Dataset","metadata":{"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]}},{"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    X = np.stack([X,X,X], axis=-1)\n    \n    #Standardize\n    mean = mean or X.mean()\n    X = X - mean\n    std = srd 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    \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        V = np.zeros_like(Xstd, dtype=np.uint8)\n    return V\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\n                \n            ","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:41.520914Z","iopub.status.busy":"2024-01-11T17:09:41.520531Z","iopub.status.idle":"2024-01-11T17:09:41.546261Z","shell.execute_reply":"2024-01-11T17:09:41.545085Z","shell.execute_reply.started":"2024-01-11T17:09:41.52088Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model(config: dict, weights_path: str):\n    model = ResNet(**config)\n    checkpoint = torch.load(weights_path, map_location=torch.device('cpu'))\n    model.load_state_dict(checkpoint[\"model_state_dict\"])\n    device = torch.device('cpu')\n    model.to(device)\n    model.eval\n    return model","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:41.548864Z","iopub.status.busy":"2024-01-11T17:09:41.548419Z","iopub.status.idle":"2024-01-11T17:09:41.564148Z","shell.execute_reply":"2024-01-11T17:09:41.562984Z","shell.execute_reply.started":"2024-01-11T17:09:41.548824Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"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, batchsize=1, shuffle=False)\n    \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                prediciton = model(image)\n                proba = prediction[\"multilabel_proba\"].detach().cpu().numpy().reshape(-1)\n\n                \n            events = proba >= threshold\n            labels = np.argwhere(events).reshape(-1).tolist()\n        else:\n\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 // batach_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                    prediciton = 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.execute_input":"2024-01-11T17:09:41.746198Z","iopub.status.busy":"2024-01-11T17:09:41.745391Z","iopub.status.idle":"2024-01-11T17:09:41.762374Z","shell.execute_reply":"2024-01-11T17:09:41.761341Z","shell.execute_reply.started":"2024-01-11T17:09:41.746152Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install resampy","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:41.896047Z","iopub.status.busy":"2024-01-11T17:09:41.894976Z","iopub.status.idle":"2024-01-11T17:09:56.427626Z","shell.execute_reply":"2024-01-11T17:09:56.425945Z","shell.execute_reply.started":"2024-01-11T17:09:41.896006Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import resampy","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:56.431153Z","iopub.status.busy":"2024-01-11T17:09:56.430609Z","iopub.status.idle":"2024-01-11T17:09:56.436991Z","shell.execute_reply":"2024-01-11T17:09:56.435451Z","shell.execute_reply.started":"2024-01-11T17:09:56.431111Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"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    predictions_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                                 res_type= \"kaiser_fast\")\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 = prediciton_for_clip(test_df_for_audio_id,\n                                                      clip=clip,\n                                                      model=model,\n                                                      mel_params=mel_params,\n                                                      threshold=threshold)\n                \n            row_id = list(prediction_dict.keys())\n            birds = list(prediction_dict.values())\n            prediciton_df = pd.DataFrame({\n                \"row_id\": row_id,\n                \"birds\" : birds\n            })\n            prediction_dfs.append(prediciton_df)\n    \n    prediction_df = pd.concat(predition_dfs, axis=0, sort=False).reset_index(drop=True)\n    return prediciton_df\n","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:56.439278Z","iopub.status.busy":"2024-01-11T17:09:56.438788Z","iopub.status.idle":"2024-01-11T17:09:56.452766Z","shell.execute_reply":"2024-01-11T17:09:56.45193Z","shell.execute_reply.started":"2024-01-11T17:09:56.439237Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = prediction(test_df = test,\n                        test_audio=test_audio,\n                        model_config=model_config,\n                        mel_params=melspectrogram_parameters,\n                        weights_path=weights_path,\n                        threshold=0.8)\nsubmission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.execute_input":"2024-01-11T17:09:56.456357Z","iopub.status.busy":"2024-01-11T17:09:56.455668Z","iopub.status.idle":"2024-01-11T17:09:57.319736Z","shell.execute_reply":"2024-01-11T17:09:57.317924Z","shell.execute_reply.started":"2024-01-11T17:09:56.456322Z"},"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":null,"end_time":null,"exception":null,"start_time":null,"status":"pending"},"tags":[]},"execution_count":null,"outputs":[]}]}