{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<h2 style='color:yellow'> About </h2>\n\n<p><i>As the “extinction capital of the world,” Hawai'i has lost 68% of its bird species, the consequences of which can harm entire food chains. Researchers use population monitoring to understand how native birds react to changes in the environment and conservation efforts. But many of the remaining birds across the islands are isolated in difficult-to-access, high-elevation habitats. With physical monitoring difficult, scientists have turned to sound recordings.Known as bioacoustic monitoring, this approach could provide a passive, low labor, and cost-effective strategy for studying endangered bird populations</i></p>\n\n<p><i>In this competition, you’ll use your machine learning skills to identify bird species by sound. Specifically, you'll develop a model that can process continuous audio data and then acoustically recognize the species.If successful, you'll help advance the science of bioacoustics and support ongoing research to protect endangered Hawaiian birds. </i></p>\n\n<a href = https://www.kaggle.com/c/birdclef-2022/overview>Source </a>","metadata":{}},{"cell_type":"markdown","source":"<h2 style='color:green'> Some Fantastic Notebooks and Resources </h2>\n\n\n* https://www.kaggle.com/c/birdclef-2022/discussion/307752\n* https://www.kaggle.com/amandanavine/hawaiian-bird-species\n* https://www.kaggle.com/c/birdclef-2022/discussion/311005\n* https://www.kaggle.com/c/birdclef-2022/discussion/307842\n* https://www.tensorflow.org/tutorials/audio/simple_audio\n* https://www.kaggle.com/shreyasajal/birdclef-librosa-audio-feature-extraction\n* https://www.kaggle.com/kaerunantoka/birdclef2022-create-image-data-from-audio-data\n* https://www.kaggle.com/code/virajkadam/birdclef-extracting-spectrograms\n* https://earthnworld.com/best-singing-birds-in-the-world/\n* http://ceur-ws.org/Vol-1866/paper_143.pdf","metadata":{}},{"cell_type":"markdown","source":"<h2 style='color:green'> Imports </h2>","metadata":{}},{"cell_type":"code","source":"#general\nimport pandas as pd \nimport numpy as np \nimport os \n\nimport geopandas as gpd\nfrom shapely import geometry\nimport geopy \n\n#plotting\nimport matplotlib.pyplot as plt \nimport seaborn as sns\n\n\n#deep learning \nimport tensorflow as tf \n\n#mapping\nimport folium\nfrom folium.plugins import HeatMap,MarkerCluster\n\n\n#audio data\nimport librosa\nimport librosa.display as ld\n\n\n#colored print \nfrom termcolor import colored\n    \n    \nfrom IPython.display import Audio\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:05:10.183241Z","iopub.execute_input":"2022-03-24T06:05:10.183889Z","iopub.status.idle":"2022-03-24T06:05:18.504621Z","shell.execute_reply.started":"2022-03-24T06:05:10.183757Z","shell.execute_reply":"2022-03-24T06:05:18.503795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Helper Functions**","metadata":{}},{"cell_type":"code","source":"def  color_print(print_str,\n                 print_color='green'):\n    \n    '''print in given  color (default green)'''\n    print(colored(print_str,print_color))\n\n    \n#helper to plot spectogram\ndef plot_spectrogram(path,birdname='',sr=None):\n    '''plot spectrogram from given path'''\n    \n    #loading audio\n    signal,sr=librosa.load(path,sr=sr)\n\n    fig,ax=plt.subplots(figsize=(16,6))\n    M = librosa.feature.melspectrogram(y=signal, sr=sr)\n    M_db = librosa.power_to_db(M, ref=np.max)\n    img = ld.specshow(M_db, y_axis='mel', x_axis='time', ax=ax)\n    plt.colorbar(img)\n    ax.set(title=f'Mel spectrogram for {birdname}')\n    plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:05:18.506643Z","iopub.execute_input":"2022-03-24T06:05:18.507221Z","iopub.status.idle":"2022-03-24T06:05:18.514071Z","shell.execute_reply.started":"2022-03-24T06:05:18.507180Z","shell.execute_reply":"2022-03-24T06:05:18.512768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Setting Random seed**","metadata":{}},{"cell_type":"code","source":"\n\nclass config:\n    def __init__(self,\n                 seed=7):\n        self.seed = seed\n    \n    def set_seed(self):\n        '''set seed for reproduciblity'''\n\n        tf.random.set_seed(self.seed)\n        os.environ['PYTHONHASHSEED'] = str(self.seed)\n        np.random.seed(self.seed)\n        color_print(print_str=f'Setting Random Seed  to {self.seed}',\n                    print_color='yellow')\n\n        \n        \ncfg = config(seed=7)\ncfg.set_seed()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:05:18.520272Z","iopub.execute_input":"2022-03-24T06:05:18.520729Z","iopub.status.idle":"2022-03-24T06:05:18.528341Z","shell.execute_reply.started":"2022-03-24T06:05:18.520698Z","shell.execute_reply":"2022-03-24T06:05:18.527518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading data","metadata":{}},{"cell_type":"code","source":"\ntrain_dir  =  '../input/birdclef-2022/train_audio/' # train audio\ntest_dir  =  '../input/birdclef-2022/test_soundscapes/'\n\n\n# csv files \ntest = pd.read_csv('../input/birdclef-2022/test.csv')\ntrain_meta = gpd.read_file('../input/birdclef-2022/train_metadata.csv')\ntrain_meta[['latitude','longitude','rating']]=train_meta[['latitude','longitude','rating']].astype(float)\n\nbird_taxanomy = pd.read_csv('../input/birdclef-2022/eBird_Taxonomy_v2021.csv') ","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:06:16.371726Z","iopub.execute_input":"2022-03-24T06:06:16.372337Z","iopub.status.idle":"2022-03-24T06:06:17.094920Z","shell.execute_reply.started":"2022-03-24T06:06:16.372289Z","shell.execute_reply":"2022-03-24T06:06:17.093946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#convert data frame into geo data frame\ntrain_meta.geometry = gpd.points_from_xy(x=train_meta['longitude'],\n                                         y = train_meta['latitude'])\n\n#set crs\n# train_meta=train_meta.set_crs('epsg:4326')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:06:17.099170Z","iopub.execute_input":"2022-03-24T06:06:17.099611Z","iopub.status.idle":"2022-03-24T06:06:17.108109Z","shell.execute_reply.started":"2022-03-24T06:06:17.099556Z","shell.execute_reply":"2022-03-24T06:06:17.107477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_meta.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:13:35.392170Z","iopub.execute_input":"2022-03-24T06:13:35.393077Z","iopub.status.idle":"2022-03-24T06:13:35.421131Z","shell.execute_reply.started":"2022-03-24T06:13:35.393009Z","shell.execute_reply":"2022-03-24T06:13:35.420042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#adding filepaths to individual files for easy access \n\ntrain_meta['filepath'] = train_dir + train_meta.filename","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:06:31.434333Z","iopub.execute_input":"2022-03-24T06:06:31.434643Z","iopub.status.idle":"2022-03-24T06:06:31.445564Z","shell.execute_reply.started":"2022-03-24T06:06:31.434613Z","shell.execute_reply":"2022-03-24T06:06:31.444784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style= 'color:green'>Audio Exploratory Data Analysis </h2>","metadata":{}},{"cell_type":"markdown","source":"<h3 style='color:green'> First lets take a look at some interesting/common bird calls  (click play to play the Audio)</h3>","metadata":{}},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Yellow-fronted Canary</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Yellow-fronted Canary'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:16.566102Z","iopub.execute_input":"2022-03-24T06:50:16.566439Z","iopub.status.idle":"2022-03-24T06:50:16.591543Z","shell.execute_reply.started":"2022-03-24T06:50:16.566402Z","shell.execute_reply":"2022-03-24T06:50:16.590072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Yellow-fronted Canary')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:17.074835Z","iopub.execute_input":"2022-03-24T06:50:17.075156Z","iopub.status.idle":"2022-03-24T06:50:17.622813Z","shell.execute_reply.started":"2022-03-24T06:50:17.075125Z","shell.execute_reply":"2022-03-24T06:50:17.622064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>House Sparrow</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='House Sparrow'].sort_values(by='rating',ascending=False).iloc[2]\nAudio(row['filepath'])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:30.133134Z","iopub.execute_input":"2022-03-24T06:50:30.133988Z","iopub.status.idle":"2022-03-24T06:50:30.164116Z","shell.execute_reply.started":"2022-03-24T06:50:30.133945Z","shell.execute_reply":"2022-03-24T06:50:30.162954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='House Sparrow')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:30.511356Z","iopub.execute_input":"2022-03-24T06:50:30.511950Z","iopub.status.idle":"2022-03-24T06:50:31.335160Z","shell.execute_reply.started":"2022-03-24T06:50:30.511910Z","shell.execute_reply":"2022-03-24T06:50:31.334206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Barn Owl</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Barn Owl'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:50.503142Z","iopub.execute_input":"2022-03-24T06:50:50.503434Z","iopub.status.idle":"2022-03-24T06:50:50.527918Z","shell.execute_reply.started":"2022-03-24T06:50:50.503396Z","shell.execute_reply":"2022-03-24T06:50:50.527120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Barn Owl')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:50:50.824508Z","iopub.execute_input":"2022-03-24T06:50:50.825664Z","iopub.status.idle":"2022-03-24T06:50:51.475197Z","shell.execute_reply.started":"2022-03-24T06:50:50.825603Z","shell.execute_reply":"2022-03-24T06:50:51.473866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Indian Peafowl (I hear these calls quite often)</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Indian Peafowl'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:02.239397Z","iopub.execute_input":"2022-03-24T06:51:02.240180Z","iopub.status.idle":"2022-03-24T06:51:02.298636Z","shell.execute_reply.started":"2022-03-24T06:51:02.240136Z","shell.execute_reply":"2022-03-24T06:51:02.296954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Indian Peafowl')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:02.695918Z","iopub.execute_input":"2022-03-24T06:51:02.696505Z","iopub.status.idle":"2022-03-24T06:51:04.928970Z","shell.execute_reply.started":"2022-03-24T06:51:02.696467Z","shell.execute_reply":"2022-03-24T06:51:04.927851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Laughing Gull</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Laughing Gull'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:12.442421Z","iopub.execute_input":"2022-03-24T06:51:12.442753Z","iopub.status.idle":"2022-03-24T06:51:12.464412Z","shell.execute_reply.started":"2022-03-24T06:51:12.442718Z","shell.execute_reply":"2022-03-24T06:51:12.462999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Laughing Gull')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:12.832925Z","iopub.execute_input":"2022-03-24T06:51:12.833952Z","iopub.status.idle":"2022-03-24T06:51:13.290628Z","shell.execute_reply.started":"2022-03-24T06:51:12.833895Z","shell.execute_reply":"2022-03-24T06:51:13.289900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Northern Cardinal</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Northern Cardinal'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:34.972641Z","iopub.execute_input":"2022-03-24T06:51:34.973096Z","iopub.status.idle":"2022-03-24T06:51:35.003698Z","shell.execute_reply.started":"2022-03-24T06:51:34.973055Z","shell.execute_reply":"2022-03-24T06:51:35.003061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Northern Cardinal')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:51:35.395123Z","iopub.execute_input":"2022-03-24T06:51:35.395600Z","iopub.status.idle":"2022-03-24T06:51:36.445579Z","shell.execute_reply.started":"2022-03-24T06:51:35.395568Z","shell.execute_reply":"2022-03-24T06:51:36.444640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style='color:yellow'>Red Junglefowl</h4>","metadata":{}},{"cell_type":"code","source":"row = train_meta[train_meta['common_name']=='Red Junglefowl'].sort_values(by='rating',ascending=False).iloc[0]\nAudio(row['filepath'])\n","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:48:13.487437Z","iopub.execute_input":"2022-03-24T06:48:13.487823Z","iopub.status.idle":"2022-03-24T06:48:13.524257Z","shell.execute_reply.started":"2022-03-24T06:48:13.487761Z","shell.execute_reply":"2022-03-24T06:48:13.523511Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(path=row['filepath'],birdname='Red Junglefowl')","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:48:48.755797Z","iopub.execute_input":"2022-03-24T06:48:48.756290Z","iopub.status.idle":"2022-03-24T06:48:49.492315Z","shell.execute_reply.started":"2022-03-24T06:48:48.756256Z","shell.execute_reply":"2022-03-24T06:48:49.490893Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style= 'color:green'>Exploratory Data Analysis </h2>","metadata":{}},{"cell_type":"markdown","source":"**A brief look at the Bird Taxanomy data**\n\n\n![](https://images.theconversation.com/files/176054/original/file-20170628-7313-1au5deb.jpg?ixlib=rb-1.1.0&q=45&auto=format&w=1000&fit=clip)","metadata":{}},{"cell_type":"code","source":"color_print(f'There are {bird_taxanomy.ORDER1.nunique()} unique orders in bird taxanomy data','yellow')\ncolor_print(f'There are {bird_taxanomy.FAMILY.nunique()} unique families in bird taxanomy data','yellow')\ncolor_print(f'There are {bird_taxanomy.SPECIES_CODE.nunique()} unique species in bird taxanomy data','yellow')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:12.611695Z","iopub.execute_input":"2022-03-24T06:53:12.612022Z","iopub.status.idle":"2022-03-24T06:53:12.628665Z","shell.execute_reply.started":"2022-03-24T06:53:12.611991Z","shell.execute_reply":"2022-03-24T06:53:12.627789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Training data**","metadata":{}},{"cell_type":"markdown","source":"<h3 style='color:green'> What is the count of ratings of recording quality  ?</h3>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(20,10))\nplt.yticks(fontsize=16)\nsns.countplot(y=\"rating\",\n              data=train_meta,\n              palette=\"RdYlGn\",\n              linewidth=3)\nplt.title(\"Count of Ratings\",font=\"Serif\", size=15,color='g')\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:13.289215Z","iopub.execute_input":"2022-03-24T06:53:13.290239Z","iopub.status.idle":"2022-03-24T06:53:13.572124Z","shell.execute_reply.started":"2022-03-24T06:53:13.290204Z","shell.execute_reply":"2022-03-24T06:53:13.571469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"color_print(f'There are {train_meta.scientific_name.nunique()} unique species in train data','yellow')\ncolor_print(f'There are {train_meta.shape[0]} recordings in train data','yellow')\nprint('-'*50 + '.'*30 + '-'*50)\ncolor_print(f'There are {train_meta[train_meta.rating >= 3.5].scientific_name.nunique()} unique species in train data with recording quality rating > 3.5','yellow')\ncolor_print(f'There are {train_meta[train_meta.rating >= 3.5].shape[0]} recordings in train data with recording quality rating > 3.5','yellow')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:13.573674Z","iopub.execute_input":"2022-03-24T06:53:13.574885Z","iopub.status.idle":"2022-03-24T06:53:13.618188Z","shell.execute_reply.started":"2022-03-24T06:53:13.574828Z","shell.execute_reply":"2022-03-24T06:53:13.617031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# taking recordings with rating >3.5 \ntrain_2 = train_meta.query('rating>=3.5')\ntrain_2.shape","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:13.814024Z","iopub.execute_input":"2022-03-24T06:53:13.814331Z","iopub.status.idle":"2022-03-24T06:53:13.834860Z","shell.execute_reply.started":"2022-03-24T06:53:13.814298Z","shell.execute_reply":"2022-03-24T06:53:13.833887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Among the selected recordings, what are the most common type of calls  ?</h3>","metadata":{}},{"cell_type":"code","source":"fig=plt.figure(figsize=(20,10))\nplt.yticks(fontsize=12)\ncall_types=pd.Series(train_2['type'].apply(lambda x: ','.join(eval(x)))).value_counts().sort_values(ascending=False)[:20]\n\ncall_types.plot.barh(title = 'top types of call',color=(0,0.5,0.2,0.7),width = 0.75)\nplt.title(\"top types of calls\",font=\"Serif\", size=20)\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:14.441397Z","iopub.execute_input":"2022-03-24T06:53:14.441867Z","iopub.status.idle":"2022-03-24T06:53:14.887825Z","shell.execute_reply.started":"2022-03-24T06:53:14.441820Z","shell.execute_reply":"2022-03-24T06:53:14.887186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Among the selected recordings, which are the most recorded birds ?</h3>","metadata":{}},{"cell_type":"code","source":"fig=plt.figure(figsize=(20,10))\nplt.yticks(fontsize=16)\ntop_birds=train_2['common_name'].value_counts().sort_values(ascending=False)[:20]\nplt.title(\"Birds with most number of recordings\",font=\"Serif\", size=20)\n\ntop_birds.plot.barh(color= 'y',width = 0.75,alpha=0.75)\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:14.889519Z","iopub.execute_input":"2022-03-24T06:53:14.889959Z","iopub.status.idle":"2022-03-24T06:53:15.201862Z","shell.execute_reply.started":"2022-03-24T06:53:14.889913Z","shell.execute_reply":"2022-03-24T06:53:15.201177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Among the selected recordings, which are the least recorded birds ?</h3>","metadata":{}},{"cell_type":"code","source":"fig=plt.figure(figsize=(20,10))\nplt.yticks(fontsize=16)\n\nrare_birds=train_2['common_name'].value_counts().sort_values(ascending=True)[:20]\n\nrare_birds.sort_values(ascending=False).plot.barh(title = 'Birds with least number of recordings',color= (0.6,0.3,0.3,0.75),width = 0.75)\nplt.title(\"Birds with least number of recordings\",font=\"Serif\", size=20)\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:21.151530Z","iopub.execute_input":"2022-03-24T06:53:21.152029Z","iopub.status.idle":"2022-03-24T06:53:21.481504Z","shell.execute_reply.started":"2022-03-24T06:53:21.151992Z","shell.execute_reply":"2022-03-24T06:53:21.480576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Who are the most common contributors ?</h3>","metadata":{}},{"cell_type":"code","source":"fig=plt.figure(figsize=(20,10))\nplt.yticks(fontsize=16)\ntop_aut=train_2['author'].value_counts().sort_values(ascending=False)[:20]\ntop_aut.plot.barh(color= (0.0,0.7,0.5,0.75),width = 0.75)\nplt.title(\"Most Common Contributors\",color='k', size=20)\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:21.681132Z","iopub.execute_input":"2022-03-24T06:53:21.681572Z","iopub.status.idle":"2022-03-24T06:53:22.023977Z","shell.execute_reply.started":"2022-03-24T06:53:21.681518Z","shell.execute_reply":"2022-03-24T06:53:22.023000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Where are the birds audio recorded at ?</h3>","metadata":{}},{"cell_type":"code","source":"m1 = folium.Map(location=(train_meta.latitude.mean(),train_meta.longitude.mean()),zoom_start = 4, min_zoom=3,max_zoom=7)\nh_map = HeatMap(data=train_meta[['latitude','longitude']],\n                radius=4,\n                blur=2).add_to(m1)\n\nm1","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T06:53:22.431666Z","iopub.execute_input":"2022-03-24T06:53:22.432125Z","iopub.status.idle":"2022-03-24T06:53:22.726103Z","shell.execute_reply.started":"2022-03-24T06:53:22.432092Z","shell.execute_reply":"2022-03-24T06:53:22.724881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> What are the birds found in hawai'i ?</h3>","metadata":{}},{"cell_type":"code","source":"lat,lon  = 19.741755, -155.844437\n\n\n#take a buffer region around defined location\nhawaii_location = geometry.Point([lon,lat]).buffer(3)\n\nhawaii_birds = train_meta[train_meta.geometry.intersects(hawaii_location)]\n\ncolor_print(f'There are {hawaii_birds.size} birds recordings from Hawaii and surrounding region.','yellow')\ncolor_print(f'There are {hawaii_birds.common_name.nunique()} unique birds from Hawaii and surrounding region.','yellow')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T07:26:43.068475Z","iopub.execute_input":"2022-03-24T07:26:43.068842Z","iopub.status.idle":"2022-03-24T07:26:43.093432Z","shell.execute_reply.started":"2022-03-24T07:26:43.068805Z","shell.execute_reply":"2022-03-24T07:26:43.092514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> Lets see a map of recordings in hawaii. Hover over the dots to see the common name of the birds</h3>","metadata":{}},{"cell_type":"code","source":"#map\nm2 = folium.Map(location=(lat,lon),zoom_start = 7, min_zoom=6,max_zoom=14)\n\nhawaii_birds.explore(m=m2,tiles= 'OpenStreetMap',tooltip='common_name')\n\nm2","metadata":{"execution":{"iopub.status.busy":"2022-03-24T07:26:45.359854Z","iopub.execute_input":"2022-03-24T07:26:45.360150Z","iopub.status.idle":"2022-03-24T07:26:45.535845Z","shell.execute_reply.started":"2022-03-24T07:26:45.360121Z","shell.execute_reply":"2022-03-24T07:26:45.535221Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style='color:green'> What is the distribution of birds found in Hawai'i ?</h3>","metadata":{}},{"cell_type":"code","source":"fig=plt.figure(figsize=(20,10))\nplt.yticks(fontsize=16)\nhawaii_birds.common_name.value_counts().plot.barh(color= (0.0,0.7,0.5,0.75),width = 0.75)\nplt.title(\"Birds recorded in Hawai'i\",color='k', size=20)\nplt.yticks(size=10)\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-24T07:26:46.497455Z","iopub.execute_input":"2022-03-24T07:26:46.497990Z","iopub.status.idle":"2022-03-24T07:26:47.125280Z","shell.execute_reply.started":"2022-03-24T07:26:46.497956Z","shell.execute_reply":"2022-03-24T07:26:47.124681Z"},"trusted":true},"execution_count":null,"outputs":[]}]}