Teradata R Package Function Reference | 17.00 - 17.00 - SentimentEvaluator - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

Description

The EvaluateSentimentExtractor function uses test data to evaluate the precision and recall of the predictions output by the function ExtractSentiment (td_sentiment_extractor_mle). The precision and recall are affected by the model that the function td_sentiment_extractor_mle uses; therefore, if the model is changed, EvaluateSentimentExtractor must be rerun on the new predictions.

Usage

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

Arguments

object

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

object.order.column

Optional Argument.
Specifies Order By columns for "object".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

obs.column

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

sentiment.column

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

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.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_sentiment_evaluator_mle" which is a named list containing object of class "tbl_teradata".
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 object(s) of class "tbl_teradata".
    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 td_sentiment_trainer_mle() function.
    td_sentiment_trainer_out <- td_sentiment_trainer_mle(data = sentiment_train,
                                                         text.column = "review",
                                                         sentiment.column = "category",
                                                         model.file = "sentimentmodel1.bin"
                                                         )
                                                    
    # Use the td_sentiment_extractor_mle() 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 tbl_teradata ('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"
                                                    )