Teradata R Package Function Reference - TextClassifier - 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 TextClassifier function classifies input text, using a model output by td_text_classifier_trainer_mle function.

Usage

  td_text_classifier_mle (
      model.file = NULL,
      newdata = NULL,
      text.column = NULL,
      accumulate = NULL,
      newdata.sequence.column = NULL,
      newdata.order.column = NULL
  )

Arguments

model.file

Required Argument.
Specifies the model installed in the Vantage using the td_text_classifier_trainer_mle function.
Types: character

newdata

Required Argument.
Specifies the name of the tbl_teradata that contains the text to be classified.

newdata.order.column

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

text.column

Required Argument.
Specifies the column of the input tbl_teradata that contains the text to be used for predicting the class.
Types: character

accumulate

Optional Argument.
Specifies the names of the input columns to copy to the output table.
Types: character OR vector of Strings (character)

newdata.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "newdata". 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_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")
    
    # Generate model file using td_text_classifier_trainer_mle function.
    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')
    
    # Example 1 - This example uses model file "knn.bin" generated by
    # td_text_classifier_trainer_mle function to classify the input text.
    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')