{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd \nimport plotly.express as px\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport torch\nimport torchaudio\nimport os\nimport IPython.display as ipd\nimport numpy as np\nfrom plotly.offline import init_notebook_mode, iplot, plot\nimport plotly as py\ninit_notebook_mode(connected=True)\npd.set_option('display.max_columns', None)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"audio_files=[]\nfor root,_,files in os.walk(\"../input/birdsong-recognition/train_audio\"):\n    for f in files:\n        audio_files.append(os.path.join(root,f))","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":"# Birds Distribution Over The Globe\n","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_bird_geo=pd.DataFrame()\ndf_bird_geo['Bird_Name']=df['species']\ndf_bird_geo['lattitude']=df['latitude']\ndf_bird_geo['longitude']=df['longitude']\ndf_bird_geo['country']=df['country']\ndf_bird_geo_1=df_bird_geo.drop_duplicates()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.scatter_geo(df_bird_geo_1, lat=\"lattitude\",lon=\"longitude\",\n                     color=\"Bird_Name\", # which column to use to set the color of markers\n                     hover_name=\"country\", # column added to hover information\n                     projection=\"natural earth\")\niplot(fig)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Birds Count Distribution ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(10,5))\nsns.countplot(df.ebird_code,order=df.ebird_code.value_counts().index).set_xticklabels(\" \")\nplt.savefig(\"output1.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(df.ebird_code.value_counts(),bins=10)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Top 10 Countries  by Number of Birds Observed ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots()\nfig.set_size_inches(14, 5)\nx=(df.country.value_counts()[:10]).index \ny=(df.country.value_counts()[:10]).values\nsns.barplot(x=x,y=y,).set_yscale(\"log\") \nfig.savefig(\"outpu3.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Top Birds By Count","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly.express as px\nfig = px.bar(df, x=df['species'])\niplot(fig)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Audio Length Distribution over Dataset","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots()\nfig.set_size_inches(14, 5)\nsns.countplot(df.length,order=df.length.value_counts(ascending=True).index)\nfig.savefig(\"outpu4.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots()\nfig.set_size_inches(14, 5)\nsns.countplot(df.speed, order=df.speed.value_counts().index)\nfig.savefig(\"outpu5.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots()\nfig.set_size_inches(14, 5)\nsns.countplot(df.rating)\nfig.savefig(\"outpu5.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualizing Audio Waveform","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"filename = audio_files[0]\nwaveform, sample_rate = torchaudio.load(filename)\n\nprint(\"Shape of waveform: {}\".format(waveform.size()))\nprint(\"Sample rate of waveform: {}\".format(sample_rate))\nplt.figure(figsize=(15,5))\nplt.plot(waveform.t().numpy())\nipd.Audio(audio_files[0])\nfig.savefig(\"outpu6.jpeg\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Function To Conver Audio .mp3 / wav  -> Tensor ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"def convert_to_tensor(audio_file):\n    tensor, _= torchaudio.load(audio_file)\n    torch.save(tensor,'_tensor')\n    return tensor","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"convert_to_tensor(audio_files[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"np.shape(convert_to_tensor(audio_files[0]))","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}