開始使用免費開始

終極對決!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 以及對應的 AmazonProGooglePro 雙詞頻率。請使用這個資料框,找出兩個語料庫之間共同出現、差異最大的前 5 個雙詞。

本練習屬於課程

R 的 Bag-of-Words 文本探勘

檢視課程

練習說明

  • 使用 dplyr 函式從 all_tdm_df 建立 common_words
    • AmazonPro 欄位做 filter(),篩出非零值。
    • 同樣地,對 GooglePro 欄位做篩選,保留非零值。
    • 接著 mutate() 一個新欄位 diff,其值為兩個詞頻欄位的 abs(絕對)差。
  • common_words pipe 給 slice_max,建立 top5_df,依 diff 欄位取前 5 大的值。結果會印到主控台供你檢視。
  • 建立 pyramid.plot,依序傳入 top5_df$AmazonProtop5_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)
編輯並執行程式碼