क्लासिफिकेशन के लिए इस्तेमाल होने वाले फीचर्स को बेहतर बनाना

Python में Time Series Data के लिए Machine Learning

Chris Holdgraf

Fellow, Berkeley Institute for Data Science

ऑडिटरी एनवलप

  • ऑडिटरी एनवलप निकालने के लिए डेटा को स्मूथ करें
  • हर समय बिंदु पर मौजूद कुल ऑडियो ऊर्जा से जुड़ा

Python में Time Series Data के लिए Machine Learning

समय के साथ स्मूथिंग

  • पूरे समय पर औसत लेने के बजाय, आप लोकल औसत ले सकते हैं
  • इसे अपनी टाइमसीरीज़ को स्मूथ करना कहते हैं
  • यह अल्पकालिक शोर हटाता है और समग्र पैटर्न बचाता है
Python में Time Series Data के लिए Machine Learning

अपने डेटा को स्मूथ करें

Python में Time Series Data के लिए 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 में Time Series Data के लिए Machine Learning

ऑडिटरी एनवलप की गणना

  • पहले अपने ऑडियो को rectify करें, फिर स्मूथ करें

      audio_rectified = audio.apply(np.abs)
      audio_envelope = audio_rectified.rolling(50).mean()
    
Python में Time Series Data के लिए Machine Learning

Python में Time Series Data के लिए Machine Learning

Python में Time Series Data के लिए Machine Learning

Python में Time Series Data के लिए 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 में Time Series Data के लिए Machine Learning

scikit-learn के लिए फीचर्स तैयार करना

X = np.column_stack([envelope_mean, envelope_std, envelope_max])
y = labels.reshape(-1, 1)
Python में Time Series Data के लिए Machine Learning

क्लासिफिकेशन के लिए क्रॉस-वैलिडेशन

  • cross_val_score यह प्रक्रिया ऑटोमेट करता है:
    • डेटा को training/validation सेट्स में बाँटना
    • मॉडल को training डेटा पर फिट करना
    • validation डेटा पर स्कोर करना
    • इस प्रक्रिया को दोहराना
Python में Time Series Data के लिए 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 में Time Series Data के लिए Machine Learning

ऑडिटरी फीचर्स: टेम्पोग्राम

  • हम टाइमसीरीज़-विशिष्ट फंक्शन्स से जटिल समय-संबंधी जानकारी का सार ले सकते हैं
  • librosa ऑडिटरी और टाइमसीरीज़ फीचर इंजीनियरिंग के लिए बढ़िया लाइब्रेरी है
  • यहाँ हम tempogram निकालेंगे, जो समय के साथ ध्वनि के tempo का अनुमान लगाता है
  • एनवलप की तरह ही, हम tempo के summary statistics भी निकाल सकते हैं
Python में Time Series Data के लिए 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 में Time Series Data के लिए Machine Learning

अभ्यास करते हैं!

Python में Time Series Data के लिए Machine Learning

Preparing Video For Download...