새로운 피처의 상관관계 살펴보기
이제 거래량과 datetime 기반 피처를 만들었으니, new_features 리스트에 저장한 새로운 피처들과 타깃(5d_close_future_pct) 간의 상관관계를 확인해 얼마나 밀접하게 관련되어 있는지 살펴보겠습니다. pandas에는 DataFrame용 내장 메서드 .corr()가 있고, seaborn에는 상관관계를 시각화하기 좋은 heatmap() 함수가 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 금융 분야 Machine Learning
연습 안내
- 요일 번호를
'weekday_'문자열과 이어 붙여weekday_1같은 요일 컬럼 이름이new_features에 포함되도록new_features변수를 확장하세요. - Seaborn의
heatmap을 사용해new_features와 타깃5d_close_future_pct의 상관관계를 그려 보세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Add the weekday labels to the new_features list
new_features.extend([____ + ____ for i in range(1, 5)])
# Plot the correlations between the new features and the targets
sns.____(lng_df[____ + ['5d_close_future_pct']].corr(), annot=True)
plt.yticks(rotation=0) # ensure y-axis ticklabels are horizontal
plt.xticks(rotation=90) # ensure x-axis ticklabels are vertical
plt.tight_layout()
plt.show()