MulaiMulai sekarang secara gratis

Memvisualisasikan frekuensi kata

Setelah Anda menghitung kata-kata yang paling sering muncul dengan dan tanpa stop words, saatnya memvisualisasikan perbedaannya. Pada latihan ini, Anda akan menggunakan matplotlib untuk membuat diagram batang untuk kedua kasus tersebut.

Daftar berikut telah dimuatkan untuk Anda: top_words_without_stopwords, top_counts_without_stopwords, top_words_with_stopwords, top_counts_with_stopwords.

Latihan ini adalah bagian dari kursus

Natural Language Processing (NLP) in Python

Lihat Kursus

Petunjuk latihan

  • Gunakan plt.bar() untuk memplot 10 frekuensi kata teratas dengan stop words.
  • Gunakan plt.bar() untuk memplot 10 frekuensi kata teratas tanpa stop words.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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()
Edit dan Jalankan Kode