특성 선택과 함께 Naive Bayes 학습하기
이제 3장의 마지막에서 실행했던 Naive Bayes 텍스트 분류 모델을, 직전 연습 문제에서 선택한 열인 volunteer 데이터셋의 title 과 category_desc 를 사용해 다시 실행해 보세요.
이 연습은 강의의 일부입니다
Python으로 배우는 Machine Learning 전처리
연습 안내
- 클래스 분포가 고르지 않으므로,
filtered_text텍스트 벡터와y레이블(즉,category_desc레이블)을train_test_split()에 넣고,stratify매개변수에y를 전달하세요. nbNaive Bayes 모델을X_train과y_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.____)