시작하기무료로 시작하기

특성 선택과 함께 Naive Bayes 학습하기

이제 3장의 마지막에서 실행했던 Naive Bayes 텍스트 분류 모델을, 직전 연습 문제에서 선택한 열인 volunteer 데이터셋의 titlecategory_desc 를 사용해 다시 실행해 보세요.

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

Python으로 배우는 Machine Learning 전처리

강의 보기

연습 안내

  • 클래스 분포가 고르지 않으므로, filtered_text 텍스트 벡터와 y 레이블(즉, category_desc 레이블)을 train_test_split() 에 넣고, stratify 매개변수에 y 를 전달하세요.
  • nb Naive Bayes 모델을 X_trainy_train 에 맞추세요.
  • nb 의 테스트 세트 정확도를 계산하세요.

실습형 인터랙티브 연습

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

# Split the dataset according to the class distribution of category_desc
X_train, X_test, y_train, y_test = ____(____.toarray(), ____, stratify=____, random_state=42)

# Fit the model to the training data
nb.____

# Print out the model's accuracy
print(nb.____)
코드 편집 및 실행