본문 바로가기

파이썬/머신러닝,딥러닝

train_test_split 에서 stratify 의 의미

 

학습 데이터와 시험 데이터로 분리

from sklearn.model_selection import train_test_split  #Scikit-Learn 의 model_selection library를 train_test_split로 명명
X_train,X_test,y_train,y_test=train_test_split(X,y, test_size=0.3, random_state=1, stratify=y)   # x와 y의 data를 각각 30%, 70%의 비율로 test_set과 training_set으로 나눔

 

학습 데이터로 자료를 학습시키고 학습에 전혀 사용하지 않은 시험데이터에 적용하여

학습 결과의 일반화가 가능한지 알아보기 위함이다.

 

학습 데이터와 시험 데이터 모두 동일한 비율의 y 의 범주가 포함되도록 층화추출법을 사용한 것으로

 

stratify = y 를 부여하여 y 값으로 층화해 임의표집하도록 한다.