การวิเคราะห์ความรู้สึกใน R
Ted Kwartler
Data Dude
เป้าหมายเริ่มต้น: ใช้ฟังก์ชัน polarity() เพื่อแบ่งส่วนย่อยของข้อความสำหรับการวิเคราะห์
pos_comments <- subset(bos_reviews$comments,
bos_reviews$polarity > 0)
neg_comments <- subset(bos_reviews$comments,
bos_reviews$polarity < 0)
pos_terms <- paste(pos_comments, collapse = " ")
neg_terms <- paste(neg_comments, collapse = " ")
เป้าหมาย: ใช้รีวิวที่จัดรูปแบบ tidy แล้วเพื่อสร้างการให้คะแนน polarity ในรูปแบบ tidy
library(tidytext)
library(dplyr)
tidy_reviews <- bos_reviews %>%
unnest_tokens(word, comments)
tidy_reviews <- tidy_reviews %>%
group_by(id) %>%
mutate(original_word_order = seq_along(word))
lexicon "bing" ใน sentiments จัดหมวดหมู่คำเป็น positive หรือ negative
library(tidytext)
library(tidyr)
library(dplyr)
bing <- sentiments %>%
filter(lexicon == "bing")
pos_neg <- tidy_reviews %>%
inner_join(bing) %>%
count(sentiment) %>%
pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>%
mutate(polarity = positive - negative)
การวิเคราะห์ความรู้สึกใน R