เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การแสดงภาพความถี่ของคำ

เมื่อคำนวณคำที่พบบ่อยที่สุดทั้งแบบมีและไม่มี stop words แล้ว ถึงเวลานำผลลัพธ์มาแสดงเป็นภาพเพื่อเปรียบเทียบความแตกต่าง ในแบบฝึกหัดนี้ จะใช้ matplotlib สร้างกราฟแท่งสำหรับทั้งสองกรณี

รายการต่อไปนี้ได้รับการโหลดไว้ให้แล้ว: top_words_without_stopwords, top_counts_without_stopwords, top_words_with_stopwords, top_counts_with_stopwords

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใช้ plt.bar() พล็อตความถี่ของ 10 คำที่พบบ่อยที่สุดแบบมี stop words
  • ใช้ plt.bar() พล็อตความถี่ของ 10 คำที่พบบ่อยที่สุดแบบไม่มี stop words

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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()
แก้ไขและรันโค้ด