분류에 사용하는 특성 개선

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...