文字向量化
現在你要將 UFO 資料集中的 desc 欄位轉換成 tf/idf 向量,因為這個欄位很可能藏有可用的資訊。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 列印
desc欄位的.head()。 - 建立一個
TfidfVectorizer()物件。 - 使用
vec對desc欄位進行 fit 與 transform。 - 列印
desc_tfidf向量的.shape,看看產生了多少欄。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Take a look at the head of the desc field
print(____)
# Instantiate the tfidf vectorizer object
vec = ____
# Fit and transform desc using vec
desc_tfidf = vec.____
# Look at the number of columns and rows
print(____.shape)