Teradata R Package Function Reference - SentimentEvaluator - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The SentimentEvaluator function uses test data to evaluate the precision and recall of the predictions output by the function SentimentExtractor.

Usage

  td_sentiment_evaluator_mle (
      object = NULL,
      obs.column = NULL,
      sentiment.column = NULL,
      object.sequence.column = NULL
  )

Arguments

object

Required Argument.
Specifies the input tbl_teradata with a text column which contains input text.

obs.column

Required Argument.
Specifies the name of the input column with the observed sentiment (POS, NEG or NEU).

sentiment.column

Required Argument.
Specifies the name of the input column with the predicted sentiment (POS, NEG or NEU).

object.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "object". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_sentiment_evaluator_mle" which is a named list containing Teradata tbl object.
Named list member can be referenced directly with the "$" operator using name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("sentimenttrainer_example", "sentiment_train")
    loadExampleData("sentimentextractor_example", "sentiment_extract_input", "sentiment_word")
    
    # Create remote tibble objects.
    sentiment_train <- tbl(con, "sentiment_train")
    sentiment_extract_input <- tbl(con, "sentiment_extract_input")
    sentiment_word <- tbl(con, "sentiment_word")
    
    # Example 1 -This example uses the dictionary model file 'default_sentiment_lexicon.txt'
    td_sentiment_extractor_out1 <- td_sentiment_extractor_mle(object = "dictionary",
                                                         newdata = sentiment_extract_input,
                                                         text.column = "review",
                                                         accumulate = c("category")
                                                         )
    td_sent_eval_out1 <- td_sentiment_evaluator_mle(object=td_sentiment_extractor_out1$result,
                                                obs.column='category',
                                                sentiment.column='out_polarity'
                                               )
                                                
    # Example 2 - This example uses the classification model file 
    # 'default_sentiment_classification_model.bin'
    td_sentiment_extractor_out2 <- td_sentiment_extractor_mle(object = "classification:default_sentiment_classification_model.bin",
                                                         newdata = sentiment_extract_input,
                                                         text.column = "review",
                                                         accumulate = c("category")
                                                         )
    td_sent_eval_out2 <- td_sentiment_evaluator_mle(object=td_sentiment_extractor_out2$result,
                                                obs.column='category',
                                                sentiment.column='out_polarity'
                                               )
                        										  
    # Example 3 - This example uses classification model file output by 
    # the SentimentTrainer function
    td_sentiment_trainer_out <- td_sentiment_trainer_mle(data = sentiment_train,
                                                     text.column = "review",
                                                     sentiment.column = "category",
                                                     model.file = "sentimentmodel1.bin"
                                                    )
    # Use the sentiment extractor function to extract sentiment of each input document
    td_sentiment_extractor_out3 <- td_sentiment_extractor_mle(object = "classification:sentimentmodel1.bin",
                                                         newdata = sentiment_extract_input,
                                                         text.column = "review",
                                                         accumulate = c("category")
                                                        )
    td_sent_eval_out3 <- td_sentiment_evaluator_mle(object=td_sentiment_extractor_out3$result,
                                                obs.column="category",
                                                sentiment.column="out_polarity"
                                               )
    
    # Example 4 - This example uses a dictionary table ('sentiment_word') 
    # instead of model file
    td_sentiment_extractor_out4 <- td_sentiment_extractor_mle(newdata = sentiment_extract_input,
                                                         dict.data = sentiment_word,
                                                         text.column = "review",
                                                         accumulate = c("category")
                                                         )
    td_sent_eval_out4 <- td_sentiment_evaluator_mle(object=td_sentiment_extractor_out4$result,
                                                obs.column="category",
                                                sentiment.column="out_polarity"
                                               )