predict.SentimentDictionaryWeighted: Prediction for given dictionary

View source: R/predict.R

predict.SentimentDictionaryWeightedR Documentation

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 class 'SentimentDictionaryWeighted'
predict(
  object,
  newdata = NULL,
  language = "english",
  weighting = function(x) tm::weightTfIdf(x, normalize = FALSE),
  ...
)

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.

Value

data.frame with predicted sentiment scores.

See Also

SentimentDictionaryWeighted, generateDictionary and compareToResponse for default dictionary generations

Examples

#' # 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)

SentimentAnalysis documentation built on Aug. 24, 2023, 1:07 a.m.