Python में Time Series Data के लिए Machine Learning
Chris Holdgraf
Fellow, Berkeley Institute for Data Science
array.shape
(10, 5)
array[:3]
array([[ 0.735528 , 1.00122818, -0.28315978],
[-0.94478393, 0.18658748, -0.00241224],
[-0.74822942, -1.46636618, 0.69835096]])
df.head()
col1 col2 col3
0 0.735528 1.001228 -0.283160
1 -0.944784 0.186587 -0.002412
2 -0.748229 -1.466366 0.698351
3 1.038589 -0.171248 0.831457
4 -0.161904 0.003972 -0.321933
देखें कि यह आपकी अपेक्षा जैसा दिख रहा है।
# Using matplotlib
fig, ax = plt.subplots()
ax.plot(...)
# Using pandas
fig, ax = plt.subplots()
df.plot(..., ax=ax)
Scikit-learn Python में सबसे लोकप्रिय मशीन लर्निंग लाइब्रेरी है
from sklearn.svm import LinearSVC
scikit-learn डेटा की एक खास संरचना अपेक्षित करता है:
(samples, features)सुनिश्चित करें कि आपका डेटा कम से कम दो-आयामी हो
सुनिश्चित करें कि पहली आयाम samples हो
array.T.shape
(10, 3)
.reshape() उपयोग करें: array.shape
(10,)
array.reshape(-1, 1).shape
(10, 1)
-1 उस axis को शेष मानों से स्वतः भर देगा# एक सपोर्ट वेक्टर क्लासिफायर इम्पोर्ट करें
from sklearn.svm import LinearSVC
# मॉडल instantiate करें
model = LinearSVC()
# कुछ डेटा पर मॉडल fit करें
model.fit(X, y)
अक्सर y का shape (samples, 1) होता है
# हर input feature के लिए एक coefficient होता है
model.coef_
array([[ 0.69417875, -0.5289162 ]])
# predictions जनरेट करें
predictions = model.predict(X_test)
Python में Time Series Data के लिए Machine Learning