Learn R Programming

SentimentAnalysis (version 1.3-5)

predict.SentimentDictionaryWeighted: Prediction for given dictionary

Description

Function takes a dictionary of class SentimentDictionaryWeighted with weights as input. It then applies this dictionary to textual contents in order to calculate a sentiment score.

Usage

# S3 method for SentimentDictionaryWeighted
predict(
  object,
  newdata = NULL,
  language = "english",
  weighting = function(x) tm::weightTfIdf(x, normalize = FALSE),
  ...
)

Value

data.frame with predicted sentiment scores.

Arguments

object

Dictionary of class SentimentDictionaryWeighted.

newdata

A vector of characters, a data.frame, an object of type Corpus, TermDocumentMatrix or DocumentTermMatrix .

language

Language used for preprocessing operations (default: English).

weighting

Function used for weighting of words; default is a a link to the tf-idf scheme.

...

Additional parameters passed to function for e.g. preprocessing.

See Also

SentimentDictionaryWeighted, generateDictionary and compareToResponse for default dictionary generations

Examples

Run this code
#' # Create a vector of strings
documents <- c("This is a good thing!",
               "This is a very good thing!",
               "This is okay.",
               "This is a bad thing.",
               "This is a very bad thing.")
response <- c(1, 0.5, 0, -0.5, -1)

# Generate dictionary with LASSO regularization
dictionary <- generateDictionary(documents, response)

# Compute in-sample performance
sentiment <- predict(dictionary, documents)
compareToResponse(sentiment, response)

Run the code above in your browser using DataLab