시각화
Histogram
- Seaborn의 histplot() 함수로 Histogram을 그린다
sns.histplot(x='BloodPressure', hue='Outcome', data=diabetes, bins=20)
plt.show()

Density Plot
- Seaborn의 kdeplot() 함수로 Density Plot을 그린다
① kdeplot(..., hue='Outcome')
- 당뇨병환자여부의 비율이 유지된 채로 표시
- 두 그래프의 아래 면적의 합이 1
sns.kdeplot(x='BloodPressure', hue='Outcome', data=diabetes)
plt.show()
② kdeplot(..., hue='Outcome', common_norm=False)
- common_norm 매개변수 값을 False로 지정하면 두 그래프 각각의 아래 면적이 1이 된다
- common_norm 매개변수의 기본값은 True

multiple='fill' 지정
- multiple 매개변수 값을 'fill' 로 지정해 비율을 비교가능
- 단, 양의 비교가 아닌 비율을 비교
- 페인트 칠 한 것 처럼 보임
① kdeplot(..., hue='Outcome', multiple='fill')
sns.kdeplot(x='BloodPressure', hue='Outcome', data=diabetes, multiple='fill')
plt.axhline(diabetes['Outcome'].mean(), color='r')
plt.show()

② histplot(..., hue='Outcome', multiple='fill')
sns.histplot(x='BloodPressure', hue='Outcome', data=diabetes, bins=20, multiple='fill')
plt.axhline(diabetes['Outcome'].mean(), color='r')
plt.show()

수치화
로지스틱 회귀 .Logit()
- 수치형 VS 범주형에 맞는 가설 검정 도구는 없음
- 로지스틱 회귀 모델로 p-value를 구해서 차이가 있는지 없는지를 확인해보면 되겠다
temp = diabetes.loc[diabetes['BloodPressure'].notnull()]
model = sm.Logit(temp['Outcome'], temp['BloodPressure'])
result = model.fit()
print(result.pvalues)
'KT 에이블스쿨 8기 > 데이터분석' 카테고리의 다른 글
| 이변량 분석 ③ - 범주형 → 범주형 (0) | 2025.11.25 |
|---|---|
| 이변량 분석 ② - 범주형 → 수치형 (1) | 2025.11.25 |
| 단변량 분석 ② - 범주형 (0) | 2025.11.25 |
| 단변량 분석 ① - 수치형 (0) | 2025.11.25 |
| 시각화라이브러리 ② - Seaborn (0) | 2025.11.25 |