Python 튜토리얼

기초

  • moneyIcon Prize : 교육
  • 9,999명 D-100694

 

Lv1 모델링 python 파이썬 train_test_split() - (4)

2021.10.15 10:14 11,247 Views

안녕하세요. 👷‍♀️👷‍♂️

이번시간에는 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())



output :

2    10021

1    10003

0     9976

Name: category, dtype: int64


2    3341

1    3334

0    3325

Name: category, dtype: int64

--------------------------------------------------------------------------------------------------------------------------------------------


[Colab 실습 링크]


↩️ 오늘의 파이썬 리스트


#데이콘_101 #AI #머신러닝 #딥러닝 #파이썬 #파이선 #데이터분석 #데이터사이언티스트 #코랩 #Python #colab #kaggle #pandas #numpy #sckit-learn  # train_test_split()


로그인이 필요합니다
0 / 1000
왼쪽눈썹왁싱
2021.11.03 12:07


오늘의 파이썬 링크에서🌷Lv1 | 모델링 | 4/6 | train_test_split - (4) 클릭시 '오늘의 파이썬' 화면이 나옵니다. 확인 부탁드립니다.

DACON.투게더
2021.11.03 12:15

안녕하세요. 왼쪽눈썹왁싱님.

내용 수정 되었습니다.

감사합니다.

moran
2022.01.04 15:52

dbnoid
2022.01.20 13:27

acebed
2022.03.11 14:52

done

비회원
2022.04.07 11:36

코튼클린
2023.01.17 16:25

done

highllight
2023.02.12 17:50

이전 글
인덱싱을 위한 Pandas .iloc .loc 사용 방법 데이터 분석 및 조작을위한
Competition - Python 튜토리얼
Likes 4
Views 1,852
Comments 0
일 년 전
현재 글
Lv1 모델링 python 파이썬 train_test_split() - (4)
Competition - Python 튜토리얼
Likes 6
Views 11,247
Comments 8
3년 전
다음 글
다음 글이 존재하지 않습니다.