開始使用免費開始

詞彙影響力與頻率分析

探索資料最簡單的方法之一就是做頻率分析。雖然並不困難,但在情感分析中,這個簡單的方法常常能帶來意外的啟發。這個練習中,你將建立長條圖。你會再次使用 mobybing 來繪製視覺化。

為了把長條由小到大排序,你會用到因子的小技巧。reorder() 能根據另一個分數變數來調整因子層級的順序。在這裡,你會用分數變數 polarity 來重新排序因子變數 term

本練習屬於課程

R 情感分析

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

moby_tidy_sentiment <- moby %>% 
  # Inner join to bing lexicon by term = word
  inner_join(bing, by = c("term" = "word")) %>% 
  # Count by term and sentiment, weighted by count
  count(___, ___, wt = ___) %>%
  # Pivot sentiment, using n as values
  pivot_wider(names_from = ___, values_from = ___, values_fill = ___) %>%
  # Mutate to add a polarity column
  mutate(polarity = ___ - ___)

# Review
moby_tidy_sentiment
編輯並執行程式碼