{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"},{"sourceId":1264575,"sourceType":"datasetVersion","datasetId":725893},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-11T14:19:34.146515Z","iopub.execute_input":"2024-01-11T14:19:34.146970Z","iopub.status.idle":"2024-01-11T14:19:34.756577Z","shell.execute_reply.started":"2024-01-11T14:19:34.146933Z","shell.execute_reply":"2024-01-11T14:19:34.754670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:34.759217Z","iopub.execute_input":"2024-01-11T14:19:34.760658Z","iopub.status.idle":"2024-01-11T14:19:34.768811Z","shell.execute_reply.started":"2024-01-11T14:19:34.760586Z","shell.execute_reply":"2024-01-11T14:19:34.767049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:34.770487Z","iopub.execute_input":"2024-01-11T14:19:34.770973Z","iopub.status.idle":"2024-01-11T14:19:35.256301Z","shell.execute_reply.started":"2024-01-11T14:19:34.770933Z","shell.execute_reply":"2024-01-11T14:19:35.255052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.258014Z","iopub.execute_input":"2024-01-11T14:19:35.259469Z","iopub.status.idle":"2024-01-11T14:19:35.306420Z","shell.execute_reply.started":"2024-01-11T14:19:35.259359Z","shell.execute_reply":"2024-01-11T14:19:35.305356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\npd.set_option('display.expand_frame_repr', False)\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.309478Z","iopub.execute_input":"2024-01-11T14:19:35.311044Z","iopub.status.idle":"2024-01-11T14:19:35.320728Z","shell.execute_reply.started":"2024-01-11T14:19:35.310998Z","shell.execute_reply":"2024-01-11T14:19:35.318686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.323168Z","iopub.execute_input":"2024-01-11T14:19:35.324198Z","iopub.status.idle":"2024-01-11T14:19:35.428400Z","shell.execute_reply.started":"2024-01-11T14:19:35.324122Z","shell.execute_reply":"2024-01-11T14:19:35.426872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns_with_nulls=df.columns[df.isnull().any()]\nprint(columns_with_nulls)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.430782Z","iopub.execute_input":"2024-01-11T14:19:35.432472Z","iopub.status.idle":"2024-01-11T14:19:35.520276Z","shell.execute_reply.started":"2024-01-11T14:19:35.432401Z","shell.execute_reply":"2024-01-11T14:19:35.518313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.522271Z","iopub.execute_input":"2024-01-11T14:19:35.522780Z","iopub.status.idle":"2024-01-11T14:19:35.534317Z","shell.execute_reply.started":"2024-01-11T14:19:35.522722Z","shell.execute_reply":"2024-01-11T14:19:35.532333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.537336Z","iopub.execute_input":"2024-01-11T14:19:35.538009Z","iopub.status.idle":"2024-01-11T14:19:35.583635Z","shell.execute_reply.started":"2024-01-11T14:19:35.537947Z","shell.execute_reply":"2024-01-11T14:19:35.581420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.586007Z","iopub.execute_input":"2024-01-11T14:19:35.586537Z","iopub.status.idle":"2024-01-11T14:19:35.598676Z","shell.execute_reply.started":"2024-01-11T14:19:35.586488Z","shell.execute_reply":"2024-01-11T14:19:35.596842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.600691Z","iopub.execute_input":"2024-01-11T14:19:35.601101Z","iopub.status.idle":"2024-01-11T14:19:35.617113Z","shell.execute_reply.started":"2024-01-11T14:19:35.601069Z","shell.execute_reply":"2024-01-11T14:19:35.615628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.619333Z","iopub.execute_input":"2024-01-11T14:19:35.619796Z","iopub.status.idle":"2024-01-11T14:19:35.636441Z","shell.execute_reply.started":"2024-01-11T14:19:35.619732Z","shell.execute_reply":"2024-01-11T14:19:35.634692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].fillna('no',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.638474Z","iopub.execute_input":"2024-01-11T14:19:35.639028Z","iopub.status.idle":"2024-01-11T14:19:35.653018Z","shell.execute_reply.started":"2024-01-11T14:19:35.638986Z","shell.execute_reply":"2024-01-11T14:19:35.651370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.661762Z","iopub.execute_input":"2024-01-11T14:19:35.663451Z","iopub.status.idle":"2024-01-11T14:19:35.675997Z","shell.execute_reply.started":"2024-01-11T14:19:35.663391Z","shell.execute_reply":"2024-01-11T14:19:35.674504Z"},"trusted":true},"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.status.busy":"2024-01-11T14:19:35.678176Z","iopub.execute_input":"2024-01-11T14:19:35.678635Z","iopub.status.idle":"2024-01-11T14:19:35.701335Z","shell.execute_reply.started":"2024-01-11T14:19:35.678585Z","shell.execute_reply":"2024-01-11T14:19:35.699702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.703181Z","iopub.execute_input":"2024-01-11T14:19:35.703652Z","iopub.status.idle":"2024-01-11T14:19:35.738900Z","shell.execute_reply.started":"2024-01-11T14:19:35.703610Z","shell.execute_reply":"2024-01-11T14:19:35.737653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('playback_used', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.740531Z","iopub.execute_input":"2024-01-11T14:19:35.740994Z","iopub.status.idle":"2024-01-11T14:19:35.760583Z","shell.execute_reply.started":"2024-01-11T14:19:35.740947Z","shell.execute_reply":"2024-01-11T14:19:35.758831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ebird_code'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.762449Z","iopub.execute_input":"2024-01-11T14:19:35.763292Z","iopub.status.idle":"2024-01-11T14:19:35.779217Z","shell.execute_reply.started":"2024-01-11T14:19:35.763248Z","shell.execute_reply":"2024-01-11T14:19:35.776867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ebird_code'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.781536Z","iopub.execute_input":"2024-01-11T14:19:35.782160Z","iopub.status.idle":"2024-01-11T14:19:35.795258Z","shell.execute_reply.started":"2024-01-11T14:19:35.782103Z","shell.execute_reply":"2024-01-11T14:19:35.793333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.797434Z","iopub.execute_input":"2024-01-11T14:19:35.798341Z","iopub.status.idle":"2024-01-11T14:19:35.815183Z","shell.execute_reply.started":"2024-01-11T14:19:35.798273Z","shell.execute_reply":"2024-01-11T14:19:35.813432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels']=df['channels'].astype(str).str[0].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.817681Z","iopub.execute_input":"2024-01-11T14:19:35.818412Z","iopub.status.idle":"2024-01-11T14:19:35.854306Z","shell.execute_reply.started":"2024-01-11T14:19:35.818348Z","shell.execute_reply":"2024-01-11T14:19:35.852970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['channels'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.856338Z","iopub.execute_input":"2024-01-11T14:19:35.856803Z","iopub.status.idle":"2024-01-11T14:19:35.866345Z","shell.execute_reply.started":"2024-01-11T14:19:35.856757Z","shell.execute_reply":"2024-01-11T14:19:35.865343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.868157Z","iopub.execute_input":"2024-01-11T14:19:35.868634Z","iopub.status.idle":"2024-01-11T14:19:35.884725Z","shell.execute_reply.started":"2024-01-11T14:19:35.868595Z","shell.execute_reply":"2024-01-11T14:19:35.883277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.886569Z","iopub.execute_input":"2024-01-11T14:19:35.887032Z","iopub.status.idle":"2024-01-11T14:19:35.902625Z","shell.execute_reply.started":"2024-01-11T14:19:35.886994Z","shell.execute_reply":"2024-01-11T14:19:35.900894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['year']=df['date'].apply(lambda x: x.split('-')[0]).astype(int)\ndf['month']=df['date'].apply(lambda x: x.split('-')[1]).astype(int)\ndf['day_of_month']=df['date'].apply(lambda x: x.split('-')[2]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.904544Z","iopub.execute_input":"2024-01-11T14:19:35.905057Z","iopub.status.idle":"2024-01-11T14:19:35.978424Z","shell.execute_reply.started":"2024-01-11T14:19:35.905017Z","shell.execute_reply":"2024-01-11T14:19:35.976703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('date',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:35.982918Z","iopub.execute_input":"2024-01-11T14:19:35.983570Z","iopub.status.idle":"2024-01-11T14:19:36.008325Z","shell.execute_reply.started":"2024-01-11T14:19:35.983512Z","shell.execute_reply":"2024-01-11T14:19:36.006996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.010234Z","iopub.execute_input":"2024-01-11T14:19:36.010789Z","iopub.status.idle":"2024-01-11T14:19:36.055784Z","shell.execute_reply.started":"2024-01-11T14:19:36.010726Z","shell.execute_reply":"2024-01-11T14:19:36.054175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.057601Z","iopub.execute_input":"2024-01-11T14:19:36.058109Z","iopub.status.idle":"2024-01-11T14:19:36.148609Z","shell.execute_reply.started":"2024-01-11T14:19:36.058066Z","shell.execute_reply":"2024-01-11T14:19:36.146684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.151039Z","iopub.execute_input":"2024-01-11T14:19:36.152091Z","iopub.status.idle":"2024-01-11T14:19:36.165798Z","shell.execute_reply.started":"2024-01-11T14:19:36.152031Z","shell.execute_reply":"2024-01-11T14:19:36.163801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['pitch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.168468Z","iopub.execute_input":"2024-01-11T14:19:36.169068Z","iopub.status.idle":"2024-01-11T14:19:36.186590Z","shell.execute_reply.started":"2024-01-11T14:19:36.169014Z","shell.execute_reply":"2024-01-11T14:19:36.184819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['duration'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.188336Z","iopub.execute_input":"2024-01-11T14:19:36.189243Z","iopub.status.idle":"2024-01-11T14:19:36.205821Z","shell.execute_reply.started":"2024-01-11T14:19:36.189184Z","shell.execute_reply":"2024-01-11T14:19:36.204012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].unique()\ndf['species'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.208881Z","iopub.execute_input":"2024-01-11T14:19:36.209404Z","iopub.status.idle":"2024-01-11T14:19:36.232688Z","shell.execute_reply.started":"2024-01-11T14:19:36.209362Z","shell.execute_reply":"2024-01-11T14:19:36.231622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['speed'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.234552Z","iopub.execute_input":"2024-01-11T14:19:36.235015Z","iopub.status.idle":"2024-01-11T14:19:36.252366Z","shell.execute_reply.started":"2024-01-11T14:19:36.234978Z","shell.execute_reply":"2024-01-11T14:19:36.250826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.254902Z","iopub.execute_input":"2024-01-11T14:19:36.255422Z","iopub.status.idle":"2024-01-11T14:19:36.268779Z","shell.execute_reply.started":"2024-01-11T14:19:36.255373Z","shell.execute_reply":"2024-01-11T14:19:36.267111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['number_of_notes'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.271146Z","iopub.execute_input":"2024-01-11T14:19:36.271718Z","iopub.status.idle":"2024-01-11T14:19:36.285156Z","shell.execute_reply.started":"2024-01-11T14:19:36.271666Z","shell.execute_reply":"2024-01-11T14:19:36.283670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['title'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.287560Z","iopub.execute_input":"2024-01-11T14:19:36.288158Z","iopub.status.idle":"2024-01-11T14:19:36.309500Z","shell.execute_reply.started":"2024-01-11T14:19:36.288095Z","shell.execute_reply":"2024-01-11T14:19:36.308058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('title', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.311485Z","iopub.execute_input":"2024-01-11T14:19:36.312570Z","iopub.status.idle":"2024-01-11T14:19:36.333492Z","shell.execute_reply.started":"2024-01-11T14:19:36.312510Z","shell.execute_reply":"2024-01-11T14:19:36.332321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['secondary_labels'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.335094Z","iopub.execute_input":"2024-01-11T14:19:36.336544Z","iopub.status.idle":"2024-01-11T14:19:36.351227Z","shell.execute_reply.started":"2024-01-11T14:19:36.336493Z","shell.execute_reply":"2024-01-11T14:19:36.350120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.353272Z","iopub.execute_input":"2024-01-11T14:19:36.353819Z","iopub.status.idle":"2024-01-11T14:19:36.367059Z","shell.execute_reply.started":"2024-01-11T14:19:36.353765Z","shell.execute_reply":"2024-01-11T14:19:36.365504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bird_seen'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.371208Z","iopub.execute_input":"2024-01-11T14:19:36.373094Z","iopub.status.idle":"2024-01-11T14:19:36.390871Z","shell.execute_reply.started":"2024-01-11T14:19:36.373031Z","shell.execute_reply":"2024-01-11T14:19:36.389452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sci_name'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.407157Z","iopub.execute_input":"2024-01-11T14:19:36.408205Z","iopub.status.idle":"2024-01-11T14:19:36.419326Z","shell.execute_reply.started":"2024-01-11T14:19:36.408155Z","shell.execute_reply":"2024-01-11T14:19:36.417470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['location'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.421505Z","iopub.execute_input":"2024-01-11T14:19:36.421980Z","iopub.status.idle":"2024-01-11T14:19:36.439429Z","shell.execute_reply.started":"2024-01-11T14:19:36.421940Z","shell.execute_reply":"2024-01-11T14:19:36.438309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.441176Z","iopub.execute_input":"2024-01-11T14:19:36.441629Z","iopub.status.idle":"2024-01-11T14:19:36.455558Z","shell.execute_reply.started":"2024-01-11T14:19:36.441590Z","shell.execute_reply":"2024-01-11T14:19:36.454263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df[df['latitude']!='Not specified']\ndf=df[df['longitude']!='Not specified']","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.457546Z","iopub.execute_input":"2024-01-11T14:19:36.459318Z","iopub.status.idle":"2024-01-11T14:19:36.529109Z","shell.execute_reply.started":"2024-01-11T14:19:36.459255Z","shell.execute_reply":"2024-01-11T14:19:36.527153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['latitude']=df['latitude'].astype(float)\ndf['longitude']=df['longitude'].astype(float)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.531071Z","iopub.execute_input":"2024-01-11T14:19:36.531635Z","iopub.status.idle":"2024-01-11T14:19:36.552551Z","shell.execute_reply.started":"2024-01-11T14:19:36.531579Z","shell.execute_reply":"2024-01-11T14:19:36.551344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.556485Z","iopub.execute_input":"2024-01-11T14:19:36.557453Z","iopub.status.idle":"2024-01-11T14:19:36.620347Z","shell.execute_reply.started":"2024-01-11T14:19:36.557395Z","shell.execute_reply":"2024-01-11T14:19:36.618854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.622283Z","iopub.execute_input":"2024-01-11T14:19:36.622851Z","iopub.status.idle":"2024-01-11T14:19:36.666693Z","shell.execute_reply.started":"2024-01-11T14:19:36.622798Z","shell.execute_reply":"2024-01-11T14:19:36.665296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.668731Z","iopub.execute_input":"2024-01-11T14:19:36.669871Z","iopub.status.idle":"2024-01-11T14:19:36.682496Z","shell.execute_reply.started":"2024-01-11T14:19:36.669820Z","shell.execute_reply":"2024-01-11T14:19:36.680782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate']=df['sampling_rate'].fillna(0).astype(str).apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.686303Z","iopub.execute_input":"2024-01-11T14:19:36.687044Z","iopub.status.idle":"2024-01-11T14:19:36.719263Z","shell.execute_reply.started":"2024-01-11T14:19:36.686952Z","shell.execute_reply":"2024-01-11T14:19:36.717711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sampling_rate'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.721329Z","iopub.execute_input":"2024-01-11T14:19:36.721827Z","iopub.status.idle":"2024-01-11T14:19:36.732805Z","shell.execute_reply.started":"2024-01-11T14:19:36.721784Z","shell.execute_reply":"2024-01-11T14:19:36.731140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.734952Z","iopub.execute_input":"2024-01-11T14:19:36.735402Z","iopub.status.idle":"2024-01-11T14:19:36.747822Z","shell.execute_reply.started":"2024-01-11T14:19:36.735365Z","shell.execute_reply":"2024-01-11T14:19:36.745963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.750161Z","iopub.execute_input":"2024-01-11T14:19:36.751313Z","iopub.status.idle":"2024-01-11T14:19:36.765168Z","shell.execute_reply.started":"2024-01-11T14:19:36.751259Z","shell.execute_reply":"2024-01-11T14:19:36.763208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adjusted_type=df['type'].astype(str).apply(lambda x: x.split(',')).reset_index().explode('type')\nadjusted_type=adjusted_type['type'].apply(lambda x: x.strip().lower()).reset_index()\nadjusted_type['type']=adjusted_type['type'].replace('calls','call')\nadjusted_type['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:36.767658Z","iopub.execute_input":"2024-01-11T14:19:36.768589Z","iopub.status.idle":"2024-01-11T14:19:37.306003Z","shell.execute_reply.started":"2024-01-11T14:19:36.768540Z","shell.execute_reply":"2024-01-11T14:19:37.304686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.307435Z","iopub.execute_input":"2024-01-11T14:19:37.307866Z","iopub.status.idle":"2024-01-11T14:19:37.347283Z","shell.execute_reply.started":"2024-01-11T14:19:37.307830Z","shell.execute_reply":"2024-01-11T14:19:37.345806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.349321Z","iopub.execute_input":"2024-01-11T14:19:37.349946Z","iopub.status.idle":"2024-01-11T14:19:37.363736Z","shell.execute_reply.started":"2024-01-11T14:19:37.349903Z","shell.execute_reply":"2024-01-11T14:19:37.362248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.366773Z","iopub.execute_input":"2024-01-11T14:19:37.367461Z","iopub.status.idle":"2024-01-11T14:19:37.388469Z","shell.execute_reply.started":"2024-01-11T14:19:37.367396Z","shell.execute_reply":"2024-01-11T14:19:37.387164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].replace(['? m','?? m','NaN', 'Unknown m', ' m', '-m'],'99999')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.390789Z","iopub.execute_input":"2024-01-11T14:19:37.391721Z","iopub.status.idle":"2024-01-11T14:19:37.413925Z","shell.execute_reply.started":"2024-01-11T14:19:37.391669Z","shell.execute_reply":"2024-01-11T14:19:37.412712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].str.replace(',','')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.416781Z","iopub.execute_input":"2024-01-11T14:19:37.417580Z","iopub.status.idle":"2024-01-11T14:19:37.439100Z","shell.execute_reply.started":"2024-01-11T14:19:37.417536Z","shell.execute_reply":"2024-01-11T14:19:37.437224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].str.replace('.', '')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.441560Z","iopub.execute_input":"2024-01-11T14:19:37.442031Z","iopub.status.idle":"2024-01-11T14:19:37.462546Z","shell.execute_reply.started":"2024-01-11T14:19:37.441990Z","shell.execute_reply":"2024-01-11T14:19:37.461110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].str.replace('~', '')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.464440Z","iopub.execute_input":"2024-01-11T14:19:37.464909Z","iopub.status.idle":"2024-01-11T14:19:37.489436Z","shell.execute_reply.started":"2024-01-11T14:19:37.464872Z","shell.execute_reply":"2024-01-11T14:19:37.488290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for index, row in df.iterrows():\n  elevation=row['elevation']\n  if '-' in elevation and not elevation.startswith('-'):\n    #Replace range values with their minimum\n    range_values=elevation.split('-')\n    df.at[index, 'elevation']=min(int(range_values[0].strip(' m')), int(range_values[1].strip(' m')))","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:37.491239Z","iopub.execute_input":"2024-01-11T14:19:37.491988Z","iopub.status.idle":"2024-01-11T14:19:38.986342Z","shell.execute_reply.started":"2024-01-11T14:19:37.491945Z","shell.execute_reply":"2024-01-11T14:19:38.984802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.elevation=df['elevation'].str.replace('m','')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:38.988431Z","iopub.execute_input":"2024-01-11T14:19:38.988885Z","iopub.status.idle":"2024-01-11T14:19:39.026408Z","shell.execute_reply.started":"2024-01-11T14:19:38.988847Z","shell.execute_reply":"2024-01-11T14:19:39.025102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.elevation.fillna('99999',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:39.028403Z","iopub.execute_input":"2024-01-11T14:19:39.029290Z","iopub.status.idle":"2024-01-11T14:19:39.040942Z","shell.execute_reply.started":"2024-01-11T14:19:39.029245Z","shell.execute_reply":"2024-01-11T14:19:39.039307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.elevation.unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:39.043027Z","iopub.execute_input":"2024-01-11T14:19:39.043653Z","iopub.status.idle":"2024-01-11T14:19:39.062983Z","shell.execute_reply.started":"2024-01-11T14:19:39.043602Z","shell.execute_reply":"2024-01-11T14:19:39.061282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=pd.to_numeric(df['elevation'],errors='coerce')\nsum_elevation=0\ncount_valid_values=0\nfor index,row in df.iterrows():\n  if row['elevation']!=99999:\n    sum_elevation+=row['elevation']\n    count_valid_values+=1\nmean_elevation =sum_elevation/count_valid_values\nmean_elevation","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:39.065221Z","iopub.execute_input":"2024-01-11T14:19:39.066106Z","iopub.status.idle":"2024-01-11T14:19:40.806915Z","shell.execute_reply.started":"2024-01-11T14:19:39.066037Z","shell.execute_reply":"2024-01-11T14:19:40.805220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].mean()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.809476Z","iopub.execute_input":"2024-01-11T14:19:40.810338Z","iopub.status.idle":"2024-01-11T14:19:40.822857Z","shell.execute_reply.started":"2024-01-11T14:19:40.810270Z","shell.execute_reply":"2024-01-11T14:19:40.821612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation']=df['elevation'].replace(['99999'], mean_elevation)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.824945Z","iopub.execute_input":"2024-01-11T14:19:40.825552Z","iopub.status.idle":"2024-01-11T14:19:40.836266Z","shell.execute_reply.started":"2024-01-11T14:19:40.825504Z","shell.execute_reply":"2024-01-11T14:19:40.833819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.elevation.dtype","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.838436Z","iopub.execute_input":"2024-01-11T14:19:40.839023Z","iopub.status.idle":"2024-01-11T14:19:40.856199Z","shell.execute_reply.started":"2024-01-11T14:19:40.838969Z","shell.execute_reply":"2024-01-11T14:19:40.853860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['description'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.858254Z","iopub.execute_input":"2024-01-11T14:19:40.858881Z","iopub.status.idle":"2024-01-11T14:19:40.880505Z","shell.execute_reply.started":"2024-01-11T14:19:40.858821Z","shell.execute_reply":"2024-01-11T14:19:40.878823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('description', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.882677Z","iopub.execute_input":"2024-01-11T14:19:40.883323Z","iopub.status.idle":"2024-01-11T14:19:40.903806Z","shell.execute_reply.started":"2024-01-11T14:19:40.883262Z","shell.execute_reply":"2024-01-11T14:19:40.902256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.905395Z","iopub.execute_input":"2024-01-11T14:19:40.906031Z","iopub.status.idle":"2024-01-11T14:19:40.921484Z","shell.execute_reply.started":"2024-01-11T14:19:40.905975Z","shell.execute_reply":"2024-01-11T14:19:40.919602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.923679Z","iopub.execute_input":"2024-01-11T14:19:40.924214Z","iopub.status.idle":"2024-01-11T14:19:40.945557Z","shell.execute_reply.started":"2024-01-11T14:19:40.924175Z","shell.execute_reply":"2024-01-11T14:19:40.943727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3']==0]","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.947227Z","iopub.execute_input":"2024-01-11T14:19:40.947819Z","iopub.status.idle":"2024-01-11T14:19:40.977053Z","shell.execute_reply.started":"2024-01-11T14:19:40.947762Z","shell.execute_reply":"2024-01-11T14:19:40.975900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(df[df['bitrate_of_mp3']=='3'].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:40.978327Z","iopub.execute_input":"2024-01-11T14:19:40.978716Z","iopub.status.idle":"2024-01-11T14:19:41.007421Z","shell.execute_reply.started":"2024-01-11T14:19:40.978672Z","shell.execute_reply":"2024-01-11T14:19:41.005381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['bitrate_of_mp3'].isna()]","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.009539Z","iopub.execute_input":"2024-01-11T14:19:41.010060Z","iopub.status.idle":"2024-01-11T14:19:41.059520Z","shell.execute_reply.started":"2024-01-11T14:19:41.010005Z","shell.execute_reply":"2024-01-11T14:19:41.058007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3']=df['bitrate_of_mp3'].fillna('0')\ndf['bitrate_of_mp3']=df['bitrate_of_mp3'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.061678Z","iopub.execute_input":"2024-01-11T14:19:41.062182Z","iopub.status.idle":"2024-01-11T14:19:41.096632Z","shell.execute_reply.started":"2024-01-11T14:19:41.062142Z","shell.execute_reply":"2024-01-11T14:19:41.095332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m=df['bitrate_of_mp3'].mean()\nm","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.098639Z","iopub.execute_input":"2024-01-11T14:19:41.099618Z","iopub.status.idle":"2024-01-11T14:19:41.110635Z","shell.execute_reply.started":"2024-01-11T14:19:41.099560Z","shell.execute_reply":"2024-01-11T14:19:41.108534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3']=df['bitrate_of_mp3'].replace(0,m)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.113412Z","iopub.execute_input":"2024-01-11T14:19:41.114395Z","iopub.status.idle":"2024-01-11T14:19:41.125940Z","shell.execute_reply.started":"2024-01-11T14:19:41.114333Z","shell.execute_reply":"2024-01-11T14:19:41.124800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.127859Z","iopub.execute_input":"2024-01-11T14:19:41.128793Z","iopub.status.idle":"2024-01-11T14:19:41.169796Z","shell.execute_reply.started":"2024-01-11T14:19:41.128714Z","shell.execute_reply":"2024-01-11T14:19:41.168628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['file_type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.171316Z","iopub.execute_input":"2024-01-11T14:19:41.172137Z","iopub.status.idle":"2024-01-11T14:19:41.195320Z","shell.execute_reply.started":"2024-01-11T14:19:41.172090Z","shell.execute_reply":"2024-01-11T14:19:41.193626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['volume'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.197925Z","iopub.execute_input":"2024-01-11T14:19:41.198459Z","iopub.status.idle":"2024-01-11T14:19:41.211476Z","shell.execute_reply.started":"2024-01-11T14:19:41.198421Z","shell.execute_reply":"2024-01-11T14:19:41.209803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['background'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.213157Z","iopub.execute_input":"2024-01-11T14:19:41.213586Z","iopub.status.idle":"2024-01-11T14:19:41.232085Z","shell.execute_reply.started":"2024-01-11T14:19:41.213550Z","shell.execute_reply":"2024-01-11T14:19:41.230451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['background'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.234302Z","iopub.execute_input":"2024-01-11T14:19:41.235003Z","iopub.status.idle":"2024-01-11T14:19:41.254046Z","shell.execute_reply.started":"2024-01-11T14:19:41.234958Z","shell.execute_reply":"2024-01-11T14:19:41.252763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('background',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.255148Z","iopub.execute_input":"2024-01-11T14:19:41.255475Z","iopub.status.idle":"2024-01-11T14:19:41.269816Z","shell.execute_reply.started":"2024-01-11T14:19:41.255445Z","shell.execute_reply":"2024-01-11T14:19:41.268329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['xc_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.271389Z","iopub.execute_input":"2024-01-11T14:19:41.273017Z","iopub.status.idle":"2024-01-11T14:19:41.284698Z","shell.execute_reply.started":"2024-01-11T14:19:41.272955Z","shell.execute_reply":"2024-01-11T14:19:41.283237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('xc_id',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.286794Z","iopub.execute_input":"2024-01-11T14:19:41.287670Z","iopub.status.idle":"2024-01-11T14:19:41.305107Z","shell.execute_reply.started":"2024-01-11T14:19:41.287613Z","shell.execute_reply":"2024-01-11T14:19:41.302722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.306813Z","iopub.execute_input":"2024-01-11T14:19:41.308642Z","iopub.status.idle":"2024-01-11T14:19:41.348093Z","shell.execute_reply.started":"2024-01-11T14:19:41.308596Z","shell.execute_reply":"2024-01-11T14:19:41.345950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['url'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.350617Z","iopub.execute_input":"2024-01-11T14:19:41.351239Z","iopub.status.idle":"2024-01-11T14:19:41.373870Z","shell.execute_reply.started":"2024-01-11T14:19:41.351185Z","shell.execute_reply":"2024-01-11T14:19:41.371862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('url',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.376440Z","iopub.execute_input":"2024-01-11T14:19:41.376999Z","iopub.status.idle":"2024-01-11T14:19:41.391624Z","shell.execute_reply.started":"2024-01-11T14:19:41.376956Z","shell.execute_reply":"2024-01-11T14:19:41.390036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.394368Z","iopub.execute_input":"2024-01-11T14:19:41.394931Z","iopub.status.idle":"2024-01-11T14:19:41.408534Z","shell.execute_reply.started":"2024-01-11T14:19:41.394887Z","shell.execute_reply":"2024-01-11T14:19:41.407249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['author'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.410895Z","iopub.execute_input":"2024-01-11T14:19:41.411445Z","iopub.status.idle":"2024-01-11T14:19:41.424993Z","shell.execute_reply.started":"2024-01-11T14:19:41.411406Z","shell.execute_reply":"2024-01-11T14:19:41.422946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['recordist'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.427100Z","iopub.execute_input":"2024-01-11T14:19:41.427721Z","iopub.status.idle":"2024-01-11T14:19:41.441384Z","shell.execute_reply.started":"2024-01-11T14:19:41.427679Z","shell.execute_reply":"2024-01-11T14:19:41.439681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['author']!=df['recordist']]","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.442695Z","iopub.execute_input":"2024-01-11T14:19:41.443508Z","iopub.status.idle":"2024-01-11T14:19:41.470184Z","shell.execute_reply.started":"2024-01-11T14:19:41.443457Z","shell.execute_reply":"2024-01-11T14:19:41.468149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('author', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.472242Z","iopub.execute_input":"2024-01-11T14:19:41.472853Z","iopub.status.idle":"2024-01-11T14:19:41.491238Z","shell.execute_reply.started":"2024-01-11T14:19:41.472804Z","shell.execute_reply":"2024-01-11T14:19:41.489337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['primary_label'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.493475Z","iopub.execute_input":"2024-01-11T14:19:41.494003Z","iopub.status.idle":"2024-01-11T14:19:41.510349Z","shell.execute_reply.started":"2024-01-11T14:19:41.493960Z","shell.execute_reply":"2024-01-11T14:19:41.509182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.511957Z","iopub.execute_input":"2024-01-11T14:19:41.513280Z","iopub.status.idle":"2024-01-11T14:19:41.524184Z","shell.execute_reply.started":"2024-01-11T14:19:41.513234Z","shell.execute_reply":"2024-01-11T14:19:41.522623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value']=df['length'].str.extract(r'(\\d+)')\ndf['min_value']=pd.to_numeric(df['min_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.526996Z","iopub.execute_input":"2024-01-11T14:19:41.528235Z","iopub.status.idle":"2024-01-11T14:19:41.617231Z","shell.execute_reply.started":"2024-01-11T14:19:41.528177Z","shell.execute_reply":"2024-01-11T14:19:41.615840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['min_value'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.619481Z","iopub.execute_input":"2024-01-11T14:19:41.620041Z","iopub.status.idle":"2024-01-11T14:19:41.629861Z","shell.execute_reply.started":"2024-01-11T14:19:41.619991Z","shell.execute_reply":"2024-01-11T14:19:41.628168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value']=df['length'].str.extract(r'-(\\d+)')\ndf['max_value']=pd.to_numeric(df['max_value'],errors='coerce')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.632708Z","iopub.execute_input":"2024-01-11T14:19:41.633686Z","iopub.status.idle":"2024-01-11T14:19:41.713379Z","shell.execute_reply.started":"2024-01-11T14:19:41.633562Z","shell.execute_reply":"2024-01-11T14:19:41.712339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['max_value'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.714943Z","iopub.execute_input":"2024-01-11T14:19:41.715567Z","iopub.status.idle":"2024-01-11T14:19:41.725518Z","shell.execute_reply.started":"2024-01-11T14:19:41.715527Z","shell.execute_reply":"2024-01-11T14:19:41.724167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['time'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.728156Z","iopub.execute_input":"2024-01-11T14:19:41.728965Z","iopub.status.idle":"2024-01-11T14:19:41.744781Z","shell.execute_reply.started":"2024-01-11T14:19:41.728920Z","shell.execute_reply":"2024-01-11T14:19:41.743360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('time',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.746041Z","iopub.execute_input":"2024-01-11T14:19:41.746423Z","iopub.status.idle":"2024-01-11T14:19:41.764143Z","shell.execute_reply.started":"2024-01-11T14:19:41.746390Z","shell.execute_reply":"2024-01-11T14:19:41.762838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['license'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.766087Z","iopub.execute_input":"2024-01-11T14:19:41.767321Z","iopub.status.idle":"2024-01-11T14:19:41.781056Z","shell.execute_reply.started":"2024-01-11T14:19:41.767263Z","shell.execute_reply":"2024-01-11T14:19:41.779681Z"},"trusted":true},"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_mapping=dict(zip(df['license'], df['license_encoded']))\nprint(\"Label Encoded Unique Values: \", encoded_unique_values)\nprint(\"Label Mapping: \", label_mapping)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.782824Z","iopub.execute_input":"2024-01-11T14:19:41.783582Z","iopub.status.idle":"2024-01-11T14:19:41.809152Z","shell.execute_reply.started":"2024-01-11T14:19:41.783536Z","shell.execute_reply":"2024-01-11T14:19:41.807457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('license',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.810987Z","iopub.execute_input":"2024-01-11T14:19:41.811535Z","iopub.status.idle":"2024-01-11T14:19:41.831895Z","shell.execute_reply.started":"2024-01-11T14:19:41.811481Z","shell.execute_reply":"2024-01-11T14:19:41.830192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.835431Z","iopub.execute_input":"2024-01-11T14:19:41.836126Z","iopub.status.idle":"2024-01-11T14:19:41.880631Z","shell.execute_reply.started":"2024-01-11T14:19:41.836069Z","shell.execute_reply":"2024-01-11T14:19:41.879052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.882242Z","iopub.execute_input":"2024-01-11T14:19:41.883132Z","iopub.status.idle":"2024-01-11T14:19:41.973343Z","shell.execute_reply.started":"2024-01-11T14:19:41.883076Z","shell.execute_reply":"2024-01-11T14:19:41.971858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style='white')\nplt.figure(figsize=(10,6))\nsns.countplot(x='rating',data=df,order=df['rating'].value_counts().index,palette='Set1')\nplt.title('Distribution of Ratings')\nplt.xlabel('Rating')\nplt.ylabel('Count')\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:41.975129Z","iopub.execute_input":"2024-01-11T14:19:41.975572Z","iopub.status.idle":"2024-01-11T14:19:42.482174Z","shell.execute_reply.started":"2024-01-11T14:19:41.975536Z","shell.execute_reply":"2024-01-11T14:19:42.480712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style='ticks')\nplt.figure(figsize=(10,6))\nsns.countplot(y='playback_used_encoded',data=df,palette='Set2')\nplt.title('Distribution of Playback Used')\nplt.xlabel('Count')\nplt.ylabel('Playback Used')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:42.484313Z","iopub.execute_input":"2024-01-11T14:19:42.484860Z","iopub.status.idle":"2024-01-11T14:19:42.786560Z","shell.execute_reply.started":"2024-01-11T14:19:42.484805Z","shell.execute_reply":"2024-01-11T14:19:42.785370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.countplot(x='rating', hue='playback_used_encoded', data=df, palette='pastel')\nplt.title('Rating versus Playback Used')\nplt.xlabel('Rating')\nplt.ylabel('Count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:42.788365Z","iopub.execute_input":"2024-01-11T14:19:42.789026Z","iopub.status.idle":"2024-01-11T14:19:43.259033Z","shell.execute_reply.started":"2024-01-11T14:19:42.788983Z","shell.execute_reply":"2024-01-11T14:19:43.257825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_count=df['number_of_notes'].value_counts()\ncustom_colors=[(239/255, 71/255, 111/255, 1),(247/255, 140/255, 107/255, 1),(255/255, 209/255, 102/255, 1),(6/255, 214/255, 160/255, 1),(17/255, 138/255, 178/255, 1)]\nplt.figure(figsize=(10,10))\nplt.pie(values_count,labels=None, autopct='%1.1f%%', startangle=90,colors=custom_colors, wedgeprops=dict(width=0.3) )\nplt.gca().set_facecolor('#07384C')\nplt.title(f'Distribution of number of notes', fontsize=15)\nplt.legend(values_count.index, title='Categories', loc='upper right',bbox_to_anchor=(1,0,0.5,1))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:43.261040Z","iopub.execute_input":"2024-01-11T14:19:43.261895Z","iopub.status.idle":"2024-01-11T14:19:43.634979Z","shell.execute_reply.started":"2024-01-11T14:19:43.261855Z","shell.execute_reply":"2024-01-11T14:19:43.633215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sns.countplot(x='month', data=data)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:19:43.636635Z","iopub.execute_input":"2024-01-11T14:19:43.637113Z","iopub.status.idle":"2024-01-11T14:19:43.762607Z","shell.execute_reply.started":"2024-01-11T14:19:43.637065Z","shell.execute_reply":"2024-01-11T14:19:43.759554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Feature Extraction**","metadata":{}},{"cell_type":"code","source":"import librosa\nimport librosa.display\nimport soundfile as sf\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:19.970636Z","iopub.execute_input":"2024-01-11T14:20:19.971263Z","iopub.status.idle":"2024-01-11T14:20:19.980525Z","shell.execute_reply.started":"2024-01-11T14:20:19.971206Z","shell.execute_reply":"2024-01-11T14:20:19.978841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amecro1=\"/kaggle/input/birdsong-recognition/train_audio/amecro/XC109768.mp3\"\namecro2=\"/kaggle/input/birdsong-recognition/train_audio/amecro/XC114554.mp3\"\nbalori1=\"/kaggle/input/birdsong-recognition/train_audio/balori/XC101614.mp3\"\nbalori2=\"/kaggle/input/birdsong-recognition/train_audio/balori/XC139729.mp3\"\nbrebia1=\"/kaggle/input/birdsong-recognition/train_audio/brebla/XC104521.mp3\"\nbrebia2=\"/kaggle/input/birdsong-recognition/train_audio/brebla/XC205761.mp3\"\ncalgul1=\"/kaggle/input/birdsong-recognition/train_audio/calgul/XC161039.mp3\"\ncalgul2=\"/kaggle/input/birdsong-recognition/train_audio/calgul/XC109695.mp3\"\ncomnig1=\"/kaggle/input/birdsong-recognition/train_audio/comnig/XC152345.mp3\"\ncomnig2=\"/kaggle/input/birdsong-recognition/train_audio/comnig/XC186695.mp3\"","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:20.926042Z","iopub.execute_input":"2024-01-11T14:20:20.927467Z","iopub.status.idle":"2024-01-11T14:20:20.934388Z","shell.execute_reply.started":"2024-01-11T14:20:20.927410Z","shell.execute_reply":"2024-01-11T14:20:20.932985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_1, sr1_1 = librosa.load(amecro1)\ny1_2, sr1_2 = librosa.load(amecro2)\ny1_3, sr1_3 = librosa.load(balori1)\ny1_4, sr1_4 = librosa.load(balori2)\ny1_5, sr1_5 = librosa.load(brebia1)\ny2_1, sr2_1 = librosa.load(brebia2)\ny2_2, sr2_2 = librosa.load(calgul1)\ny2_3, sr2_3 = librosa.load(calgul2)\ny2_4, sr2_4 = librosa.load(comnig1)\ny2_5, sr2_5 = librosa.load(comnig2)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:22.052348Z","iopub.execute_input":"2024-01-11T14:20:22.052794Z","iopub.status.idle":"2024-01-11T14:20:22.612194Z","shell.execute_reply.started":"2024-01-11T14:20:22.052758Z","shell.execute_reply":"2024-01-11T14:20:22.610537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zcr1_1=librosa.feature.zero_crossing_rate(y1_1)\nzcr2_1=librosa.feature.zero_crossing_rate(y2_1)\nzcr1_2=librosa.feature.zero_crossing_rate(y1_2)\nzcr1_3=librosa.feature.zero_crossing_rate(y1_3)\nzcr1_4=librosa.feature.zero_crossing_rate(y1_4)\nzcr1_5=librosa.feature.zero_crossing_rate(y1_5)\nzcr2_2=librosa.feature.zero_crossing_rate(y2_2)\nzcr2_3=librosa.feature.zero_crossing_rate(y2_3)\nzcr2_4=librosa.feature.zero_crossing_rate(y2_4)\nzcr2_5=librosa.feature.zero_crossing_rate(y2_5)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:23.683032Z","iopub.execute_input":"2024-01-11T14:20:23.683575Z","iopub.status.idle":"2024-01-11T14:20:23.825140Z","shell.execute_reply.started":"2024-01-11T14:20:23.683533Z","shell.execute_reply":"2024-01-11T14:20:23.823464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"energy1_1=librosa.feature.rms(y=y1_1)\nenergy1_2=librosa.feature.rms(y=y1_2)\nenergy1_3=librosa.feature.rms(y=y1_3)\nenergy1_4=librosa.feature.rms(y=y1_4)\nenergy1_5=librosa.feature.rms(y=y1_5)\nenergy2_1=librosa.feature.rms(y=y2_1)\nenergy2_2=librosa.feature.rms(y=y2_2)\nenergy2_3=librosa.feature.rms(y=y2_3)\nenergy2_4=librosa.feature.rms(y=y2_4)\nenergy2_5=librosa.feature.rms(y=y2_5)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:24.083880Z","iopub.execute_input":"2024-01-11T14:20:24.084439Z","iopub.status.idle":"2024-01-11T14:20:24.541943Z","shell.execute_reply.started":"2024-01-11T14:20:24.084387Z","shell.execute_reply":"2024-01-11T14:20:24.540504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y1_1)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr1_1)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_3)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr1_3)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_5)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr1_5)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_2)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr2_2)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_4)), ref=np.max)\nfrequencies = librosa.fft_frequencies(sr=sr2_4)\nmin_frequency = np.min(frequencies)\nmax_frequency = np.max(frequencies)\nprint(\"Minimum Frequency:\", min_frequency, \"Hz\")\nprint(\"Maximum Frequency:\", max_frequency, \"Hz\")","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:24.545015Z","iopub.execute_input":"2024-01-11T14:20:24.545598Z","iopub.status.idle":"2024-01-11T14:20:24.786868Z","shell.execute_reply.started":"2024-01-11T14:20:24.545555Z","shell.execute_reply":"2024-01-11T14:20:24.785332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(zcr1_1[0], 'b')\nplt.plot(zcr1_2[0], 'b')\nplt.plot(zcr1_3[0], 'b')\nplt.plot(zcr1_4[0], 'b')\nplt.plot(zcr1_5[0], 'b')\nplt.plot(zcr2_1[0],'r')\nplt.plot(zcr2_2[0],'r')\nplt.plot(zcr2_3[0],'r')\nplt.plot(zcr2_4[0],'r')\nplt.plot(zcr2_5[0],'r')\nplt.title(\"Zero Crossing Rates\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:24.789093Z","iopub.execute_input":"2024-01-11T14:20:24.789511Z","iopub.status.idle":"2024-01-11T14:20:25.176359Z","shell.execute_reply.started":"2024-01-11T14:20:24.789475Z","shell.execute_reply":"2024-01-11T14:20:25.174823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"timeof1_1 = np.arange(0,len(y1_1))/sr1_1\ntimeof1_2 = np.arange(0,len(y1_2))/sr1_2\ntimeof1_3 = np.arange(0,len(y1_3))/sr1_3\ntimeof1_4 = np.arange(0,len(y1_4))/sr1_4\ntimeof1_5 = np.arange(0,len(y1_5))/sr1_5\nfig,ax=plt.subplots(5)\nax[0].plot(timeof1_1,y1_1)\nax[0].set(xlabel=\"Time(in seconds)\")\nax[1].plot(timeof1_2,y1_2)\nax[1].set(xlabel=\"Time(in seconds)\")\nax[2].plot(timeof1_3,y1_3)\nax[2].set(xlabel=\"Time(in seconds)\",ylabel='Sound Amplitude')\nax[3].plot(timeof1_4,y1_4)\nax[3].set(xlabel=\"Time(in seconds)\")\nax[4].plot(timeof1_5,y1_5)\nax[4].set(xlabel=\"Time(in seconds)\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:23:58.871433Z","iopub.execute_input":"2024-01-11T14:23:58.871931Z","iopub.status.idle":"2024-01-11T14:24:00.841704Z","shell.execute_reply.started":"2024-01-11T14:23:58.871892Z","shell.execute_reply":"2024-01-11T14:24:00.840263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pitch1_1, magnitude1_1=librosa.piptrack(y=y1_1, sr=sr1_1)\npitch1_2, magnitude1_2=librosa.piptrack(y=y1_2, sr=sr1_2)\nplt.plot(pitch1_1, 'r')\nplt.plot(pitch1_2, 'r')\nplt.show()\npitch1_3, magnitude1_3=librosa.piptrack(y=y1_3, sr=sr1_3)\npitch1_4, magnitude1_4=librosa.piptrack(y=y1_4, sr=sr1_4)\nplt.plot(pitch1_3, 'b')\nplt.plot(pitch1_4, 'b')\nplt.show()\npitch1_5, magnitude1_5=librosa.piptrack(y=y1_5, sr=sr1_5)\npitch2_1, magnitude1_1=librosa.piptrack(y=y2_1, sr=sr2_1)\nplt.plot(pitch1_5, 'r')\nplt.plot(pitch2_1, 'r')\nplt.show()\npitch2_2, magnitude1_2=librosa.piptrack(y=y2_2, sr=sr2_2)\npitch2_3, magnitude1_3=librosa.piptrack(y=y2_3, sr=sr2_3)\nplt.plot(pitch2_2, 'b')\nplt.plot(pitch2_3, 'b')\nplt.show()\npitch2_4, magnitude1_4=librosa.piptrack(y=y2_4, sr=sr2_4)\npitch2_5, magnitude1_5=librosa.piptrack(y=y2_5, sr=sr2_5)\nplt.plot(pitch2_4, 'r')\nplt.plot(pitch2_5, 'r')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:26:50.845286Z","iopub.execute_input":"2024-01-11T14:26:50.845827Z","iopub.status.idle":"2024-01-11T14:27:22.618307Z","shell.execute_reply.started":"2024-01-11T14:26:50.845788Z","shell.execute_reply":"2024-01-11T14:27:22.616771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.amplitude_to_db(np.abs(librosa.stft(y1_1)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr1_1, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of Amecro 1')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_2)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr1_2, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 2 of Amecro')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_3)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr1_3, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 1 of Balori')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_4)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr1_4, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 2 of Balori')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y1_5)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr1_5, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 1 of Brebia')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_1)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr2_1, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 2 of Brebia')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_2)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr2_2, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 1 of Calgul')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_3)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr2_3, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 2 of Calgul')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_4)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr2_4, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 1 of Comnig')\nplt.show()\nD = librosa.amplitude_to_db(np.abs(librosa.stft(y2_5)), ref=np.max)\nlibrosa.display.specshow(D, sr=sr2_5, x_axis='time', y_axis='log')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Spectrogram of the Audio 2 of Comnig')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:42:02.264103Z","iopub.execute_input":"2024-01-11T14:42:02.264664Z","iopub.status.idle":"2024-01-11T14:42:15.759287Z","shell.execute_reply.started":"2024-01-11T14:42:02.264622Z","shell.execute_reply":"2024-01-11T14:42:15.757893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import cv2\nimport audioread\nimport logging\nimport os\nimport random\nimport time\nimport warnings\nimport librosa\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\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Optional\nfrom fastprogress import progress_bar\nfrom sklearn.metrics import f1_score\nfrom torchvision import models","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:25.562867Z","iopub.execute_input":"2024-01-11T14:20:25.563392Z","iopub.status.idle":"2024-01-11T14:20:25.576754Z","shell.execute_reply.started":"2024-01-11T14:20:25.563353Z","shell.execute_reply":"2024-01-11T14:20:25.574888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_seed(seed: int=42):\n        random.seed(seed)\n        np.random.seed(seed)\n        os.environ[\"PYTHONHASHSEED\"]=str(seed)\n        torch.manual_seed(seed)\n        torch.cuda.manual_seed(seed)\n        torch.backends.cudnn.deterministic = True\n        torch.backends.cudnn.benchmark= True","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:25.768494Z","iopub.execute_input":"2024-01-11T14:20:25.769032Z","iopub.status.idle":"2024-01-11T14:20:25.777399Z","shell.execute_reply.started":"2024-01-11T14:20:25.768988Z","shell.execute_reply":"2024-01-11T14:20:25.775690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_logger(out_file=None):\n    logger= logging.getLogger()\n    formatter= logging.Formatter(\"%(asctime)s - %(levelname)s - %(message)s\")\n    logger.handlers = []\n    logger.setLevel(logging.INFO)\n    \n    handler = logging.StreamHandler()\n    handler.setFormatter(formatter)\n    handler.setLevel(logging.INFO)\n    logger.addHandler(handler)\n    \n    if out_file is not None:\n        fh= logging.FileHandler(out_file)\n        fh.setFormatter(formatter)\n        fh.setLevel(logging.INFO)\n        logger.addHandler(fh)\n    logger.info(\"logger set up\")\n    return logger\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@contextmanager #measure execution time\ndef timer(name: str, logger: Optional[logging.Logger]= None):\n    t0= time.time()\n    msg= f\"[{name}] start\"\n    if logger is None:\n        print(msg)\n    else:\n        logger.info(msg)    \n    yield\n    \n    msg=f\"[{name}] done in {time.time() - t0:.2f} s\"\n    if logger is None:\n        print(msg)\n    else:\n        logger.info(msg)   ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:25.947726Z","iopub.execute_input":"2024-01-11T14:20:25.948208Z","iopub.status.idle":"2024-01-11T14:20:25.965205Z","shell.execute_reply.started":"2024-01-11T14:20:25.948171Z","shell.execute_reply":"2024-01-11T14:20:25.963081Z"},"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-11T14:20:26.113115Z","iopub.execute_input":"2024-01-11T14:20:26.113546Z","iopub.status.idle":"2024-01-11T14:20:26.132175Z","shell.execute_reply.started":"2024-01-11T14:20:26.113513Z","shell.execute_reply":"2024-01-11T14:20:26.130084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TARGET_SR=32000","metadata":{"execution":{"iopub.status.busy":"2024-01-11T14:20:26.493587Z","iopub.execute_input":"2024-01-11T14:20:26.494106Z","iopub.status.idle":"2024-01-11T14:20:26.500729Z","shell.execute_reply.started":"2024-01-11T14:20:26.494066Z","shell.execute_reply":"2024-01-11T14:20:26.499112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/birdcall-check/test.csv\")\ntest_audio = \"/kaggle/input/birdcall-check/test_audio\"\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:18.694495Z","iopub.execute_input":"2024-01-11T15:02:18.695356Z","iopub.status.idle":"2024-01-11T15:02:18.715372Z","shell.execute_reply.started":"2024-01-11T15:02:18.695309Z","shell.execute_reply":"2024-01-11T15:02:18.713973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ResNet(nn.Module): #base class\n    def __init__(self, base_model_name: str, pretrained=False, #constructor #weights \n                 num_classes=264): #constructor method\n        super().__init__()\n        base_model = models.__getattribute__(base_model_name)(\n              pretrained=pretrained)\n        layers= list(base_model.children())[:-2]\n        layers.append(nn.AdaptiveMaxPool2d(1))\n        self.encoder = nn.Sequential(*layers)\n        \n        in_features=base_model.fc.in_features  #number of input features\n        \n        self.classifier = nn.Sequential(\n          nn.Linear(in_features,1024), nn.ReLU(), nn.Dropout(p=0.2),\n          nn.Linear(1024,1024), nn.ReLU(), nn.Dropout(p=0.2),\n          nn.Linear(1024, num_classes))\n    def forward(self,x):\n        batch_size= x.size(0)\n        x= self.encoder(x).view(batch_size, -1)\n        x= self.classifier(x)\n        multiclass_proba = F.softmax(x, dim=1)\n        multilabel_proba = F.sigmoid(x)\n        \n        return {\n            \"logits\":x,\n            \"multiclass_proba\": multiclass_proba,\n            \"multilabel_proba\": multilabel_proba\n        }    ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:19.454354Z","iopub.execute_input":"2024-01-11T15:02:19.454806Z","iopub.status.idle":"2024-01-11T15:02:19.466415Z","shell.execute_reply.started":"2024-01-11T15:02:19.454768Z","shell.execute_reply":"2024-01-11T15:02:19.465315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_config ={\n    \"base_model_name\": \"resnet50\",\n    \"pretrained\": False,\n    \"num_classes\": 264   \n}\n\nmelspectrogram_parameters ={\n    \"n_mels\": 128,\n    \"fmin\": 0,\n    \"fmax\":12000\n}\nimport os\n\nweights_path = '/kaggle/input/birdcall-resnet50-init-weights/best.pth'\n#weights_path = \"../input/birdcall-resnet50-init-weights/best.pth\"","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:22.568891Z","iopub.execute_input":"2024-01-11T15:02:22.569341Z","iopub.status.idle":"2024-01-11T15:02:22.576137Z","shell.execute_reply.started":"2024-01-11T15:02:22.569305Z","shell.execute_reply":"2024-01-11T15:02:22.574801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\ndf=pd.read_csv(\"/kaggle/input/birdsong-recognition/train.csv\")\n\nunique_bird_names = df['ebird_code'].unique()\nlabel_encoder = LabelEncoder()\nencoded_labels = label_encoder.fit_transform(unique_bird_names)\n\nBIRD_CODE = dict(zip(unique_bird_names,encoded_labels))\n\n# for bird_name, label in BIRD_CODE.items():\n#     print(f\"{bird_name}: {label}\")\n\nINV_BIRD_CODE={v: k for k, v in BIRD_CODE.items()}","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:23.054757Z","iopub.execute_input":"2024-01-11T15:02:23.055193Z","iopub.status.idle":"2024-01-11T15:02:23.478600Z","shell.execute_reply.started":"2024-01-11T15:02:23.055157Z","shell.execute_reply":"2024-01-11T15:02:23.477211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def mono_to_color(X:np.ndarray,mean=None,std=None,norm_max=None,norm_min= None,eps=1e-6):\n    X=np.stack([X,X,X],axis=-1)\n    \n    mean = mean or X.mean()\n    X=X-mean\n    std=std or X.std()\n    Xstd= X/(std+eps)\n    \n    _min,_max= Xstd.min(),Xstd.max()\n    norm_max= norm_max or _max\n    norm_min= norm_min or _min\n    \n    if(_max - _min)>eps:\n        V=Xstd\n        V[V<norm_min]=norm_min\n        V[V>norm_max]=norm_max\n        \n        V=255*(V-norm_min)/(norm_max - norm_min)\n        V=V.astype(np.uint8)\n    else:\n        V=np.zeroes_like(Xstd, dtype=np.uint8)\n    return V\nclass TestDataset(data.Dataset):\n    def __init__(self,df:pd.DataFrame, clip:np.array,img_size=224,melspectrogram_parameters={}):\n        self.df=df\n        self.clip=clip\n        self.img_size= img_size\n        self.melspectrogram_parameters = melspectrogram_parameters\n        \n    def __len__(self):\n        return len(self.df)\n    \n    def __getitem__(self, idx: int):\n        SR = 32000\n\n        sample = self.df.loc[idx, :]  # return row\n        site = sample.site\n        row_id = sample.row_id\n\n        if site == \"site_3\":\n            y = self.clip.astype(np.float32)\n            len_y = len(y)\n            start = 0\n            end = SR * 5\n\n            images = []\n            while len_y > start:\n                y_batch = y[start:end].astype(np.float32)\n\n                if len(y_batch) != (SR * 5):\n                    break\n                start = end\n                end = end + SR * 5\n\n                melspec = librosa.feature.melspectrogram(y=y_batch, sr=SR, **self.melspectrogram_parameters)\n                melspec = librosa.power_to_db(melspec).astype(np.float32)\n\n                image = mono_to_color(melspec)\n\n                height, width, _ =image.shape\n\n                image = cv2.resize(image, (int(width * self.img_size / height), self.img_size))\n\n                image = np.moveaxis(image, 2, 0)  # color channel axis to the first dimension\n\n                image = (image / 255.0).astype(np.float32)\n                images.append(image)\n\n            images = np.asarray(images)\n\n            return images, row_id, site\n\n        else:\n\n            end_seconds = int(sample.seconds)\n            start_seconds = int(end_seconds - 5)\n            start_index = SR * start_seconds\n            end_index = SR * end_seconds\n\n            y = self.clip[start_index:end_index].astype(np.float32)\n\n            melspec = librosa.feature.melspectrogram(y=y, sr=SR, **self.melspectrogram_parameters)\n\n            melspec = librosa.power_to_db(melspec).astype(np.float32)\n\n            image = mono_to_color(melspec)\n            height, width, _ =image.shape\n            image = cv2.resize(image,(int(width * self.img_size / height),self.img_size))\n            image = np.moveaxis(image, 2, 0)\n            image = (image / 255.0).astype(np.float32)\n            \n            return image, row_id, site\n        ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:23.481172Z","iopub.execute_input":"2024-01-11T15:02:23.482164Z","iopub.status.idle":"2024-01-11T15:02:23.506889Z","shell.execute_reply.started":"2024-01-11T15:02:23.482113Z","shell.execute_reply":"2024-01-11T15:02:23.505225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model(config: dict, weights_path: str):\n    model = ResNet(**config)\n\n    # Load the checkpoint and map the tensors to the CPU if CUDA is not available\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n    checkpoint = torch.load(weights_path, map_location=device)\n\n    # Load the model's learned parameters\n    model.load_state_dict(checkpoint[\"model_state_dict\"])\n\n    # Move the model to the specified device\n    model.to(device)\n\n    # Set the model to evaluation mode\n    model.eval()\n\n    return model","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:23.792891Z","iopub.execute_input":"2024-01-11T15:02:23.793397Z","iopub.status.idle":"2024-01-11T15:02:23.800396Z","shell.execute_reply.started":"2024-01-11T15:02:23.793333Z","shell.execute_reply":"2024-01-11T15:02:23.799475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prediction_for_clip(test_df: pd.DataFrame,\n                        clip: np.ndarray,\n                        model: ResNet,\n                        mel_params: dict,\n                        threshold=0.5):\n\n\n    dataset = TestDataset(df=test_df,\n                          clip=clip,\n                          img_size=224,\n                          melspectrogram_parameters=mel_params)\n\n    loader = data.DataLoader(dataset, batch_size=1, shuffle=False)\n\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n    model.eval()\n\n    prediction_dict = {}\n\n    for image, row_id, site in progress_bar(loader):\n        site = site[0]\n        row_id = row_id[0]\n        if site in {\"site_1\", \"site_2\"}:\n            image = image.to(device)\n\n            with torch.no_grad():\n                prediction = model(image)\n                proba = prediction[\"multilabel_proba\"].detach().cpu().numpy().reshape(-1)\n                \n            events = proba >= threshold\n            labels = np.argwhere(events).reshape(-1).tolist()\n            \n        else:\n    # to avoid prediction on large batch\n            image = image.squeeze(0)\n            batch_size = 16\n            whole_size = image.size(0)\n\n            if whole_size % batch_size == 0:\n                n_iter = whole_size // batch_size\n            else:\n                n_iter = whole_size // batch_size + 1\n\n            all_events = set()\n\n            for batch_i in range(n_iter):\n                batch = image[batch_i * batch_size: (batch_i + 1) * batch_size]\n\n                if batch.ndim == 3:\n                    batch = batch.unsqueeze(0)\n                    \n                batch = batch.to(device)\n                with torch.no_grad():\n                    prediction = model(batch)\n\n                    proba = prediction[\"multilabel_proba\"].detach().cpu().numpy()\n                events = proba >= threshold\n\n                for i in range(len(events)):\n                    event = events[i, :]\n                    labels = np.argwhere(event).reshape(-1).tolist()\n\n                    for label in labels:\n                        all_events.add(label)\n\n            labels=list(all_events)\n            \n        if len(labels)==0:\n            prediction_dict[row_id]=\"nocall\"\n        else:\n            labels_str_list=list(map(lambda x: INV_BIRD_CODE[x], labels))\n            label_string=\" \".join(labels_str_list)\n            prediction_dict[row_id]= label_string\n            \n    return prediction_dict\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:24.121560Z","iopub.execute_input":"2024-01-11T15:02:24.122214Z","iopub.status.idle":"2024-01-11T15:02:24.139624Z","shell.execute_reply.started":"2024-01-11T15:02:24.122176Z","shell.execute_reply":"2024-01-11T15:02:24.138523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prediction(test_df: pd.DataFrame,\n              test_audio: Path,\n              model_config: dict,\n              mel_params: dict,\n              weights_path: str,\n              threshold=0.5):\n    \n    model = get_model(model_config, weights_path)\n    unique_audio_id = test_df.audio_id.unique()\n\n    warnings.filterwarnings(\"ignore\")\n\n    prediction_dfs = []\n\n    for audio_id in unique_audio_id:\n        with timer(f\"Loading {audio_id}\", logger):\n            clip, _ = librosa.load(test_audio + \"/\" + (audio_id + \".mp3\"),\n                                   sr=TARGET_SR,\n                                   mono=True,\n                                   res_type=\"scipy\")\n\n        test_df_for_audio_id = test_df.query(\n            f\"audio_id == '{audio_id}'\").reset_index(drop=True)\n        with timer(f\"Prediction on {audio_id}\", logger):\n            prediction_dict = prediction_for_clip(test_df_for_audio_id,\n                                                  clip=clip,\n                                                  model=model,\n                                                  mel_params=mel_params,\n                                                  threshold=threshold)\n        row_id = list(prediction_dict.keys())\n        birds = list(prediction_dict.values())\n\n        prediction_df = pd.DataFrame({\n           \"row_id\": row_id,\n           \"birds\": birds\n        })\n\n        prediction_dfs.append(prediction_df)\n\n    prediction_df = pd.concat(prediction_dfs, axis=0, sort=False).reset_index(drop=True)\n\n    return prediction_df\n\n    \n    \n            ","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:02:24.436026Z","iopub.execute_input":"2024-01-11T15:02:24.436662Z","iopub.status.idle":"2024-01-11T15:02:24.448164Z","shell.execute_reply.started":"2024-01-11T15:02:24.436628Z","shell.execute_reply":"2024-01-11T15:02:24.446565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = prediction(test_df=test,\n                        test_audio=test_audio,\n                        model_config=model_config,\n                        mel_params=melspectrogram_parameters,\n                        weights_path=weights_path,\n                        threshold=0.8)\n\nsubmission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T15:03:23.267485Z","iopub.execute_input":"2024-01-11T15:03:23.267982Z","iopub.status.idle":"2024-01-11T15:04:19.827684Z","shell.execute_reply.started":"2024-01-11T15:03:23.267944Z","shell.execute_reply":"2024-01-11T15:04:19.826835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}