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

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

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

trust

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

negative

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

positive

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

anticipation

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

best_fit

The most likely sentiment category (e.g. anger, disgust, fear, joy, sadness, surprise) 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 EMOTIONS classify_emotion(documents,algorithm="bayes",verbose=TRUE, lang = "en")
#> Warning: custom functions are ignored
#> [1] "DOCUMENT 1" #> [1] "WORD: excited CAT: joy SCORE: 7.04664727784876" #> [1] "WORD: excited CAT: surprise SCORE: 6.42162226780652" #> [1] "WORD: excited CAT: trust SCORE: 7.11558212618445" #> [1] "WORD: excited CAT: positive SCORE: 7.74586822979227" #> [1] "WORD: excited CAT: anticipation SCORE: 6.73221070646721" #> [1] "WORD: happy CAT: joy SCORE: 7.04664727784876" #> [1] "WORD: happy CAT: trust SCORE: 7.11558212618445" #> [1] "WORD: happy CAT: positive SCORE: 7.74586822979227" #> [1] "WORD: happy CAT: anticipation SCORE: 6.73221070646721" #> [1] "DOCUMENT 2" #> [1] "WORD: annoyed CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: irritated CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: scared CAT: fear SCORE: 7.39326309476384"
#> ANGER DISGUST FEAR #> [1,] "2.29461377373361" "2.61429857727156" "2.23044441521636" #> [2,] "16.9528012462268" "2.61429857727156" "9.6237075099802" #> JOY SADNESS SURPRISE TRUST #> [1,] "16.670354787829" "2.3844925362004" "9.6237075099802" "16.7392896361647" #> [2,] "2.57706023213145" "2.3844925362004" "3.20208524217368" "2.50812538379575" #> POSITIVE NEGATIVE ANTICIPATION BEST_FIT #> [1,] "17.3695757397725" "1.51478335400486" "16.3559182164474" "positive" #> [2,] "1.87783928018793" "1.51478335400486" "2.89149680351299" "anger"
# pt-BR documentos <- c("Estou muito feliz, animado e otimista.", "Estou muito assustado e irritado.") # CLASSIFY EMOTIONS classify_emotion(documentos,algorithm="bayes",verbose=TRUE, lang = "pt")
#> Warning: custom functions are ignored
#> [1] "DOCUMENT 1" #> [1] "WORD: animado CAT: disgust SCORE: 7.00940893270864" #> [1] "WORD: animado CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: animado CAT: surprise SCORE: 6.42162226780652" #> [1] "WORD: animado CAT: trust SCORE: 7.11558212618445" #> [1] "WORD: animado CAT: positive SCORE: 7.74586822979227" #> [1] "WORD: animado CAT: anticipation SCORE: 6.73221070646721" #> [1] "WORD: estou CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: estou CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: estou CAT: negative SCORE: 8.10892415597534" #> [1] "WORD: feliz CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: feliz CAT: disgust SCORE: 7.00940893270864" #> [1] "WORD: feliz CAT: joy SCORE: 7.04664727784876" #> [1] "WORD: feliz CAT: negative SCORE: 8.10892415597534" #> [1] "WORD: muito CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: muito CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: otimista CAT: positive SCORE: 7.74586822979227" #> [1] "WORD: otimista CAT: anticipation SCORE: 6.73221070646721" #> [1] "DOCUMENT 2" #> [1] "WORD: estou CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: estou CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: estou CAT: negative SCORE: 8.10892415597534" #> [1] "WORD: muito CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: muito CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: assustado CAT: fear SCORE: 7.39326309476384" #> [1] "WORD: assustado CAT: joy SCORE: 7.04664727784876" #> [1] "WORD: assustado CAT: sadness SCORE: 7.23921497377981" #> [1] "WORD: assustado CAT: negative SCORE: 8.10892415597534" #> [1] "WORD: assustado CAT: anticipation SCORE: 6.73221070646721" #> [1] "WORD: irritado CAT: anger SCORE: 7.32909373624659" #> [1] "WORD: irritado CAT: joy SCORE: 7.04664727784876" #> [1] "WORD: irritado CAT: sadness SCORE: 7.23921497377981"
#> RAIVA DESGOSTO MEDO #> [1,] "24.2826222792756" "16.633843739491" "24.4109609963101" #> [2,] "24.2826222792756" "2.61502587407376" "24.4109609963101" #> ALEGRIA TRISTEZA SURPRESA #> [1,] "9.6244348067824" "2.3852198330026" "9.6244348067824" #> [2,] "16.6710820846312" "16.8636497805622" "3.20281253897588" #> CONFIANÇA POSITIVA NEGATIVA #> [1,] "9.6244348067824" "17.3703030365747" "17.7333589627577" #> [2,] "2.50885268059795" "1.87856657699013" "17.7333589627577" #> ANTECIPAÇÃO BEST_FIT #> [1,] "16.3566455132496" "medo" #> [2,] "9.6244348067824" "medo"