Análise de Sentimentos em R
Ted Kwartler
Data Dude
Objetivo inicial: usar a função polarity() para definir subseções do texto para análise.
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 = " ")
Objetivo: usar as avaliações de aluguel em formato tidy para criar a pontuação de polaridade também em formato 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))
Lembre que o léxico "bing" em sentiments classifica palavras como positivas ou negativas.
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)
Análise de Sentimentos em R