分類に使用する特徴量の改善

Pythonで学ぶMachine Learningによる時系列データ解析

Chris Holdgraf

Fellow, Berkeley Institute for Data Science

聴覚エンベロープ

  • データを平滑化して聴覚エンベロープを算出する
  • 各時点における音響エネルギーの総量に関連する

Pythonで学ぶMachine Learningによる時系列データ解析

時間方向の平滑化

  • 全時間で平均するのではなく、局所的な平均を計算できます
  • これを時系列の平滑化と呼びます
  • 短期的なノイズを除去しながら全体のパターンを保持します
Pythonで学ぶMachine Learningによる時系列データ解析

データの平滑化

Pythonで学ぶMachine Learningによる時系列データ解析

ローリングウィンドウ統計量の計算

# 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()
Pythonで学ぶMachine Learningによる時系列データ解析

聴覚エンベロープの計算

  • まず音声を_整流_し、次に平滑化します

      audio_rectified = audio.apply(np.abs)
      audio_envelope = audio_rectified.rolling(50).mean()
    
Pythonで学ぶMachine Learningによる時系列データ解析

Pythonで学ぶMachine Learningによる時系列データ解析

Pythonで学ぶMachine Learningによる時系列データ解析

Pythonで学ぶMachine Learningによる時系列データ解析

エンベロープの特徴量エンジニアリング

# 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])
Pythonで学ぶMachine Learningによる時系列データ解析

scikit-learn 向けの特徴量準備

X = np.column_stack([envelope_mean, envelope_std, envelope_max])
y = labels.reshape(-1, 1)
Pythonで学ぶMachine Learningによる時系列データ解析

分類のための交差検証

  • cross_val_score は以下のプロセスを自動化します:
    • データを訓練セット/検証セットに分割
    • 訓練データでモデルを学習
    • 検証データでスコアを算出
    • このプロセスを繰り返す
Pythonで学ぶMachine Learningによる時系列データ解析

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]
Pythonで学ぶMachine Learningによる時系列データ解析

音声特徴量:テンポグラム

  • 時系列専用の関数でより複雑な時間情報を集約できます
  • librosa は音声・時系列の特徴量エンジニアリングに優れたライブラリです
  • ここではテンポグラムを計算し、音声のテンポを時間軸で推定します
  • エンベロープと同様に、テンポの要約統計量を算出できます
Pythonで学ぶMachine Learningによる時系列データ解析

テンポグラムの計算

# 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)
Pythonで学ぶMachine Learningによる時系列データ解析

練習しましょう!

Pythonで学ぶMachine Learningによる時系列データ解析

Preparing Video For Download...