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차원인지 확인하세요
첫 번째 차원이 samples인지 확인하세요
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