ขั้นตอนที่ 3: จัดระเบียบ (และทำความสะอาด) ข้อความ

การวิเคราะห์ความรู้สึกใน 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 = " ")
การวิเคราะห์ความรู้สึกใน R

จัดระเบียบเพิ่มเติม

เป้าหมาย: ใช้รีวิวที่จัดรูปแบบ 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))
การวิเคราะห์ความรู้สึกใน R

การให้คะแนน polarity แบบ tidy text

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

มาฝึกกันเถอะ!

การวิเคราะห์ความรู้สึกใน R

Preparing Video For Download...