Sentiment analysis using R [closed]

妖精的绣舞 提交于 2019-11-27 09:22:09

问题


Are there any R packages that focus on sentiment analysis? I have a small survey where users can write a comment about their experience of using a web-tool. I ask for a numerical ranking, and there is the option of including a comment.

I am wondering what the best way of assessing the positiveness or negativeness of the comment is. I would like to be able to compare it to the numerical ranking that the user provides, using R.


回答1:


And there is this package:

sentiment: Tools for Sentiment Analysis

sentiment is an R package with tools for sentiment analysis including bayesian classifiers for positivity/negativity and emotion classification.

Update 14 Dec 2012: it has been removed to the archive...

Update 15 Mar 2013: the qdap package has a polarity function, based on Jeffery Breen's work




回答2:


Here's the work I've done on sentiment analysis in R.

The code is, by no means, polished or well-packaged, but I posted it on Github with basic documentation. I used the ViralHeat sentiment API, which just returns JSON, so the actual function to do the sentiment analysis is pretty trivial (see code here).

Feel free to contact me if you're having trouble using it. And note that you'll need to register for an API key with ViralHeat before you'll be able to use it. If you're finding the quotas too restrictive, I had contacted them and they were happy to give me a ton more queries for a few months while I played around with the API.




回答3:


For step by step guide to use 1) Viral Heat API 2) Jeffrey Breen's approach 3) Using Sentiment Package, check out this link: https://sites.google.com/site/miningtwitter/questions/sentiment




回答4:


I've tried to reorganize and provide a cohesive sentiment analysis package here. SentR includes word stemming and preprocessing and provides access to the ViralHeat API, a default aggregating function as well as a more advanced Naive Bayes method.

Installing is relatively simple:

install.packages('devtools')
require('devtools')
install_github('mananshah99/sentR')
require('sentR')

And a simple classification example:

# Create small vectors for happy and sad words (useful in aggregate(...) function)
positive <- c('happy', 'well-off', 'good', 'happiness')
negative <- c('sad', 'bad', 'miserable', 'terrible')

# Words to test sentiment
test <- c('I am a very happy person.', 'I am a very sad person', 
'I’ve always understood happiness to be appreciation. There is no greater happiness than appreciation for what one has- both physically and in the way of relationships and ideologies. The unhappy seek that which they do not have and can not fully appreciate the things around them. I don’t expect much from life. I don’t need a high paying job, a big house or fancy cars. I simply wish to be able to live my life appreciating everything around me. 
')

# 1. Simple Summation
out <- classify.aggregate(test, positive, negative)
out

# 2. Naive Bayes
out <- classify.naivebayes(test)
out

Which provides the following output:

  score
1     1
2    -1
3     2

     POS                NEG                 POS/NEG             SENT      
[1,] "9.47547003995745" "0.445453222112551" "21.2715265477714"  "positive"
[2,] "1.03127774142571" "9.47547003995745"  "0.108836578774127" "negative"
[3,] "67.1985217685598" "35.1792261323723"  "1.9101762362738"   "positive"

Please feel free to contribute :) Hope that helps!




回答5:


You can still use the sentiment package. Install it following the script below.

You may need R 3.x.

require(devtools)
install_url("http://cran.r-project.org/src/contrib/Archive/sentiment/sentiment_0.2.tar.gz")
require(sentiment)
ls("package:sentiment")


来源:https://stackoverflow.com/questions/10233087/sentiment-analysis-using-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!