Visualizzare le frequenze delle parole
Ora che hai calcolato le parole più frequenti con e senza stop word, è il momento di visualizzare le differenze. In questo esercizio userai matplotlib per tracciare grafici a barre per entrambi i casi.
Le seguenti liste sono già state caricate per te: top_words_without_stopwords, top_counts_without_stopwords, top_words_with_stopwords, top_counts_with_stopwords.
Questo esercizio fa parte del corso
Natural Language Processing (NLP) in Python
Istruzioni dell'esercizio
- Usa
plt.bar()per tracciare le 10 frequenze di parole più alte con le stop word. - Usa
plt.bar()per tracciare le 10 frequenze di parole più alte senza le stop word.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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()