여러 개의 롤링 특징 한꺼번에 만들기
이제 간단한 특징 엔지니어링을 연습해 보았으니, 좀 더 복잡한 작업으로 넘어가 보겠습니다. 시계열 데이터에 대해 여러 특징을 계산하고, 시간이 지남에 따라 어떻게 변하는지 시각화해 볼 거예요. 이 과정은 많은 시계열 모델이 동작하는 방식과 유사합니다.
이 연습은 강의의 일부입니다
Python으로 배우는 시계열 데이터 Machine Learning
연습 안내
- 계산할 네 가지 특징을 이 순서로 리스트에 정의하세요: 최소값, 최대값, 평균, 표준편차.
- 미리 정의된 롤링 윈도우(
prices_perc_rolling)를 사용해features_to_calculate의 특징들을 계산하세요. - 제공된 코드를 사용해 원래 시계열과 함께 시간에 따른 결과를 그래프로 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define a rolling window with Pandas, excluding the right-most datapoint of the window
prices_perc_rolling = prices_perc.rolling(20, min_periods=5, closed='right')
# Define the features you'll calculate for each window
features_to_calculate = [np.min, ____, ____, ____]
# Calculate these features for your rolling window object
features = prices_perc_rolling.____(features_to_calculate)
# Plot the results
ax = features.loc[:"2011-01"].plot()
prices_perc.loc[:"2011-01"].plot(ax=ax, color='k', alpha=.2, lw=3)
ax.legend(loc=(1.01, .6))
plt.show()