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_train與y_train。 - 列印
nb模型在X_test與y_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
____