文字向量化
你現在要把 volunteer 資料集的 title 欄位轉換成文字向量,並在下一個練習中用於預測任務。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 將
volunteer["title"]欄位存入名為title_text的變數。 - 以
tfidf_vec為名稱建立一個TfidfVectorizer物件。 - 使用
tfidf_vec將title_text的文字轉換為 tf-idf 向量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Take the title text
title_text = ____
# Create the vectorizer method
tfidf_vec = ____
# Transform the text into tf-idf vectors
text_tfidf = tfidf_vec.____(____)