Pythonで学ぶ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)データが少なくとも2次元であることを確認してください
第1次元がサンプルであることを確認してください
array.T.shape
(10, 3)
.reshape() を使用します:array.shape
(10,)
array.reshape(-1, 1).shape
(10, 1)
-1 は残りの値でその軸を自動的に補完します# Import a support vector classifier
from sklearn.svm import LinearSVC
# Instantiate this model
model = LinearSVC()
# Fit the model on some data
model.fit(X, y)
y の形状は (samples, 1) であることが一般的です
# There is one coefficient per input feature
model.coef_
array([[ 0.69417875, -0.5289162 ]])
# Generate predictions
predictions = model.predict(X_test)
Pythonで学ぶMachine Learningによる時系列データ解析