LoslegenKostenlos loslegen

Many repetitions of sounds

In this exercise, you'll start with perhaps the simplest classification technique: averaging across dimensions of a dataset and visually inspecting the result.

You'll use the heartbeat data described in the last chapter. Some recordings are normal heartbeat activity, while others are abnormal activity. Let's see if you can spot the difference.

Two DataFrames, normal and abnormal, each with the shape of (n_times_points, n_audio_files) containing the audio for several heartbeats are available in your workspace. Also, the sampling frequency is loaded into a variable called sfreq. A convenience plotting function show_plot_and_make_titles() is also available in your workspace.

Diese Übung ist Teil des Kurses

Machine Learning for Time Series Data in Python

Kurs anzeigen

Anleitung zur Übung

  • First, create the time array for these audio files (all audios are the same length).
  • Then, stack the values of the two DataFrames together (normal and abnormal, in that order) so that you have a single array of shape (n_audio_files, n_times_points).
  • Finally, use the code provided to loop through each list item / axis, and plot the audio over time in the corresponding axis object.
  • You'll plot normal heartbeats in the left column, and abnormal ones in the right column

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

fig, axs = plt.subplots(3, 2, figsize=(15, 7), sharex=True, sharey=True)

# Calculate the time array
time = np.arange(____) / ____

# Stack the normal/abnormal audio so you can loop and plot
stacked_audio = np.hstack([____, ____]).T

# Loop through each audio file / ax object and plot
# .T.ravel() transposes the array, then unravels it into a 1-D vector for looping
for iaudio, ax in zip(stacked_audio, axs.T.ravel()):
    ax.plot(time, iaudio)
show_plot_and_make_titles()
Code bearbeiten und ausführen