開始使用免費開始

視覺化單字頻率

你已經分別計算出包含與不包含停用詞的最高頻單字,現在該把差異視覺化了。這個練習中,你會使用 matplotlib 繪製兩種情況的長條圖。

以下清單已為你預先載入:top_words_without_stopwordstop_counts_without_stopwordstop_words_with_stopwordstop_counts_with_stopwords

本練習屬於課程

Python 的 Natural Language Processing(NLP)

檢視課程

練習說明

  • 使用 plt.bar() 繪製包含停用詞的前 10 個單字頻率。
  • 使用 plt.bar() 繪製不含停用詞的前 10 個單字頻率。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

import matplotlib.pyplot as plt
# Plot the frequencies with stop words
plt.bar(____, ____)
plt.title("Top 10 word frequencies (with stop words)")
plt.xlabel("Words")
plt.ylabel("Frequency")
plt.show()

# Plot the frequencies without stop words
plt.figure()
plt.bar(____, ____)
plt.title("Top 10 word frequencies (without stop words)")
plt.xlabel("Words")
plt.ylabel("Frequency")
plt.show()
編輯並執行程式碼