train_test_split - (4)
Data Analyst

빅데이터 관련 자료/Dacon

train_test_split - (4)

carpe08 2021. 11. 23. 00:26
320x100
320x100

이번시간에는 train_test_split() 메소드의 stratify파라미터에 대해 알아보겠습니다.

 

stratify: stratify 파라미터는 분류 문제를 다룰 때 매우 중요하게 활용되는 파라미터 값 입니다. stratify 값으로는 target 값을 지정해주면 됩니다.

stratify값을 target 값으로 지정해주면 target의 class 비율을 유지 한 채로 데이터 셋을 split 하게 됩니다. 만약 이 옵션을 지정해주지 않고 classification 문제를 다룬다면, 성능의 차이가 많이 날 수 있습니다.

# 라이브러리 로딩

from sklearn.model_selection import train_test_split



#train_test_split() 메소드를 이용해 train/validation 데이터 나누기 

# stratify 옵션을 활용하여 데이터 셋 split



x_train,x_valid, y_train, y_valid = train_test_split(train_x,train['category'],stratify = train['category'])



# y_train,y_valid 비율 확인 (value_counts())



print(y_train.value_counts())

print(y_valid.value_counts())
320x100
320x100

'빅데이터 관련 자료 > Dacon' 카테고리의 다른 글

train_test_split / LGBM - (2)  (0) 2021.11.25
train_test_split / LGBM (1)  (0) 2021.11.24
train_test_split() - (3)  (0) 2021.11.22
train_test_split() - (2)  (0) 2021.11.21
train_test_split - (1)  (0) 2021.11.20