{"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"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn import metrics\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split\n\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Activation\nfrom keras.optimizers import Adam\nfrom keras.utils import to_categorical\n\nimport librosa # for audio analysis\nimport librosa.display\nimport soundfile as sf # for reading and writing sound files\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd # to display interactive rich media like audios\nimport numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:35.218003Z","iopub.execute_input":"2024-01-11T19:02:35.218429Z","iopub.status.idle":"2024-01-11T19:02:35.226612Z","shell.execute_reply.started":"2024-01-11T19:02:35.218398Z","shell.execute_reply":"2024-01-11T19:02:35.225101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/birdsong-recognition/train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:35.830449Z","iopub.execute_input":"2024-01-11T19:02:35.831090Z","iopub.status.idle":"2024-01-11T19:02:36.297341Z","shell.execute_reply.started":"2024-01-11T19:02:35.831055Z","shell.execute_reply":"2024-01-11T19:02:36.296007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:36.431760Z","iopub.execute_input":"2024-01-11T19:02:36.432176Z","iopub.status.idle":"2024-01-11T19:02:36.519850Z","shell.execute_reply.started":"2024-01-11T19:02:36.432145Z","shell.execute_reply":"2024-01-11T19:02:36.518646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:36.893284Z","iopub.execute_input":"2024-01-11T19:02:36.894424Z","iopub.status.idle":"2024-01-11T19:02:36.903085Z","shell.execute_reply.started":"2024-01-11T19:02:36.894384Z","shell.execute_reply":"2024-01-11T19:02:36.901778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:37.347767Z","iopub.execute_input":"2024-01-11T19:02:37.348236Z","iopub.status.idle":"2024-01-11T19:02:37.356585Z","shell.execute_reply.started":"2024-01-11T19:02:37.348200Z","shell.execute_reply":"2024-01-11T19:02:37.355479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nulls = df.columns[df.isnull().any()]\nprint(nulls)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:37.703311Z","iopub.execute_input":"2024-01-11T19:02:37.703702Z","iopub.status.idle":"2024-01-11T19:02:37.781016Z","shell.execute_reply.started":"2024-01-11T19:02:37.703670Z","shell.execute_reply":"2024-01-11T19:02:37.779679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:38.022592Z","iopub.execute_input":"2024-01-11T19:02:38.023414Z","iopub.status.idle":"2024-01-11T19:02:38.044556Z","shell.execute_reply.started":"2024-01-11T19:02:38.023359Z","shell.execute_reply":"2024-01-11T19:02:38.042426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['playback_used'].fillna('no',inplace=True)\nle=LabelEncoder()\ndf['playback_used_encoded']=le.fit_transform(df['playback_used'])\nprint(df['playback_used'],df['playback_used_encoded'])","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:38.334767Z","iopub.execute_input":"2024-01-11T19:02:38.335242Z","iopub.status.idle":"2024-01-11T19:02:38.355741Z","shell.execute_reply.started":"2024-01-11T19:02:38.335206Z","shell.execute_reply":"2024-01-11T19:02:38.354446Z"},"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-11T19:02:38.631328Z","iopub.execute_input":"2024-01-11T19:02:38.632140Z","iopub.status.idle":"2024-01-11T19:02:38.648740Z","shell.execute_reply.started":"2024-01-11T19:02:38.632081Z","shell.execute_reply":"2024-01-11T19:02:38.647076Z"},"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-11T19:02:38.956879Z","iopub.execute_input":"2024-01-11T19:02:38.957281Z","iopub.status.idle":"2024-01-11T19:02:38.989136Z","shell.execute_reply.started":"2024-01-11T19:02:38.957248Z","shell.execute_reply":"2024-01-11T19:02:38.987967Z"},"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-11T19:02:39.187043Z","iopub.execute_input":"2024-01-11T19:02:39.187436Z","iopub.status.idle":"2024-01-11T19:02:39.248960Z","shell.execute_reply.started":"2024-01-11T19:02:39.187404Z","shell.execute_reply":"2024-01-11T19:02:39.247797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('date',axis=1,inplace=True)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:39.361632Z","iopub.execute_input":"2024-01-11T19:02:39.362315Z","iopub.status.idle":"2024-01-11T19:02:39.407239Z","shell.execute_reply.started":"2024-01-11T19:02:39.362268Z","shell.execute_reply":"2024-01-11T19:02:39.406308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"latitude\"].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:39.527467Z","iopub.execute_input":"2024-01-11T19:02:39.528214Z","iopub.status.idle":"2024-01-11T19:02:39.539148Z","shell.execute_reply.started":"2024-01-11T19:02:39.528164Z","shell.execute_reply":"2024-01-11T19:02:39.537906Z"},"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-11T19:02:39.696703Z","iopub.execute_input":"2024-01-11T19:02:39.697222Z","iopub.status.idle":"2024-01-11T19:02:39.760725Z","shell.execute_reply.started":"2024-01-11T19:02:39.697109Z","shell.execute_reply":"2024-01-11T19:02:39.759631Z"},"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-11T19:02:39.870928Z","iopub.execute_input":"2024-01-11T19:02:39.871388Z","iopub.status.idle":"2024-01-11T19:02:39.888404Z","shell.execute_reply.started":"2024-01-11T19:02:39.871345Z","shell.execute_reply":"2024-01-11T19:02:39.887151Z"},"trusted":true},"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.status.busy":"2024-01-11T19:02:40.056739Z","iopub.execute_input":"2024-01-11T19:02:40.057157Z","iopub.status.idle":"2024-01-11T19:02:40.080102Z","shell.execute_reply.started":"2024-01-11T19:02:40.057128Z","shell.execute_reply":"2024-01-11T19:02:40.078682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', 40)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:40.239305Z","iopub.execute_input":"2024-01-11T19:02:40.239711Z","iopub.status.idle":"2024-01-11T19:02:40.278207Z","shell.execute_reply.started":"2024-01-11T19:02:40.239668Z","shell.execute_reply":"2024-01-11T19:02:40.277223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['title','species','title','secondary_labels','description','license','recordist','primary_label','url','location'],axis=1,inplace=True)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:40.422379Z","iopub.execute_input":"2024-01-11T19:02:40.422771Z","iopub.status.idle":"2024-01-11T19:02:40.460632Z","shell.execute_reply.started":"2024-01-11T19:02:40.422729Z","shell.execute_reply":"2024-01-11T19:02:40.459007Z"},"trusted":true},"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":{"scrolled":true,"execution":{"iopub.status.busy":"2024-01-11T19:02:40.599504Z","iopub.execute_input":"2024-01-11T19:02:40.599935Z","iopub.status.idle":"2024-01-11T19:02:40.670975Z","shell.execute_reply.started":"2024-01-11T19:02:40.599902Z","shell.execute_reply":"2024-01-11T19:02:40.669844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:40.778683Z","iopub.execute_input":"2024-01-11T19:02:40.779117Z","iopub.status.idle":"2024-01-11T19:02:40.788959Z","shell.execute_reply.started":"2024-01-11T19:02:40.779085Z","shell.execute_reply":"2024-01-11T19:02:40.787601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] =df['elevation'].replace(['? m','-m' ,'Unknown m','m',''], '99999')\n","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:40.942035Z","iopub.execute_input":"2024-01-11T19:02:40.942474Z","iopub.status.idle":"2024-01-11T19:02:40.961488Z","shell.execute_reply.started":"2024-01-11T19:02:40.942439Z","shell.execute_reply":"2024-01-11T19:02:40.960141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].apply(lambda x: x.split('.')[0])","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:41.124845Z","iopub.execute_input":"2024-01-11T19:02:41.125284Z","iopub.status.idle":"2024-01-11T19:02:41.142952Z","shell.execute_reply.started":"2024-01-11T19:02:41.125251Z","shell.execute_reply":"2024-01-11T19:02:41.141465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = df['elevation'].apply(lambda x: x.split(' ')[0])","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:41.297984Z","iopub.execute_input":"2024-01-11T19:02:41.299068Z","iopub.status.idle":"2024-01-11T19:02:41.317880Z","shell.execute_reply.started":"2024-01-11T19:02:41.299027Z","shell.execute_reply":"2024-01-11T19:02:41.316568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'] = pd.to_numeric(df['elevation'], errors = 'coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:41.470015Z","iopub.execute_input":"2024-01-11T19:02:41.470405Z","iopub.status.idle":"2024-01-11T19:02:41.501073Z","shell.execute_reply.started":"2024-01-11T19:02:41.470376Z","shell.execute_reply":"2024-01-11T19:02:41.499618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dropna(inplace=True,axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:41.648375Z","iopub.execute_input":"2024-01-11T19:02:41.648800Z","iopub.status.idle":"2024-01-11T19:02:41.695444Z","shell.execute_reply.started":"2024-01-11T19:02:41.648767Z","shell.execute_reply":"2024-01-11T19:02:41.694154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['elevation'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:02:41.841075Z","iopub.execute_input":"2024-01-11T19:02:41.841448Z","iopub.status.idle":"2024-01-11T19:02:41.850494Z","shell.execute_reply.started":"2024-01-11T19:02:41.841420Z","shell.execute_reply":"2024-01-11T19:02:41.849311Z"},"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\n    mean_elevation = sum_elevation / count_valid_values\nmean_elevation","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:03:06.012872Z","iopub.execute_input":"2024-01-11T19:03:06.013290Z","iopub.status.idle":"2024-01-11T19:03:06.617526Z","shell.execute_reply.started":"2024-01-11T19:03:06.013259Z","shell.execute_reply":"2024-01-11T19:03:06.616286Z"},"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-11T19:03:07.808927Z","iopub.execute_input":"2024-01-11T19:03:07.809371Z","iopub.status.idle":"2024-01-11T19:03:07.816059Z","shell.execute_reply.started":"2024-01-11T19:03:07.809339Z","shell.execute_reply":"2024-01-11T19:03:07.814624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:03:29.770555Z","iopub.execute_input":"2024-01-11T19:03:29.770970Z","iopub.status.idle":"2024-01-11T19:03:29.805062Z","shell.execute_reply.started":"2024-01-11T19:03:29.770938Z","shell.execute_reply":"2024-01-11T19:03:29.804190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bitrate_of_mp3'].unique()","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-01-11T19:03:16.763466Z","iopub.execute_input":"2024-01-11T19:03:16.764120Z","iopub.status.idle":"2024-01-11T19:03:16.774553Z","shell.execute_reply.started":"2024-01-11T19:03:16.764086Z","shell.execute_reply":"2024-01-11T19:03:16.773689Z"},"trusted":true},"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:04:19.586439Z","iopub.execute_input":"2024-01-11T19:04:19.586881Z","iopub.status.idle":"2024-01-11T19:04:19.616730Z","shell.execute_reply.started":"2024-01-11T19:04:19.586848Z","shell.execute_reply":"2024-01-11T19:04:19.615566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['background','author','xc_id','length'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:04:14.870317Z","iopub.execute_input":"2024-01-11T19:04:14.870726Z","iopub.status.idle":"2024-01-11T19:04:14.879347Z","shell.execute_reply.started":"2024-01-11T19:04:14.870695Z","shell.execute_reply":"2024-01-11T19:04:14.877764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:06:50.750180Z","iopub.execute_input":"2024-01-11T19:06:50.750621Z","iopub.status.idle":"2024-01-11T19:06:50.806873Z","shell.execute_reply.started":"2024-01-11T19:06:50.750588Z","shell.execute_reply":"2024-01-11T19:06:50.805744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:11:51.364874Z","iopub.execute_input":"2024-01-11T19:11:51.365953Z","iopub.status.idle":"2024-01-11T19:11:52.241977Z","shell.execute_reply.started":"2024-01-11T19:11:51.365899Z","shell.execute_reply":"2024-01-11T19:11:52.240805Z"},"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='viridis')\nplt.title('Distribution of Ratings')\nplt.xlabel('Rating')\n\nplt.ylabel('Count')\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:11:52.243647Z","iopub.execute_input":"2024-01-11T19:11:52.244089Z","iopub.status.idle":"2024-01-11T19:11:52.657670Z","shell.execute_reply.started":"2024-01-11T19:11:52.244058Z","shell.execute_reply":"2024-01-11T19:11:52.656550Z"},"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='viridis')\nplt.title('Distribution of Playback Used')\nplt.xlabel('Count')\nplt.ylabel('Playback Used')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-11T19:18:31.784472Z","iopub.execute_input":"2024-01-11T19:18:31.784927Z","iopub.status.idle":"2024-01-11T19:18:32.013368Z","shell.execute_reply.started":"2024-01-11T19:18:31.784895Z","shell.execute_reply":"2024-01-11T19:18:32.012255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}