시작하기무료로 시작하기

클래스 불균형 피하기

일부 데이터는 결과 변화가 매우 불균형할 수 있어요. 예를 들어 희귀 질병 데이터셋이 그렇죠. 무작위로 데이터를 나누면 아주 불운한 분할이 생길 수도 있습니다. 희귀한 관측치가 모두 테스트 세트에만 있고 학습 세트에는 하나도 없다면 어떨까요? 학습 과정 전체가 망가질 거예요!

다행히 initial_split() 함수가 이를 해결해 줍니다. 이번 연습에서는 이렇게 불리는 클래스 불균형을 관찰하고 해결해 보겠습니다.

이미 75% 학습, 25% 테스트로 분할한 분할 객체 diabetes_split을 만드는 코드는 제공되어 있어요.

이 연습은 강의의 일부입니다

R로 배우는 트리 기반 Machine Learning

강의 보기

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Preparation
set.seed(9888)
diabetes_split <- initial_split(diabetes, prop = 0.75)

# Proportion of 'yes' outcomes in the training data
counts_train <- table(training(___)$outcome)
prop_yes_train <- counts_train["___"] / sum(counts_train)

# Proportion of 'yes' outcomes in the test data
counts_test <- table(___)
prop_yes_test <- ___ / sum(___)

paste("Proportion of positive outcomes in training set:", round(prop_yes_train, 2))
paste("Proportion of positive outcomes in test set:", round(prop_yes_test, 2))
코드 편집 및 실행