상관행렬 시각화하기
이전 연습 문제에서 만든 상관행렬은 히트맵으로 시각화할 수 있어요. 이를 위해 seaborn 라이브러리의 heatmap() 함수를 사용할 수 있으며, 히트맵 모양을 조정할 수 있는 다양한 인자를 제공합니다.
df_corr = df.corr()
sns.heatmap(df_corr)
plt.xticks(rotation=90)
plt.yticks(rotation=0)
축 레이블이 겹치지 않도록 .xticks()와 .yticks() 메서드를 사용해 회전시킬 수 있어요.
heatmap() 함수의 인자에 대해 더 알아보려면 이 페이지를 참고하세요.
이 연습은 강의의 일부입니다
Python으로 시계열 데이터 시각화
연습 안내
seaborn을sns로 임포트하세요.- Spearman 방법을 사용해
meatDataFrame의 모든 열 간 상관관계를 계산하고, 결과를corr_meat라는 새 변수에 할당하세요. corr_meat의 히트맵을 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import seaborn library
import ____ as ____
# Get correlation matrix of the meat DataFrame: corr_meat
____ = ____.____(method=____)
# Customize the heatmap of the corr_meat correlation matrix
____(corr_meat,
annot=True,
linewidths=0.4,
annot_kws={"size": 10})
plt.xticks(rotation=90)
plt.yticks(rotation=0)
plt.show()