카테고리 없음
내일배움캠프_데이터 전처리&시각화_2회차
iron-min
2025. 9. 25. 21:25
1. 기초 통계 분석
① describe : 데이터의 분포와 중심경향을 한눈에 파악할 수 있는 메서드 입니다.

② 상세 백분위수 보기
|
# 더 상세한 백분위수로 분석
detailed_stats = titanic.describe(percentiles=[.1, .25, .5, .75, .9, .95])
print("=== 상세 백분위수 분석 ===")
print(detailed_stats['Age'].round(2))
|

③ 데이터 컬럼만 보기
|
df.columns.tolist()
|

④ 결측치와 데이터 타입 보기
|
df.info()
|

⑤ 데이터 한 컬럼만 확인하기
|
df['fixed acidity']
|

⑥ 특정 조건을 만족하는 값만 확인하기
|
df[df['alcohol'] >= 12]
|

|
df_1 = df[(df['alcohol'] >= 12) & (df['quality'] >= 7)]
|

⑦ 인덱스 재정렬하기
|
df_1.reset_index()
|

⑧ 데이터 범주 확인
1) unique()
|
titanic['Sex'].unique()
|

2) value_counts()
|
sex_counts = titanic['Sex'].value_counts()
print("=== 성별 분포 ===")
print(sex_counts)
|

3) value_count(normalize=True)
|
sex_rations = titanic['Sex'].value_counts(normalize=True)
print("=== 성별 비율 ===")
print(sex_rations.round(2))
|

4) 'mean' : 평균, '50%' : 중위값
|
age_stats = titanic['Age'].describe()
mean_age = age_stats['mean']
median_age = age_stats['50%']
print(f"평균 나이: {mean_age:.1f}세")
print(f"중위수 나이: {median_age:.1f}세")
print(f"차이: {mean_age - median_age:.1f}세")
|

⑨ 왜도와 첨도 해석



|
# 왜도와 첨도로 분포 특성 정량화
age_data = titanic['Age'].dropna()
skewness = age_data.skew()
kurtosis = age_data.kurtosis()
print(f"왜도(Skewness): {skewness:.3f}")
print(f"첨도(Kurtosis): {kurtosis:.3f}")
|

추가로 왜도, 첨도에 대한 이해가 안되서 공식을 찾아봤습니다.
※ 크기가 n 인 표본의 왜도와 첨도


⑩ 상관관계 분석
|
# 주요 숫자형 변수들의 상관관계
numeric_cols = ['Survived', 'Pclass', 'Age', 'SibSp', 'Parch', 'Fare']
correlation_matrix = titanic[numeric_cols].corr()
print("=== 상관관계 매트릭스 ===")
print(correlation_matrix.round(3))
|
