開始使用免費開始

文字向量化

現在你要將 UFO 資料集中的 desc 欄位轉換成 tf/idf 向量,因為這個欄位很可能藏有可用的資訊。

本練習屬於課程

Python 的 Machine Learning 前處理

檢視課程

練習說明

  • 列印 desc 欄位的 .head()
  • 建立一個 TfidfVectorizer() 物件。
  • 使用 vecdesc 欄位進行 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)
編輯並執行程式碼