始める無料で始める

単語頻度の可視化

ストップワードあり・なしで最頻出の単語を計算できたので、次はその違いを可視化してみましょう。この演習では、matplotlib を使って両方のケースの棒グラフを作成します。

次のリストはあらかじめ読み込まれています:top_words_without_stopwordstop_counts_without_stopwordstop_words_with_stopwordstop_counts_with_stopwords

この演習はコースの一部です

Pythonで学ぶ自然言語処理(NLP)

コースを見る

演習の手順

  • ストップワードありの上位10件の単語頻度を、plt.bar() で可視化します。
  • ストップワードなしの上位10件の単語頻度を、plt.bar() で可視化します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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()
コードを編集して実行