开始使用免费开始使用

可视化词频

现在您已经分别计算了包含与不包含停用词时的高频词,是时候把差异可视化了。本练习中,您将使用 matplotlib 绘制两种情况的条形图。

以下列表已为您预先加载:top_words_without_stopwordstop_counts_without_stopwordstop_words_with_stopwordstop_counts_with_stopwords

本练习是课程的一部分

Python 中的自然语言处理(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()
编辑并运行代码