開始使用免費開始

UFO 資料集建模,Part 2

最後,你要使用我們建立的文字向量 desc_tfidf,並用 filtered_words 名單來建立一個已篩選的文字向量。來看看你能否根據文字預測目擊事件的 type。你將使用 Naive Bayes 模型來完成這項任務。

本練習屬於課程

Python 的 Machine Learning 前處理

檢視課程

練習說明

  • filtered_words 名單傳入索引,篩選 desc_tfidf 向量。
  • 切分 filtered_text 特徵與 y,並確保訓練集與測試集的類別分布相同;random_state 設為 42
  • 使用 nb 模型的 .fit() 來訓練 X_trainy_train
  • 列印 nb 模型在 X_testy_test 上的 .score()

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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
____
編輯並執行程式碼