The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.

우주먼지·2021년 11월 29일
1
data = result['document']
target = result['label']
x_train, x_test, y_train, y_test = train_test_split(data, target, test_size=0.2, shuffle=True, stratify = target, random_state=42)
print(len(x_train), len(x_test))

test, train set 을 나누기 위햇 train_test_split을 사용했을 때 발생했던 오류이다.

이경우 stratify를 제거해주면 정상 작동하는데,

stratify의 역할은 훈련데이터를 나눌 때 무작위로 샘플링을 하되, original dataset의 클래스 비율이 train, test set에서도 동일하게 유지되게 해준다. original dataset에서 특정 클래스 비율이 불균형한 경우 stratify 매개변수에 타깃 데이터를 지정하여 호출하면 이 비율이 유지될 수 있도록 샘플링한다.(default = None)

이 오류는 stratify하게 나눌수 없을 때 발생하는 오류로 만약 특정 라벨값을 가진 데이터가 0개일 경우 발생한다. 적어도 train에 하나 test에 하나는 있어야 하므로 모든 라벨의 데이터가 적어도 2개 이상 가져야한다는 뜻이다.

profile
안녕하세요 ㅎㅎ

0개의 댓글