終極對決!Amazon vs. Google 的正向評論
Amazon 的正向評論似乎常提到像是「good benefits」這類的雙詞,負向評論則著重在「workload」以及「work-life balance」等問題。
相較之下,Google 的正向評論會提到「great food」、「perks」、「smart people」和「fun culture」等。Google 的負向評論則討論「politics」、「getting big」、「bureaucracy」以及「middle management」。
你決定製作一張金字塔圖,將 Amazon 與 Google 的正向評論並列,方便比較兩者之間共有雙詞的差異。
我們已預先載入一個資料框 all_tdm_df,其中包含 terms 以及對應的 AmazonPro 與 GooglePro 雙詞頻率。請使用這個資料框,找出兩個語料庫之間共同出現、差異最大的前 5 個雙詞。
本練習屬於課程
R 的 Bag-of-Words 文本探勘
練習說明
- 使用
dplyr函式從all_tdm_df建立common_words。- 對
AmazonPro欄位做filter(),篩出非零值。 - 同樣地,對
GooglePro欄位做篩選,保留非零值。 - 接著
mutate()一個新欄位diff,其值為兩個詞頻欄位的abs(絕對)差。
- 對
- 將
common_wordspipe 給slice_max,建立top5_df,依diff欄位取前5大的值。結果會印到主控台供你檢視。 - 建立
pyramid.plot,依序傳入top5_df$AmazonPro、top5_df$GooglePro,最後用top5_df$terms加上標籤。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Filter to words in common and create an absolute diff column
common_words <- all_tdm_df %>%
filter(
___ != 0,
___ != 0
) %>%
___(diff = ___(___ - ___))
# Extract top 5 common bigrams
(top5_df <- common_words %>% ___(___, n = ___))
# Create the pyramid plot
pyramid.plot(top5_df$___, top5_df$___,
labels = top5_df$___, gap = 12,
top.labels = c("Amzn", "Pro Words", "Goog"),
main = "Words in Common", unit = NULL)