{"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":"# EDA for BirdCLEF 2022","metadata":{}},{"cell_type":"markdown","source":"# Load Packages","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom termcolor import colored\nsns.set_style(\"darkgrid\")","metadata":{"execution":{"iopub.status.busy":"2022-03-08T14:42:33.337866Z","iopub.execute_input":"2022-03-08T14:42:33.338393Z","iopub.status.idle":"2022-03-08T14:42:34.847656Z","shell.execute_reply.started":"2022-03-08T14:42:33.338275Z","shell.execute_reply":"2022-03-08T14:42:34.845849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = '/kaggle/input/birdclef-2022'","metadata":{"execution":{"iopub.status.busy":"2022-03-08T14:42:34.849527Z","iopub.execute_input":"2022-03-08T14:42:34.849772Z","iopub.status.idle":"2022-03-08T14:42:34.857256Z","shell.execute_reply.started":"2022-03-08T14:42:34.849743Z","shell.execute_reply":"2022-03-08T14:42:34.855632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Basic Statistics","metadata":{}},{"cell_type":"code","source":"eBird_tax_df = pd.read_csv(os.path.join(DATA_DIR, 'eBird_Taxonomy_v2021.csv'))\neBird_tax_df.head()\nprint(colored('Check number of rows and columns', 'red'))\nprint('Number of rows = {}'.format(eBird_tax_df.shape[0]))\nprint('Number of columns = {}'.format(eBird_tax_df.shape[1]))\nprint('List of columns:', eBird_tax_df.columns.values)\n\nprint(colored('\\nCheck unique numbers of entities in each parameters', 'red'))\nprint('Number of TAXON_ORDER: {}'.format(len(eBird_tax_df.TAXON_ORDER.unique())))\nprint('Number of CATEGORY = {}'.format(len(eBird_tax_df.CATEGORY.unique())))\nprint('Number of SPECIES_CODE = {}'.format(len(eBird_tax_df.SPECIES_CODE.unique())))\nprint('Number of PRIMARY_COM_NAME = {}'.format(len(eBird_tax_df.PRIMARY_COM_NAME.unique())))\nprint('Number of SCI_NAME = {}'.format(len(eBird_tax_df.SCI_NAME.unique())))\nprint('Number of ORDER1 = {}'.format(len(eBird_tax_df.ORDER1.unique())))\nprint('Number of FAMILY = {}'.format(len(eBird_tax_df.FAMILY.unique())))\nprint('Number of REPORT_AS = {}'.format(len(eBird_tax_df.REPORT_AS.unique())))\nprint('Number of SPECIES_GROUP = {}'.format(len(eBird_tax_df.SPECIES_GROUP.unique())))","metadata":{"execution":{"iopub.status.busy":"2022-03-08T14:42:34.863172Z","iopub.execute_input":"2022-03-08T14:42:34.863935Z","iopub.status.idle":"2022-03-08T14:42:34.993008Z","shell.execute_reply.started":"2022-03-08T14:42:34.863899Z","shell.execute_reply":"2022-03-08T14:42:34.992243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-size:16px\">\n    From above stats, we can see that <em>TAXON_ORDER, SPECIES_CODE, PRIMARY_COM_NAME and SCI_NAME </em> are unique parameters. Rest <em>CATEGORY, ORDER1, FAMILY, 'REPORT_AS and SPECIES_GROUP</em> are in various categories. We will check these parameters one by one. Let's start from <em>Category</em>.\n</p>","metadata":{}},{"cell_type":"code","source":"print('Number of Categories = {}'.format(len(eBird_tax_df.CATEGORY.unique())))\npie_plot_data = eBird_tax_df.groupby('CATEGORY')['TAXON_ORDER'].count().sort_values()\nlabels = pie_plot_data.keys()\nexplode = [0.015]*len(labels)\npie, ax = plt.subplots(figsize = [10,6])\nplt.pie(pie_plot_data, autopct = \"%.1f%%\", labels = labels, explode = explode, pctdistance = 0.5)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-08T14:42:34.996614Z","iopub.execute_input":"2022-03-08T14:42:34.996852Z","iopub.status.idle":"2022-03-08T14:42:35.20795Z","shell.execute_reply.started":"2022-03-08T14:42:34.996825Z","shell.execute_reply":"2022-03-08T14:42:35.20724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-size:16px\">\n    The details of taxonomy categories are as follows:\n    <ul>\n        <li><b>Species:</b> e.g., Tundra Swan Cygnus columbianus </li>\n        <li><b>ISSF or Identifiable Sub-specific Group:</b> Identifiable subspecies or group of subspecies, e.g., Tundra Swan (Bewick’s) Cygnus columbianus bewickii or Tundra Swan (Whistling) Cygnus columbianus columbianus</li>\n        <li><b>Slash:</b> Identification to Species-pair, e.g., Tundra/Trumpeter Swan Cygnus columbianus/buccinator</li>\n        <li><b>Spuh:</b> Genus or identification at broad level, e.g., swan sp. Cygnus sp.</li>\n        <li><b>Hybrid:</b> Hybrid between two species, e.g., Tundra x Trumpeter Swan (hybrid)</li>\n        <li><b>Intergrade:</b> Hybrid between two ISSF (subspecies or subspecies groups), e.g., Tundra Swan (Whistling x Bewick’s) Cygnus columbianus columbianus x bewickii</li>\n        <li><b>Domestic:</b> Distinctly-plumaged domesticated varieties that may be free-flying (these do not count on personal lists) e.g., Mallard (Domestic type)</li>\n        <li><b>Form:</b> Miscellaneous other taxa, including recently-described species yet to be accepted or distinctive forms that are not universally accepted, e.g., Red-tailed Hawk (abieticola), Upland Goose (Bar-breasted)</li>\n    </ul> \n<a href=\"https://ebird.org/science/use-ebird-data/the-ebird-taxonomy\">source</a>\n</p>\n\n<p style=\"font-size:16px\">\n    <em>Species</em> is the most predominant category, followed by <em>ISSF</em>, <em>Slash</em>, <em>Spuh</em> etc. Now let's check <em>ORDER1</em> parameter.\n</p>","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize = (10,7), dpi = 120)\n# gs = gridspec.GridSpec(2,2)\ncolors = sns.color_palette()\n\n# ax0 = fig.add_subplot(gs[0:2,0])\norder_count = pd.DataFrame(eBird_tax_df.groupby('ORDER1').TAXON_ORDER.count())\nfifth_largest_value = order_count['TAXON_ORDER'].nlargest(5)[4]\ncolor_plt = [colors[0] if value < fifth_largest_value else colors[3] for value in order_count.TAXON_ORDER]\nbar = sns.barplot(data = order_count, y = order_count.index, x = 'TAXON_ORDER',  ax = ax, palette = color_plt)\nplt.xlabel('# of Order')\nplt.ylabel('')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-08T14:42:35.209079Z","iopub.execute_input":"2022-03-08T14:42:35.2101Z","iopub.status.idle":"2022-03-08T14:42:35.811887Z","shell.execute_reply.started":"2022-03-08T14:42:35.210061Z","shell.execute_reply":"2022-03-08T14:42:35.809375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see the top 5 Orders highlighted in red bars.","metadata":{}},{"cell_type":"code","source":"## WORK IN PROGRESS... STAY TUNED","metadata":{},"execution_count":null,"outputs":[]}]}