電影評論的文字雲
你一直在使用「電影評論」資料集。你已經探索了評論的分佈,並看過最長與最短的評論長度。不過,正面與負面評論各自都在談些什麼?
在這個練習中,你會練習為前 100 筆正面評論建立文字雲。
哪些字詞最常跳出來?對你而言合理嗎?
字串 descriptions 已經幫你建立好,內容是將前 100 筆正面評論的描述串接而成。電影情境專用的停用字(非常常見但資訊量低、我們想從圖中排除的詞,例如 the、a/an、and)已提供為 my_stopwords。回想一下,interpolation 參數可以讓文字雲看起來更平滑。
本練習屬於課程
Python 情感分析
練習說明
- 從相應的套件匯入 wordcloud 函式。
- 對字串
descriptions套用文字雲函式。將背景色設為 'white',並調整stopwords參數。 - 建立文字雲影像。
- 最後,別忘了把影像顯示出來。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the word cloud function
____
# Create and generate a word cloud image
my_cloud = ____(____='white', ____=my_stopwords).____(descriptions)
# Display the generated wordcloud image
plt.____(____, interpolation='bilinear')
plt.axis("off")
# Don't forget to show the final image
____