시간 지연 특성과 자기회귀 모델

Python으로 배우는 시계열 데이터 Machine Learning

Chris Holdgraf

Fellow, Berkeley Institute for Data Science

과거는 유용합니다

  • 시계열 데이터는 거의 항상 시점 간에 공유되는 정보를 포함합니다
  • 과거 정보는 미래를 예측하는 데 도움이 됩니다
  • 시계열 예측에 가장 적합한 특성은 동일 시계열의 과거 값인 경우가 많습니다
Python으로 배우는 시계열 데이터 Machine Learning

평활도와 자기상관에 대하여

  • 시계열에서 자주 묻는 질문: 데이터가 얼마나 부드러운가
  • 즉, 한 시점이 인접 시점과 얼마나 상관되는지(자기상관)
  • 데이터의 자기상관 정도는 모델에 영향을 미칩니다
Python으로 배우는 시계열 데이터 Machine Learning

시간 지연 특성 생성하기

  • 과거 값을 입력 특성으로 사용하는 모델을 구축하는 방법을 살펴봅시다
  • 이를 통해 신호의 자기상관 정도(및 그 외 다양한 정보)를 평가할 수 있습니다
Python으로 배우는 시계열 데이터 Machine Learning

Pandas로 데이터 시간 이동하기

print(df)
         df 
    0   0.0
    1   1.0 
    2   2.0 
    3   3.0 
    4   4.0 
# Shift a DataFrame/Series by 3 index values towards the past
print(df.shift(3))
         df
    0   NaN
    1   NaN
    2   NaN
    3   0.0
    4   1.0
Python으로 배우는 시계열 데이터 Machine Learning

시간 이동 DataFrame 생성하기

# data is a pandas Series containing time series data
data = pd.Series(...)

# Shifts
shifts = [0, 1, 2, 3, 4, 5, 6, 7]

# Create a dictionary of time-shifted data
many_shifts = {'lag_{}'.format(ii): data.shift(ii) for ii in shifts}

# Convert them into a dataframe
many_shifts = pd.DataFrame(many_shifts)
Python으로 배우는 시계열 데이터 Machine Learning

시간 이동 특성으로 모델 학습하기

# Fit the model using these input features 
model = Ridge() 
model.fit(many_shifts, data)
Python으로 배우는 시계열 데이터 Machine Learning

자기회귀 모델 계수 해석하기

# Visualize the fit model coefficients
fig, ax = plt.subplots()
ax.bar(many_shifts.columns, model.coef_)
ax.set(xlabel='Coefficient name', ylabel='Coefficient value')

# Set formatting so it looks nice
plt.setp(ax.get_xticklabels(), rotation=45, horizontalalignment='right')
Python으로 배우는 시계열 데이터 Machine Learning

거친 신호의 계수 시각화

Python으로 배우는 시계열 데이터 Machine Learning

부드러운 신호의 계수 시각화

Python으로 배우는 시계열 데이터 Machine Learning

연습해 봅시다!

Python으로 배우는 시계열 데이터 Machine Learning

Preparing Video For Download...