{"cells":[{"metadata":{},"cell_type":"markdown","source":"# EDA of Cornell Birdcall Identification Competition Data","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"#### Importing Python Libraries","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import librosa\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport librosa.display\nimport plotly.express as px\nimport IPython.display as ipd\n\nimport matplotlib.pyplot as plt\n%matplotlib inline\nfrom matplotlib.offsetbox import AnnotationBbox\nfrom mpl_toolkits.basemap import Basemap","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/birdsong-recognition/train.csv')\ntest = pd.read_csv('/kaggle/input/birdsong-recognition/test.csv')\naudio_metadata = pd.read_csv('/kaggle/input/birdsong-recognition/example_test_audio_metadata.csv')\naudio_summary = pd.read_csv('/kaggle/input/birdsong-recognition/example_test_audio_summary.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's dive deep into training dataset and extract some data patterns that might help us to understand data from various view points.\nBasic structure of trainging dataset is as followed.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"There are total 21375 samples present in dataset with 35 different features. Let's take a look at these 35 different features.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head().T","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"It is clear that this dataset has recordings for 264 different bird species, and total 949 recordist has contributed with their recordings.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train['ebird_code'].nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['recordist'].nunique()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's deep dive into data and check locations and time period when souds were recorded. ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train['country'].nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"longitude = train[train[\"longitude\"] != 'Not specified']['longitude'].apply(lambda x: float(x)).tolist()\nlatitude = train[train[\"latitude\"] != 'Not specified']['latitude'].apply(lambda x: float(x)).tolist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(1, figsize=(16,6))\nworld_map = Basemap(projection='merc', llcrnrlat=-60, urcrnrlat=65, llcrnrlon=-180,\n                    urcrnrlon=180, lat_ts=0, resolution='c')\nworld_map.fillcontinents(color='#191919',lake_color='#000000')\nworld_map.drawmapboundary(fill_color='#000000')\nworld_map.drawcountries(linewidth=0.1, color=\"w\")\nmxy = world_map(longitude, latitude)\nworld_map.scatter(mxy[0], mxy[1], s=3, c=\"#1292db\", lw=0, alpha=1, zorder=5)\nplt.title(\"Recording Locations\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Most of the recordings are from the region of North America and Europe. Let's count number of recordings per country.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"country = train[\"country\"].value_counts()\ncountry = country[:35,]\nplt.figure(figsize=(20, 6))\nax = sns.barplot(country.index, country.values, palette=\"hls\")\nplt.title(\"Country and Number of Audio File Recorded\", fontsize=16)\nplt.xticks(rotation=90, fontsize=13)\nplt.yticks(fontsize=13)\nplt.ylabel(\"Number of Audio Files\", fontsize=14)\nplt.xlabel(\"\");\nfor p in ax.patches:\n    height = p.get_height()\n    y=p.get_bbox().get_points()[1,1]\n    ax.text(p.get_x()+p.get_width()/2., height + 350, int(y), ha=\"center\", rotation=90)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(16, 6))\nax = sns.countplot(train['date'].apply(lambda x: x.split('-')[0]), palette=\"hls\")\nplt.title(\"Year of Recording\", fontsize=16)\nplt.xticks(rotation=90, fontsize=13)\nplt.ylabel(\"Number of Recording\", fontsize=14)\nplt.xlabel(\"Years\", fontsize=14)\nfor p in ax.patches:\n    height = p.get_height()\n    y=p.get_bbox().get_points()[1,1]\n    ax.text(p.get_x()+p.get_width()/2., height + 50, int(y), ha=\"center\", rotation=90)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Following types of recordings are present in trainign dataset.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train[\"file_type\"].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sound = train['type'].apply(lambda x: x.split(',')).reset_index().explode(\"type\")\nsound = sound['type'].apply(lambda x: x.strip().lower()).reset_index()\nsound['type'] = sound['type'].replace('calls', 'call')\nsound = sound['type'].value_counts()[:10,]\nplt.figure(figsize=(16, 6))\nax = sns.barplot(sound.index, sound.values, palette=\"hls\")\nplt.title(\"Types of Sounds\", fontsize=16)\nplt.xticks(rotation=90, fontsize=13)\nplt.yticks(fontsize=13)\nplt.xlabel(\"\");\nfor p in ax.patches:\n    height = p.get_height()\n    y=p.get_bbox().get_points()[1,1]\n    ax.text(p.get_x()+p.get_width()/2., height + 350, int(y), ha=\"center\", rotation=90)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's see how many times bird was seen while recording sound.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"data = train['bird_seen'].value_counts()\nplt.figure(figsize=(16, 6))\nax = sns.barplot(data.index, data.values, palette=\"hls\")\nplt.title(\"Song was heard, but was Bird Seen?\", fontsize=16)\nplt.ylabel(\"Frequency\", fontsize=14)\nplt.yticks(fontsize=13)\nplt.xticks(rotation=45, fontsize=13)\nplt.xlabel(\"\");\nfor p in ax.patches:\n    height = p.get_height()\n    y=p.get_bbox().get_points()[1,1]\n    ax.text(p.get_x()+p.get_width()/2., height/2, int(y), ha=\"center\", rotation=90)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}