classify_polarity: classifies the polarity (e.g. positive or negative) of a set...

Description Usage Arguments Value Author(s) Examples

Description

Classifies the polarity (e.g. positive or negative) of a set of texts using a naive Bayes classifier trained on Janyce Wiebe's subjectivity lexicon.

Usage

1
2
classify_polarity(textColumns,algorithm="bayes",pstrong=0.5,pweak=1.0,
prior=1.0,verbose=FALSE,...)

Arguments

textColumns

A data.frame of text documents listed one per row.

algorithm

A string indicating whether to use the naive bayes algorithm or a simple voter algorithm.

pstrong

A numeric specifying the probability that a strongly subjective term appears in the given text.

pweak

A numeric specifying the probability that a weakly subjective term appears in the given text.

prior

a numeric specifying the prior probability to use for the naive Bayes classifier.

verbose

A logical specifying whether to print detailed output regarding the classification process.

...

Additional parameters to be passed into the create_matrix function.

Value

Returns an object of class data.frame with four columns and one row for each document.

pos

The absolute log likelihood of the document expressing a positive sentiment.

neg

The absolute log likelihood of the document expressing a negative sentiment.

pos/neg

The ratio of absolute log likelihoods between positive and negative sentiment scores. A score of 1 indicates a neutral sentiment, less than 1 indicates a negative sentiment, and greater than 1 indicates a positive sentiment.

best_fit

The most likely sentiment category (e.g. positive, negative, neutral) for the given text.

Author(s)

Timothy P. Jurka <tpjurka@ucdavis.edu>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# LOAD LIBRARY
library(sentiment)

# DEFINE DOCUMENTS
documents <- c("I am very happy, excited, and optimistic.",
				"I am very scared, annoyed, and irritated.",
				"Iraq's political crisis entered its second week one step closer to the potential 
				dissolution of the government, with a call for elections by a vital coalition partner 
				and a suicide attack that extended the spate of violence that has followed the withdrawal 
				of U.S. troops.",
				"With nightfall approaching, Los Angeles authorities are urging residents to keep their
				outdoor lights on as police and fire officials try to catch the person or people responsible 
				for nearly 40 arson fires in the last three days.")
				
# CLASSIFY POLARITY
classify_polarity(documents,algorithm="bayes",verbose=TRUE)

abhy/sentiment documentation built on May 10, 2019, 4:10 a.m.