比較 BoW 與 TF-IDF 的表徵
你是穿戴式科技公司分析團隊的一員。你的目標是協助產品經理理解新款智慧手錶的顧客回饋。你已經完成文字前處理,並建立了兩種表徵:使用 CountVectorizer() 產生的 bow_matrix,以及使用 TfidfVectorizer() 產生的 tfidf_matrix。在這個練習中,你會把兩者視覺化並進行比較,進一步了解它們如何捕捉詞彙的重要性。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Convert BoW matrix to a DataFrame
df_bow = pd.DataFrame(
____,
columns=vectorizer.____
)
# Plot the heatmap
plt.figure(figsize=(10, 6))
sns.heatmap(____, annot=True)
plt.title("BoW Scores Across Reviews")
plt.xlabel("Terms")
plt.xticks(rotation=45)
plt.ylabel("Documents")
plt.show()