從顧客評論建立詞彙表
你是 TechZone(消費性電子公司)產品分析團隊的一員。你收到一小批關於一款新裝置的顧客評論。為了分析這些評論,你會先進行文字前處理,並建立一份詞彙表——也就是唯一字詞的清單,用來定義將每則評論表示為數值資料時所使用的特徵。
我們已為你載入 preprocess() 函式。它會將文字轉為小寫、進行斷詞,並移除標點符號。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
練習說明
- 使用
preprocess()函式對資料集中每一則評論做前處理。 - 在前處理後的評論上擬合
vectorizer。 - 列印輸出的詞彙表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
reviews = [
"The product is fantastic! It works like a charm.",
"I hated the product. It broke after one use.",
"Product was okay, not the best, but fine overall."
]
# Preprocess the reviews
cleaned_reviews = [____ for ____ in ____]
vectorizer = CountVectorizer()
# Fit the vectorizer
vectorizer.____
# Print the vocabulary
print(vectorizer.____)