{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport folium","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"df = pd.read_csv('../input/birdsong-recognition/train.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# First glance","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# country distribution\ndf.country.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.country.value_counts()[0:10].plot(kind='bar')\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# convert lat/lon to numeric/NaN\ndf.latitude = pd.to_numeric(df.latitude, errors='coerce')\ndf.longitude = pd.to_numeric(df.longitude, errors='coerce')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# first simple plot of locations\nsns.scatterplot(x='longitude', y='latitude', data=df)\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# eval frequencies\nbird_freq = df.ebird_code.value_counts()\nbird_freq","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# select first 10 categories and plot in color\ndf_select = df[df.ebird_code.isin(bird_freq[0:9+1].index)]\nsns.scatterplot(x='longitude', y='latitude', hue='ebird_code', data=df_select, palette='colorblind')\nplt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) # move legend out of the plot area\n\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# select next 10 categories and plot in color\ndf_select = df[df.ebird_code.isin(bird_freq[10:19+1].index)]\nsns.scatterplot(x='longitude', y='latitude', hue='ebird_code', data=df_select, palette='colorblind')\nplt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# select next 10 categories and plot in color\ndf_select = df[df.ebird_code.isin(bird_freq[20:29+1].index)]\nsns.scatterplot(x='longitude', y='latitude', hue='ebird_code', data=df_select, palette='colorblind')\nplt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# select next 10 categories and plot in color\ndf_select = df[df.ebird_code.isin(bird_freq[30:39+1].index)]\nsns.scatterplot(x='longitude', y='latitude', hue='ebird_code', data=df_select, palette='colorblind')\nplt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Look at only one bird category and provide interactive map","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"my_bird = 'houspa'\ndf_example = df[df.ebird_code.isin([my_bird])]\ndf_example.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# check for missing coordinates\ndf_example.latitude.isna().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# check for missing coordinates\ndf_example.longitude.isna().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# remove rows with missings\ndf_example = df_example.dropna(axis=0, subset=['latitude','longitude'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_example.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# interactive map\nzoom_factor = 2\nmy_map_1 = folium.Map(location=[0,0], zoom_start=zoom_factor)\n\nfor i in range(0,df_example.shape[0]):\n   folium.Circle(\n      location=[df_example.iloc[i]['latitude'], df_example.iloc[i]['longitude']],\n      radius=np.sqrt(df_example.iloc[i]['rating'])*25000,\n      color='blue',\n      popup='ID: ' + str(df_example.iloc[i]['xc_id']),\n      fill=True,\n      fill_color='blue',\n   ).add_to(my_map_1)\n\nmy_map_1 # display","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Show another one","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"my_bird = 'greegr'\ndf_example = df[df.ebird_code.isin([my_bird])]\ndf_example = df_example.dropna(axis=0, subset=['latitude','longitude'])\n\n# interactive map\nzoom_factor = 2\nmy_map_2 = folium.Map(location=[0,0], zoom_start=zoom_factor)\n\nfor i in range(0,df_example.shape[0]):\n   folium.Circle(\n      location=[df_example.iloc[i]['latitude'], df_example.iloc[i]['longitude']],\n      radius=np.sqrt(df_example.iloc[i]['rating'])*25000,\n      color='blue',\n      popup='ID: ' + str(df_example.iloc[i]['xc_id']),\n      fill=True,\n      fill_color='blue',\n   ).add_to(my_map_2)\n\nmy_map_2 # display","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}