반응형
이 글에서는 이론은 다루지 않습니다.
일원분산분석 (One-way ANOVA)
일원분산분석에서 등분산 검정은 sklearn에 포함된
Signature: bartlett(*samples)
Docstring:
Perform Bartlett's test for equal variances.
Bartlett's test tests the null hypothesis that all input samples
are from populations with equal variances. For samples
from significantly non-normal populations, Levene's test
`levene` is more robust.
만약
이원분산분석 (Two-way ANOVA)
요인이 두개 이상이고 그룹이 두개 이상인 경우이다. 요인간의 상호작용이 있는지 확인하고, 상호작용이 없을시 일원분산분석을 각각의 요인에 대해 수행한다. 일원분산분석처럼 statsmodels.formula.api.ols, statsmodels.stats.anova.anova_lm을 통해 측정 가능하다.
- 독립변수 : C_var1, C_var2 (모두 범주형 변수)
- 종속변수 : target
아래와 같은 코드를 이용하여 이원분산분석, 그 중에서 상호작용항의 정보를 구할 수 있다.
from statsmodels.formula.api import ols
from statsmodels.api import stats
model = ols('target ~ C(C_var1) + C(C_var2) + C(C_var1):C(C_var2)', df).fit()
stats.anova_lm(model)
위 코드에서 C_var1과 C_var2 변수를 C로 감싼 것은 범주형 변수라는 것을 알려주는 것이다. 만약 범주형 변수에 C 로 감싸주지 않는다면 잘못된 값을 얻을 것이다.
위 코드를 실행하면 아래와 같은 결과를 얻을 수 있다.

index에 상호작용항
반응형
'AI > Data Science' 카테고리의 다른 글
[분석통계] 정규성 검정 (0) | 2023.05.29 |
---|---|
[분석통계] 통계적 검정 방법 간단 정리 (0) | 2023.05.27 |
[Pandas] 여러 Column 동시에 추가하기 (assign) (0) | 2023.04.19 |
가설과 P-Value의 의미 (0) | 2023.04.11 |
[Pandas] Apply, Map Practice (0) | 2023.04.02 |