시작하기무료로 시작하기

UFO 데이터셋 모델링, 2부

마지막으로, 앞에서 만든 텍스트 벡터 desc_tfidffiltered_words 목록을 적용해 필터링된 텍스트 벡터를 만들고, 이를 사용해 모델을 구축해 보겠습니다. 텍스트를 기반으로 목격의 type을 예측할 수 있는지 확인해 볼까요? 여기서는 Naive Bayes 모델을 사용합니다.

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

Python으로 배우는 Machine Learning 전처리

강의 보기

연습 안내

  • 인덱스에 filtered_words 목록을 전달해 desc_tfidf 벡터를 필터링하세요.
  • 학습/테스트 세트에서 클래스 분포가 같도록 유지하면서 filtered_text 특성과 y를 분할하세요. random_state42로 사용하세요.
  • nb 모델의 .fit()을 사용해 X_trainy_train에 적합하세요.
  • nb 모델의 .score()X_testy_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
____
코드 편집 및 실행