การปรับปรุง Feature ที่ใช้สำหรับการจำแนกประเภท

Machine Learning สำหรับข้อมูล Time Series ใน Python

Chris Holdgraf

Fellow, Berkeley Institute for Data Science

Auditory Envelope

  • ทำ Smoothing ข้อมูลเพื่อคำนวณ Auditory Envelope
  • สะท้อนพลังงานเสียงรวมในแต่ละช่วงเวลา

Machine Learning สำหรับข้อมูล Time Series ใน Python

Smoothing ตามเวลา

  • แทนที่จะเฉลี่ยตลอด ทุก ช่วงเวลา ให้ใช้การเฉลี่ย เฉพาะที่ แทน
  • เรียกว่า Smoothing ของ Timeseries
  • ช่วยลดสัญญาณรบกวนระยะสั้น ขณะที่ยังคงรูปแบบโดยรวมไว้
Machine Learning สำหรับข้อมูล Time Series ใน Python

การทำ Smoothing ข้อมูล

Machine Learning สำหรับข้อมูล Time Series ใน Python

การคำนวณสถิติแบบ Rolling Window

# Audio is a Pandas DataFrame
print(audio.shape)  
# (n_times, n_audio_files)
(5000, 20)  
# Smooth our data by taking the rolling mean in a window of 50 samples
window_size = 50
windowed = audio.rolling(window=window_size)
audio_smooth = windowed.mean()
Machine Learning สำหรับข้อมูล Time Series ใน Python

การคำนวณ Auditory Envelope

  • Rectify เสียงก่อน แล้วจึงทำ Smoothing

      audio_rectified = audio.apply(np.abs)
      audio_envelope = audio_rectified.rolling(50).mean()
    
Machine Learning สำหรับข้อมูล Time Series ใน Python

Machine Learning สำหรับข้อมูล Time Series ใน Python

Machine Learning สำหรับข้อมูล Time Series ใน Python

Machine Learning สำหรับข้อมูล Time Series ใน Python

Feature Engineering จาก Envelope

# Calculate several features of the envelope, one per sound
envelope_mean = np.mean(audio_envelope, axis=0)
envelope_std = np.std(audio_envelope, axis=0)
envelope_max = np.max(audio_envelope, axis=0)

# Create our training data for a classifier
X = np.column_stack([envelope_mean, envelope_std, envelope_max])
Machine Learning สำหรับข้อมูล Time Series ใน Python

เตรียม Feature สำหรับ scikit-learn

X = np.column_stack([envelope_mean, envelope_std, envelope_max])
y = labels.reshape(-1, 1)
Machine Learning สำหรับข้อมูล Time Series ใน Python

Cross Validation สำหรับการจำแนกประเภท

  • cross_val_score ทำให้กระบวนการต่อไปนี้เป็นอัตโนมัติ:
    • แบ่งข้อมูลเป็นชุด Training / Validation
    • Fit โมเดลกับข้อมูล Training
    • ประเมินคะแนนบนข้อมูล Validation
    • ทำซ้ำกระบวนการนี้
Machine Learning สำหรับข้อมูล Time Series ใน Python

การใช้ cross_val_score

from sklearn.model_selection import cross_val_score

model = LinearSVC()
scores = cross_val_score(model, X, y, cv=3) 
print(scores)
[0.60911642 0.59975305 0.61404035]
Machine Learning สำหรับข้อมูล Time Series ใน Python

Auditory Features: Tempogram

  • สามารถสรุปข้อมูลเวลาที่ซับซ้อนได้ด้วยฟังก์ชันเฉพาะของ Timeseries
  • librosa เป็นไลบรารีที่ดีสำหรับ Feature Engineering ด้านเสียงและ Timeseries
  • ที่นี่จะคำนวณ Tempogram ซึ่งประมาณค่า Tempo ของเสียงตามเวลา
  • สามารถคำนวณสถิติสรุปของ Tempo ได้เช่นเดียวกับ Envelope
Machine Learning สำหรับข้อมูล Time Series ใน Python

การคำนวณ Tempogram

# Import librosa and calculate the tempo of a 1-D sound array
import librosa as lr
audio_tempo = lr.beat.tempo(y=audio, sr=sfreq, 
                            hop_length=2**6)
Machine Learning สำหรับข้อมูล Time Series ใน Python

มาฝึกกันเถอะ!

Machine Learning สำหรับข้อมูล Time Series ใน Python

Preparing Video For Download...