ฟีเจอร์อนุพันธ์: Tempogram
ข้อดีอย่างหนึ่งของการทำความสะอาดข้อมูลคือช่วยให้คำนวณฟีเจอร์ที่ซับซ้อนขึ้นได้ ตัวอย่างเช่น การคำนวณ envelope ที่ทำไปก่อนหน้านี้เป็นเทคนิคที่นิยมใช้ในการสร้างฟีเจอร์ tempo และ rhythm ในแบบฝึกหัดนี้ จะใช้ librosa เพื่อคำนวณฟีเจอร์ tempo และ rhythm สำหรับข้อมูลเสียงการเต้นของหัวใจ แล้วฝึกโมเดลอีกครั้ง
โปรดทราบว่าฟังก์ชันของ librosa มักทำงานกับ numpy arrays เท่านั้น ไม่ใช่ DataFrame ดังนั้นจึงต้องเข้าถึงข้อมูล Pandas ในรูปแบบ Numpy array โดยใช้ attribute .values
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning สำหรับข้อมูล Time Series ใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Calculate the tempo of the sounds
tempos = []
for col, i_audio in audio.items():
tempos.append(lr.beat.____(y=i_audio.values, sr=sfreq, hop_length=2**10))
# Convert the list to an array so you can manipulate it more easily
tempos = np.array(tempos)
# Calculate statistics of each tempo
tempos_mean = tempos.____(axis=-1)
tempos_std = tempos.____(axis=-1)
tempos_max = tempos.____(axis=-1)