r - R:情绪分析包
问题描述
有谁知道为什么R中SentimentAnalysisaggregate
包中的函数参数没有对情绪分数进行分组?这是一个简单的可重现示例:analyzeSentiment
> library(SentimentAnalysis)
> documents <- c("Wow, I really like the new light sabers!",
+ "That book was excellent.",
+ "R is a fantastic language.",
+ "The service in this restaurant was miserable.",
+ "This is neither positive or negative.",
+ "The waiter forget about my dessert -- what poor service!")
> Group=factor(c(1,1,2,2,3,3))
> Test_data=data.frame(documents=documents,Group=Group,stringsAsFactors = F)
> sentiment <- analyzeSentiment(x=Test_data$documents,aggregate=Test_data$Group)
> Test_data$SentimentQDAP=sentiment$SentimentQDAP
> Test_data
documents Group SentimentQDAP
1 Wow, I really like the new light sabers! 1 0.3333333
2 That book was excellent. 1 0.5000000
3 R is a fantastic language. 2 0.5000000
4 The service in this restaurant was miserable. 2 -0.3333333
5 This is neither positive or negative. 3 0.0000000
6 The waiter forget about my dessert -- what poor service! 3 -0.4000000
这给了我以下信息:
函数analyzeSentiment 的帮助说“聚合:可以对文档进行分组的因素变量。这在加入例如同一天的新闻或移动同一作者的评论时很有帮助”。
我的问题是为什么每个组内的分数不一样?
解决方案
我检查了函数的源代码analyzeSentiment
以查看该参数会发生什么aggregate
。
有趣的是,它没有在你的代码中做任何事情的原因是因为这个参数本质上是多余的——它根本不会被使用!如果您从初始analyzeSentiment
函数开始跟踪调用堆栈,则aggregate
参数只会被传递,直到它到达情绪计算的主要中心 - analyzeSentiment.DocumentTermMatrix
. 这是计算结果的数据帧然后返回的地方,传递给的值aggregate
似乎在代码中的任何地方都没有出现。它被传入并且从未使用过。
为了向后兼容,必须是他们从未添加到包中的功能,或者是以前版本遗留下来的工件。
推荐阅读
- python-3.x - Tkinter 窗口在一次运行后自动关闭
- python-3.x - 如何提取其母亲包含特定文本的元素?
- reactjs - router5 以编程方式导航浏览器历史记录
- javascript - 使用 Javascript 避免在 firebase 中重复
- javascript - cloudinary.v2.api.delete_folder 的替代方案是什么?由于不推荐使用此方法,我现在如何删除空文件夹?
- r - 用 n 个副本替换 data.frame 中的每个观察值
- akka - 了解在上游失败时如何处理 akka 引用
- python - 对 opencv 直播流应用多重效果
- kentico - Kentico:如何通过 API 处理内容分级?
- scala - 在 Spark 中的 groupby 之后跨列收集最常见的唯一值