Ven*_*a20 6 r sentiment-analysis shiny qdap
我使用qdap包来确定特定应用程序的每个评论评论的情绪.我从CSV文件中读取了评论评论,并将其传递给qdap的极性函数.一切正常,我得到所有评论评论的极性,但问题是计算所有句子的极性需要7-8秒(CSV文件中存在的句子总数是779).我在下面粘贴我的代码.
temp_csv <- filePath()
attach(temp_csv)
text_data <- temp_csv[,c('Content')]
print(Sys.time())
polterms <- list(neg=c('wtf'))
POLKEY <- sentiment_frame(positives=c(positive.words),negatives=c(polterms[[1]],negative.words))
polarity <- polarity(sentences, polarity.frame = POLKEY)
print(Sys.time())
Run Code Online (Sandbox Code Playgroud)
所用时间如下:
[1]"2016-04-12 16:43:01 IST"
[1]"2016-04-12 16:43:09 IST"
如果我做错了什么,有人可以告诉我吗?如何提高性能?
Tyl*_*ker 12
我是qdap的作者.该polarity
功能专为更小的数据集而设计.随着我的角色转移,我开始使用更大的数据集.我需要快速而准确(这两件事情彼此相反),并且已经开发了一个脱离包装sentimentr.该算法经过优化,比qdap的极性更快,更准确.
现在,你有5个基于字典(或基于训练的算法)接近情绪检测.每个都有它的缺点( - )和加号(+),在某些情况下很有用.
我在下面的代码中显示了上面前4个选项的样本数据的时间测试.
我使用pacman,因为它允许读者只运行代码; 虽然你可以用install.packages
&来代替library
.
if (!require("pacman")) install.packages("pacman")
pacman::p_load(qdap, syuzhet, dplyr)
pacman::p_load_current_gh(c("trinker/stansent", "trinker/sentimentr"))
pres_debates2012 #nrow = 2912
tic <- function (pos = 1, envir = as.environment(pos)){
assign(".tic", Sys.time(), pos = pos, envir = envir)
Sys.time()
}
toc <- function (pos = 1, envir = as.environment(pos)) {
difftime(Sys.time(), get(".tic", , pos = pos, envir = envir))
}
id <- 1:2912
Run Code Online (Sandbox Code Playgroud)
## qdap
tic()
qdap_sent <- pres_debates2012 %>%
with(qdap::polarity(dialogue, id))
toc() # Time difference of 18.14443 secs
## sentimentr
tic()
sentimentr_sent <- pres_debates2012 %>%
with(sentiment(dialogue, id))
toc() # Time difference of 1.705685 secs
## syuzhet
tic()
syuzhet_sent <- pres_debates2012 %>%
with(get_sentiment(dialogue, method="bing"))
toc() # Time difference of 1.183647 secs
## stanford
tic()
stanford_sent <- pres_debates2012 %>%
with(sentiment_stanford(dialogue))
toc() # Time difference of 6.724482 mins
Run Code Online (Sandbox Code Playgroud)
有关时间和准确性的更多信息,请参阅我的sentimentr README.md,如果它有用,请在回购中加注星标.下面的viz从README中捕获了一个测试: