UFO 데이터셋 모델링, 2부
마지막으로, 앞에서 만든 텍스트 벡터 desc_tfidf에 filtered_words 목록을 적용해 필터링된 텍스트 벡터를 만들고, 이를 사용해 모델을 구축해 보겠습니다. 텍스트를 기반으로 목격의 type을 예측할 수 있는지 확인해 볼까요? 여기서는 Naive Bayes 모델을 사용합니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Machine Learning 전처리
연습 안내
- 인덱스에
filtered_words목록을 전달해desc_tfidf벡터를 필터링하세요. - 학습/테스트 세트에서 클래스 분포가 같도록 유지하면서
filtered_text특성과y를 분할하세요.random_state는42로 사용하세요. nb모델의.fit()을 사용해X_train과y_train에 적합하세요.nb모델의.score()를X_test와y_test에 대해 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Use the list of filtered words we created to filter the text vector
filtered_text = ____[:, list(____)]
# Split the X and y sets using train_test_split, setting stratify=y
X_train, X_test, y_train, y_test = ____(____.toarray(), ____, ____, random_state=42)
# Fit nb to the training sets
____
# Print the score of nb on the test sets
____