classify_emotion: classifies the emotion (e.g. anger, disgust, fear, joy,...

Description Usage Arguments Value Author(s) Examples

Description

Classifies the emotion (e.g. anger, disgust, fear, joy, sadness, surprise) of a set of texts using a naive Bayes classifier trained on Carlo Strapparava and Alessandro Valitutti's emotions lexicon.

Usage

1
classify_emotion(textColumns,algorithm="bayes",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.

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 seven columns and one row for each document.

anger

The absolute log likelihood of the document expressing an angry sentiment.

disgust

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

fear

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

joy

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

sadness

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

surprise

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

best_fit

The most likely sentiment category (e.g. anger, disgust, fear, joy, sadness, surprise) 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
# 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.")

# CLASSIFY EMOTIONS
classify_emotion(documents,algorithm="bayes",verbose=TRUE)

JRmolina2020/sentiment documentation built on June 1, 2019, 3:54 a.m.