시작하기무료로 시작하기

단어 빈도 시각화하기

불용어를 포함한 경우와 제외한 경우의 최빈 단어를 계산했으니, 이제 그 차이를 시각화해 볼 차례예요. 이 연습 문제에서는 matplotlib을 사용해 두 경우 모두 막대 그래프를 그려 보겠습니다.

다음 리스트가 미리 로드되어 있어요: top_words_without_stopwords, top_counts_without_stopwords, top_words_with_stopwords, top_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()
코드 편집 및 실행