let us not love with words or tongue but actions and truth.

IT/파이썬 36

Imbalanced Dataset에서의 over sampling과 cross validation

지금 분석 하려고 하는 내용은 복잡하니, 개괄적인 내용만 미리 정리해보겠습니다. 우선 Imbalanced Dataset를 모델링시키기 위해서는 아래와 같은 순서로 진행합니다. StratifiedKFold기법을 적용하여, train과 test dataset으로 쪼개고 Train dataset의 Minority class를 over sampling하고 over sampling 된 traing dataset으로 모델을 Traning 시킨 후 원래 데이터의 test dataset을 통해 test한 후 모델설명력을 평균 내는 것 (cross validation의 원리) 왜 imbalanced dataset에서는 위와 같이 복잡하게 진행할까라고 하시는 분들은 아래 설명을 보시면 조금 이해가 될거 같습니다. www...

IT/파이썬 2020.12.09

ANOVA분석 & POST-HOC (사후검정)

그룹간 차이가 있는지 볼 수 있는 ANOVA검정과 사후검정 관련 포스팅을 해보겠습니다. ANOVA분석 우선 분석할 내용은, 4개의 A,B,C,D라는 학급별 수학/영어/과학 점수의 차이가 있는지 분석하는 것입니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 score_list=['math','eng','science'] from scipy import stats fstat_list=[] p_list=[] for i in lg_cat_list: fstat, p = stats.f_oneway(class_A[i], class_B[i], class_C[i], class_D[i]) fstat_list.append(fstat) p_list.append(p) Colored by Color Scripter c..

IT/파이썬 2020.12.04

Chi-square test, Fisher's exact 검정 & post-hoc

Chi-square test category형 변수별 target 과의 유의차가 있는지 검정할 때, Category변수가 많다면 아래와 같이 for문으로 작성하는 것이 더 편합니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 from scipy.stats import chi2_contingency chi_list=['cat1', 'cat2', 'cat3'] chi_val_list=[] chi_p_list=[] for i in chi_list: # contingency: 관측도수 contingency= pd.crosstab(df[i], df['target']) # dof: degree of freedom # expected: chi, p, dof, expected =chi2_conti..

IT/파이썬 2020.12.04

T-Test, levene test, 맨-휘트니 U 검정(Mann-Whitney U test)

검정해야할 컬럼들이 많을 때, 아래와 같이 for문으로 작성하면 훨씬 편하다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from scipy import stats col_list=['col1', 'col2', 'col3'] t_list=[] p_list=[] lp_list=[] up_list=[] for i in col_list: t, p = stats.ttest_ind(df[(df['target']==1)][i],df[(df['target']==0)][i]) lt, lp = stats.levene(df[(df['target']==1)][i],df[(df['target']==0)][i]) # 비모수검정 mann whitney u 검정 u, up = stats...

IT/파이썬 2020.12.04