data는 캐글의 타이타닉 데이터를 사용함
참고자료: https://blog.naver.com/breezehome50/222352652567
[파이썬 시각화] 상관관계 분석 (Correlation Plot)
Correlation Plot Correlation plot은 두 변수간의 (선형적인) 상관관계를 비교하기 위해 사용되는 그래...
blog.naver.com
feature = ['Survived', 'Pclass', 'Age', 'SibSp', 'Parch', 'Fare','Sex_binary']
corr_feature = train_data[feature].corr()
fig = plt.figure(figsize=(20,20))
n_feature = len(feature)
for i in range(n_feature):
for j in range(n_feature):
ax = fig.add_subplot(n_feature,n_feature, i*n_feature + j + 1)
plt.scatter(feature[j], feature[i], data=train_data, s=9)
if i == n_feature-1:
plt.xlabel(feature[j], fontsize=12)
if j == 0:
plt.ylabel(feature[i], fontsize=12)
ax.annotate(np.round(corr_feature.loc[feature[i], feature[j]],3), xy=(1,0), xycoords='axes fraction', fontsize=16, horizontalalignment='right',verticalalignment='bottom')
plt.show()
결과

알게된 것
age처럼 다양한 숫자를 가진게 아닌 이상 그림을 볼 이유가 없었다. 간단히 상관계수만 뽑아봐도 되겠더라.
상관계수 뽑기
corr = train_data.corr(numeric_only = True)
corr

'Python_Wiki > Python_Library' 카테고리의 다른 글
| pandas 판다스: 날짜 다루기 (2) | 2025.07.11 |
|---|---|
| 웹크롤링: Selenium + chrome driver (0) | 2025.07.10 |
| library 업데이트에 따른 경고문 + 대체한 입력 방법 (0) | 2025.06.06 |
| matplotlib: word cloud 워드 클라우드 (2) | 2025.06.06 |
| matplotlib/seaborn: heatmap 히트맵 (0) | 2025.06.06 |