{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"},{"sourceId":4784719,"sourceType":"datasetVersion","datasetId":2769560}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\ndf = pd.read_csv(r\"/kaggle/input/birdsong-recognition/train.csv\")\n\n# Boxplot of Observation Durations by Species\nplt.figure(figsize=(8, 6))\nsns.boxplot(x='speed', y='duration', data=df)\nplt.xticks(rotation=90)\nplt.title('Boxplot of Observation Durations by Speed')\nplt.xlabel('Speed')\nplt.ylabel('Duration')\nplt.savefig('Box Plot(Durations by Speed).png')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-02T09:34:39.816632Z","iopub.execute_input":"2024-03-02T09:34:39.817449Z","iopub.status.idle":"2024-03-02T09:34:40.747739Z","shell.execute_reply.started":"2024-03-02T09:34:39.817408Z","shell.execute_reply":"2024-03-02T09:34:40.746534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\ndf = pd.read_csv(r\"/kaggle/input/birdsong-recognition/train.csv\")\n\nplt.figure(figsize=(10, 5))\nplt.hist(df['number_of_notes'], bins=40, edgecolor='black')\nplt.xlabel('Call Duration (seconds)')\nplt.ylabel('Frequency')\nplt.title('Distribution of Number of Notes')\nplt.savefig('Bar Chart(Distribution of Notes).png')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-02T09:34:40.750024Z","iopub.execute_input":"2024-03-02T09:34:40.750388Z","iopub.status.idle":"2024-03-02T09:34:41.589176Z","shell.execute_reply.started":"2024-03-02T09:34:40.750356Z","shell.execute_reply":"2024-03-02T09:34:41.587851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport pandas as pd\n\ndata = pd.read_csv(r\"/kaggle/input/birdsong-recognition/train.csv\")\n\n# Filter out the records where the bird was seen\nseen_birds = data[data['bird_seen'] == 'yes']\n\n# Group the data by country and count the occurrences\ncountry_counts = seen_birds['country'].value_counts()\n\n# Prob. Sort the counts and get the top three\ntop_three = country_counts.nlargest(3)\n\n# Total Count. Sort the counts and get the top three\ntop_five = country_counts.head(5)\ntop_countries_names = top_five.index\ntop_countries_counts = top_five.values\n\n# Create the pie chart\nfig, ax = plt.subplots()\nax.pie(country_counts, labels=country_counts.index, startangle=90, autopct='%1.1f%%', colors=plt.cm.Pastel1.colors)\n\n# Hide all the labels\nfor text in ax.texts:\n    text.set_visible(False)\n\n# Only show the labels for the top three segments\nfor i, country in enumerate(top_three.index):\n    ax.texts[i*2].set_visible(True)  # Label\n    ax.texts[i*2 + 1].set_visible(True)  # Percentage\n\nplt.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.\n\n# Top 5 countries\nfor i, (name, count) in enumerate(zip(top_countries_names, top_countries_counts)):\n    plt.annotate(f'{name}: {count}', xy=(1, 0.1 - i*0.05), xycoords='axes fraction')\n\nplt.savefig('Pie Chart(Countries).png')\n\n# Display the pie chart\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-03-02T09:39:41.117952Z","iopub.execute_input":"2024-03-02T09:39:41.118398Z","iopub.status.idle":"2024-03-02T09:39:42.301844Z","shell.execute_reply.started":"2024-03-02T09:39:41.118364Z","shell.execute_reply":"2024-03-02T09:39:42.300600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torchaudio\nimport matplotlib.pyplot as plt\nfrom torchaudio.transforms import MelSpectrogram, Spectrogram\n\nfilename = '/kaggle/input/birdsong-recognition/train_audio/whcspa/XC125252.mp3'\n\nwaveform, sr = torchaudio.load(filename)\n# mel spectrogram\nmel_specgram = MelSpectrogram(sample_rate=sr, n_fft=2048, hop_length=512, n_mels=128)(waveform)\n\n# adjust mel spectrogram size\ntarget_length = 1024\nn_frames = mel_specgram.shape[2]\nif n_frames < target_length:\n    pad = torch.zeros((1, mel_specgram.shape[1], target_length - n_frames))\n    mel_specgram = torch.cat((mel_specgram, pad), dim=2)\nelif n_frames > target_length:\n    mel_specgram = mel_specgram[:, :, :target_length]\n\n# convert the mel spectrogram to a dB scale and to a numpy array\nmel_specgram = torchaudio.transforms.AmplitudeToDB()(mel_specgram).numpy()\n\n# Visualize Mel Spectrogram features\nplt.figure(figsize=(8, 3))\nplt.imshow(mel_specgram[0], origin='lower', aspect='auto', cmap='jet')\nplt.set_cmap('RdYlBu')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Mel Spectrogram of White-crowned Sparrow')\nplt.tight_layout()\nplt.savefig('Mel Spectrogram: White-crowned Sparrow(XC125252).png')\nplt.show()\n\nfilename = '/kaggle/input/birdsong-recognition/train_audio/amered/XC101593.mp3'\nwaveform, sr = torchaudio.load(filename)\n# mel spectrogram\nmel_specgram = MelSpectrogram(sample_rate=sr, n_fft=2048, hop_length=512, n_mels=128)(waveform)\n\n# adjust mel spectrogram size\ntarget_length = 1024\nn_frames = mel_specgram.shape[2]\nif n_frames < target_length:\n    pad = torch.zeros((1, mel_specgram.shape[1], target_length - n_frames))\n    mel_specgram = torch.cat((mel_specgram, pad), dim=2)\nelif n_frames > target_length:\n    mel_specgram = mel_specgram[:, :, :target_length]\n\n# convert the mel spectrogram to a dB scale and to a numpy array\nmel_specgram = torchaudio.transforms.AmplitudeToDB()(mel_specgram).numpy()\n\n# Visualize Mel Spectrogram features\nplt.figure(figsize=(8, 3))\nplt.imshow(mel_specgram[0], origin='lower', aspect='auto', cmap='jet')\nplt.set_cmap('RdYlBu')\nplt.colorbar(format='%+2.0f dB')\nplt.title('Mel Spectrogram of White-crowned Sparrow ')\nplt.tight_layout()\nplt.savefig('Mel Spectrogram: White-crowned Sparrow(XC101593).png')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-02T09:52:21.435788Z","iopub.execute_input":"2024-03-02T09:52:21.436466Z","iopub.status.idle":"2024-03-02T09:52:23.517569Z","shell.execute_reply.started":"2024-03-02T09:52:21.436426Z","shell.execute_reply":"2024-03-02T09:52:23.516518Z"},"trusted":true},"execution_count":null,"outputs":[]}]}