Classification और feature engineering

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

Chris Holdgraf

Fellow, Berkeley Institute for Data Science

मॉडल फिट करने से पहले हमेशा raw डेटा विज़ुअलाइज़ करें

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

अपना time series डेटा विज़ुअलाइज़ करें!

ixs = np.arange(audio.shape[-1])
time = ixs / sfreq
fig, ax = plt.subplots()
ax.plot(time, audio)

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

कौन से features इस्तेमाल करें?

  • Raw time series डेटा classification के लिए काफ़ी noisy होता है
  • हमें features निकालने होंगे!
  • आसान शुरुआत: अपने audio डेटा का सारांश निकालें
Python में Time Series Data के लिए Machine Learning

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

कई features की गणना

print(audio.shape)
# (n_files, time)
(20, 7000) 
means = np.mean(audio, axis=-1)
maxs = np.max(audio, axis=-1)
stds = np.std(audio, axis=-1)

print(means.shape)
# (n_files,)
(20,) 
Python में Time Series Data के लिए Machine Learning

scikit-learn से classifier फिट करना

  • हमने 2-D डेटासेट (samples x time) को 1-D डेटासेट (samples) के कई features में समेट दिया
  • हर feature को जोड़कर मॉडल के input के रूप में उपयोग कर सकते हैं
  • यदि हर sample का label है, तो scikit-learn से classifier बना और फिट कर सकते हैं
Python में Time Series Data के लिए Machine Learning

scikit-learn के लिए features तैयार करना

# Import a linear classifier
from sklearn.svm import LinearSVC

# Note that means are reshaped to work with scikit-learn
X = np.column_stack([means, maxs, stds])
y = labels.reshape(-1, 1)
model = LinearSVC()
model.fit(X, y)
Python में Time Series Data के लिए Machine Learning

अपने scikit-learn मॉडल को स्कोर करना

from sklearn.metrics import accuracy_score

# Different input data
predictions = model.predict(X_test)  

# Score our मॉडल with % correct
# मैन्युअली
percent_score = sum(predictions == labels_test) / len(labels_test)  
# sklearn scorer का उपयोग
percent_score = accuracy_score(labels_test, predictions)  
Python में Time Series Data के लिए Machine Learning

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

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

Preparing Video For Download...