predict.SentimentDictionaryWeighted {SentimentAnalysis} | R 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 |
newdata |
A vector of characters, a |
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)
[Package SentimentAnalysis version 1.3-5 Index]