Teradata R Package Function Reference - 16.20 - TextClassifierEvaluator - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The TextClassifierEvaluator function evaluates the precision, recall, and F-measure of the trained model output by the TextClassifier (td_text_classifier_mle) function.

Usage

  td_text_classifier_evaluator_mle (
      object = NULL,
      obs.column = NULL,
      predict.column = NULL,
      object.sequence.column = NULL,
      object.order.column = NULL
  )

Arguments

object

Required Argument.
Specifies the name of the tbl_teradata containing the model data from the TextClassifier (td_text_classifier_mle) function. This argument can accept either tbl_teradata object or an object of td_text_classifier_mle class.

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 that contains the expected (correct) category.
Types: character

predict.column

Required Argument.
Specifies the name of the input column that contains the predicted category (assigned by the td_text_classifier_mle function).
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_text_classifier_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("text_classifier_trainer_example", "texttrainer_input")
    loadExampleData("text_classifier_example", "textclassifier_input")
    
    # Create remote tibble objects.
    texttrainer_input <- tbl(con, "texttrainer_input")
    textclassifier_input <- tbl(con, "textclassifier_input")
    
    # The model file "knn.bin" generated by "td_text_classifier_trainer_mle" 
    # function is used by "td_text_classifier_mle" to classify the input text.
    td_text_classifier_trainer_mle(data=texttrainer_input,
                                   text.column='content',
                                   category.column='category',
                                   classifier.type='knn',
                                   model.file='knn.bin',
                                   classifier.parameters='compress:0.9',
                                   nlp.parameters=c('useStem:true','stopwordsFile:stopwords.txt'),
                                   feature.selection='DF:[0.1:0.99]',
                                   data.sequence.column='id')
    
    td_text_classifier_out <- td_text_classifier_mle(newdata=textclassifier_input,
                                                     newdata.order.column='id',
                                                     text.column='content',
                                                     accumulate=c('id','category'),
                                                     model.file='knn.bin',
                                                     newdata.sequence.column='id')
    
    # Example 1 - This example evaluates the precision, recall, and F-measure
    # of the model output generated by "td_text_classifier_mle" function.
    td_text_classifier_evaluator_out <- td_text_classifier_evaluator_mle (object = td_text_classifier_out,
                                                                          obs.column = 'category',
                                                                          predict.column = 'out_category',
                                                                          object.sequence.column = 'id',
                                                                          object.order.column = 'id')