classify_polarity 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.

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

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.

lang

Language, "en" for English and "pt" for Brazilian Portuguese.

...

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

Timothy P. Jurka <tpjurka@ucdavis.edu> and Jodavid Ferreira <jdaf1@de.ufpe.br>

Examples

# DEFINE DOCUMENTS documents <- c("I am very happy, excited, and optimistic.", "I am very scared, annoyed, and irritated.") # CLASSIFY POLARITY