{"cells":[{"metadata":{},"cell_type":"markdown","source":"##  Import Packages","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#Import Packages\n\nimport numpy as np\nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\nimport scipy.stats as stats\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nfrom IPython.core.interactiveshell import InteractiveShell\nInteractiveShell.ast_node_interactivity='all'\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Explore the files in train_audio directory","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"In this section, we are doing sneak peek into different files present in train_audio directory.  \n\nFor that first import the file into pandas dataframe.\n\nThen apply following commands on dataframe.\n\nhead() - list top few rows.\n\ninfo() - tells about different columns, their types and whether they have null or non null values.\n\nshape - number of rows and columns.\n\nvalue_counts() - find values taken by a column.\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"###  1. sample_submission.csv ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# sample_submission data\n\nsub_df = pd.read_csv('../input/birdsong-recognition/sample_submission.csv')\nsub_df.head()\nsub_df.info()\nsub_df.shape\nsub_birds_counts = sub_df['birds'].value_counts()\nsub_birds_counts","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 2. example_test_audio_summary.csv","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# example_test_audio_summary data\n\naudio_sum_df = pd.read_csv('../input/birdsong-recognition/example_test_audio_summary.csv')\naudio_sum_df.head(3)\n\naudio_sum_df.info()\naudio_sum_df.shape\naudio_sum_birds_counts = audio_sum_df['birds'].value_counts()\naudio_sum_birds_counts","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 3. example_test_audio_metadata.csv","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# Draws pie-chart from pandas Series\ndef draw_pie_chart(count_series, title, hole=0):\n    labels = count_series.index\n    sizes = count_series.values\n\n    trace = go.Pie(labels=labels, values=sizes, hole=hole)\n\n    layout = go.Layout(\n        title=dict(\n            text=title,\n            y=0.9,\n            x=0.5,\n            xanchor= 'center',\n            yanchor= 'top'\n        ),\n        \n        font=dict(\n            family=\"Arial\",\n            size=14,\n            color=\"#7f7f7f\"\n        ),\n    )\n\n    data = [trace]\n\n    fig = go.Figure(data=data, layout=layout)\n\n    fig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# example_test_audio_metadata data\n\naudio_meta_df = pd.read_csv('../input/birdsong-recognition/example_test_audio_metadata.csv')\naudio_meta_df.head(3)\n\naudio_meta_df.info()\naudio_meta_df.shape\naudio_meta_birds_counts = audio_meta_df['ebird_code'].value_counts()\naudio_meta_birds_counts\ndraw_pie_chart(audio_meta_birds_counts,'ebird_code',hole=.5)\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"audio_meta_device_counts = audio_meta_df['device'].value_counts()\naudio_meta_device_counts\ndraw_pie_chart(audio_meta_device_counts,'device',hole=.5)\n\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"audio_meta_source_counts = audio_meta_df['source'].value_counts()\naudio_meta_source_counts\ndraw_pie_chart(audio_meta_source_counts,'source',hole=.5)\n\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"audio_meta_vox_type_counts = audio_meta_df['vox_type'].value_counts()\naudio_meta_vox_type_counts\ndraw_pie_chart(audio_meta_vox_type_counts,'vox_type',hole=.5)\n\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"audio_meta_channel_counts = audio_meta_df['channel'].value_counts()\naudio_meta_channel_counts\ndraw_pie_chart(audio_meta_channel_counts,'channel',hole=.5)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 4. test.csv","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# test data\n\ntest_df = pd.read_csv('../input/birdsong-recognition/test.csv')\ntest_df.head(3)\n\ntest_df.info()\ntest_df.shape\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 5. train.csv","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# training data\n\ntrain_df = pd.read_csv('../input/birdsong-recognition/train.csv')\ntrain_df.head(3)\ntrain_df.info()\ntrain_df.shape\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Training Data Description\n#### Types of Columns\n\n\n1 Non Numeric - Categorical - Object type - There are 32 columns of this type\n\n2 Numerical columns - There are 3 columns of numeric types\n\n2.1 int64 - whole numbers - duration, xc_id\n\n2.2 float64 - decimal numbers - rating","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"### Numerical data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#Summarize data\ntrain_df.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Plot a histogram of that column\n# hist() function from Matplotlib\nrating = train_df['rating']\nplt.hist(rating, color='blue', align='left',edgecolor=\"black\")\nplt.title('rating') \nplt.ylabel('Frequency')\nplt.xlabel('rating')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Plot a histogram of that column\n# hist() function from Matplotlib\nrating = train_df['duration']\nplt.hist(rating, color='orange', align='left',edgecolor=\"black\")\nplt.title('duration') \nplt.ylabel('Frequency')\nplt.xlabel('duration')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Categorical data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"cat_train_df = train_df.select_dtypes(include='object')\ncat_train_df.head()\ncat_train_df.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def display_columns_uniqvals(df):\n    for i, col in enumerate(df.columns.tolist()):\n        if i % 5 == 0:\n            print (\"-------------------------------------------\")\n        print('\\n ({} {}) \\n Missing: {}     Uniq_val_sz: {}     \\n Uniq_vals: {}\\n\\n'.format(i,col, df[col].isnull().sum(), df[col].unique().size, df[col].unique()))\n    print('\\n')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"display_columns_uniqvals(cat_train_df)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Single Variable analysis","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"Let us understand each column one by one and group similar columns\nLet peek into data to understand each column and various values it can take.\n\nLets start with Categorical variables.\n\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"1. playback_used - \nIt contains data of string type. \nIt has 3 kinds of values no, nan, yes. \nI am curious to know how many and of which type.\n","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# Choosing ggplot style\nplt.style.use('ggplot')\n\n# Get the figure and the axes (or subplots)\nfig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(15, 4))\n\n# value_counts\nplayback_used_counts = train_df['playback_used'].value_counts().sort_index()\n\n# Prepare data for ax0  \nprint(playback_used_counts)\nprint()\nx = playback_used_counts.index.values\nheight = playback_used_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax0.bar(x, height, width=0.5, align='center')\nax0.set(title = 'playback_used_counts ', xlabel='playback_used' , ylabel = 'Frequency')\nax0.set_xticks([0, 1])\n\n\n\n# Prepare data for ax1  \n# value_counts\npitch_counts = train_df['pitch'].value_counts().sort_index()\nprint(pitch_counts)\n\nprint()\nx = pitch_counts.index.values\nheight = pitch_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax1.bar(x, height, width=0.5, align='center')\nax1.set(title = 'pitch Counts', xlabel='pitch' , ylabel = 'Frequency')\n\n\n\n# Prepare data for ax2  \n\n# Prepare data for ax1  \n# value_counts\nchannel_counts = train_df['channels'].value_counts().sort_index()\nprint(channel_counts)\n\nprint()\nx = channel_counts.index.values\nheight = channel_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax2.bar(x, height, width=0.5, align='center')\nax2.set(title = 'channel Counts', xlabel='channel' , ylabel = 'Frequency')\nax2.set_xticks([0, 1])\n\n# Title the figure\nfig.suptitle('Frequency Counts', fontsize=14, fontweight='bold');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Choosing ggplot style\nplt.style.use('seaborn-whitegrid')\n\n# Get the figure and the axes (or subplots)\nfig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(15, 4))\n\n# value_counts\nspeed_counts = train_df['speed'].value_counts().sort_index()\n\n# Prepare data for ax0  \nprint(speed_counts)\nprint()\nx = speed_counts.index.values\nheight = speed_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax0.bar(x, height, width=0.5, align='center')\nax0.set(title = 'speed_counts ', xlabel='speed' , ylabel = 'Frequency')\nax0.set_xticks([0, 1])\n\n\n\n# Prepare data for ax1  \n# value_counts\nnumber_of_notes_counts = train_df['number_of_notes'].value_counts().sort_index()\nprint(number_of_notes_counts)\n\nprint()\nx = number_of_notes_counts.index.values\nheight = number_of_notes_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax1.bar(x, height, width=0.5, align='center')\nax1.set(title = 'number_of_notes Counts', xlabel='number_of_notes' , ylabel = 'Frequency')\n\n\n\n\n# Prepare data for ax1  \n# value_counts\nbird_seen_counts = train_df['bird_seen'].value_counts().sort_index()\nprint(bird_seen_counts)\n\nprint()\nx = bird_seen_counts.index.values\nheight = bird_seen_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax2.bar(x, height, width=0.5, align='center')\nax2.set(title = 'bird_seen Counts', xlabel='bird_seen' , ylabel = 'Frequency')\nax2.set_xticks([0, 1])\n\n# Title the figure\nfig.suptitle('Frequency Counts', fontsize=14, fontweight='bold');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Choosing ggplot style\nplt.style.use('seaborn-darkgrid')\n\n# Get the figure and the axes (or subplots)\nfig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(15, 4))\n\n# Prepare data for ax0  \n# value_counts\nvolume_counts = train_df['volume'].value_counts().sort_index()\nprint(volume_counts)\n\nprint()\nx = volume_counts.index.values\nheight = volume_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax0.bar(x, height, width=0.5, align='center')\nax0.set(title = 'volume Counts', xlabel='volume' , ylabel = 'Frequency')\n\n\n\n\n# Prepare data for ax2  \n# value_counts\nlength_counts = train_df['length'].value_counts().sort_index()\nprint(length_counts)\n\nprint()\nx = length_counts.index.values\nheight = length_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax1.bar(x, height, width=0.5, align='center')\nax1.set(title = 'length Counts', xlabel='length' , ylabel = 'Frequency')\n\n\n\n# Prepare data for ax3  \n# value_counts\nlicense_counts = train_df['license'].value_counts().sort_index()\nprint(license_counts)\n\nprint()\nx = license_counts.index.values\nheight = license_counts.values\n\n# Axes.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)\nax2.bar(x, height, width=0.5, align='center')\nax2.set(title = 'license Counts', xlabel='license' , ylabel = 'Frequency')\n\n\n# Title the figure\nfig.suptitle('Frequency Counts', fontsize=14, fontweight='bold');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"draw_pie_chart(train_df['species'].value_counts().sort_index() , 'channels', .4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Conclusion\n\nThus we have grouped similar attributes and presented their frequecy counts to analyse the data. \n\nHope you enjoyed reading it so far.\n\nKindly upvote if you found it useful.\n\nThanks","execution_count":null}],"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}