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

Teradata® Package for R Function Reference

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

NaiveBayesTextClassifierTrainer

Description

The td_naivebayes_textclassifier_trainer_sqle() function calculates the conditional probabilities for token-category pairs, the prior probabilities, and the missing token probabilities for all categories. The trainer function trains the model with the probability values, and the predict function uses the values to classify documents into categories.

Usage

  td_naivebayes_textclassifier_trainer_sqle (
      data = NULL,
      doc.category.column = NULL,
      token.column = NULL,
      doc.id.column = NULL,
      model.type = "MULTINOMIAL",
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

doc.category.column

Required Argument.
Specifies the name of the input data column that contains the document category.
Types: character

token.column

Required Argument.
Specifies the name of the input data column that contains the tokens.
Types: character

doc.id.column

Optional Argument.
Specifies the name of the input data column that contains the document identifier.
Types: character

model.type

Optional Argument.
Specifies the model type of the text classifier.
Default Value: "MULTINOMIAL"
Permitted Values: "MULTINOMIAL", "BERNOULLI"
Types: character

...

Specifies the generic keyword arguments SQLE functions accept. Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the
function in a table or not. When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the
function in a volatile table or not. When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.hash.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.order.column" accepts character or vector of character (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_naivebayes_textclassifier_trainer_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):

  1. result

  2. model.data

Examples

  
    
    # Get the current context/connection.
    con <- td_get_context()$connection
    
    # Load the example data.
    loadExampleData("textparser_example", "complaints", "stop_words")

    # Create tbl_teradata object.
    complaints <- tbl(con, "complaints")
    stop_words <- tbl(con, "stop_words")

    # Check the list of available analytic functions.
    display_analytic_functions()

    # Tokenize the "text_column" and accumulate result by "doc_id" and "category".
    complaints_tokenized <- td_text_parser_sqle(
                              data=complaints,
                              text.column="text_data",
                              object=stop_words,
                              remove.stopwords=TRUE,
                              accumulate=c("doc_id", "category"))
    
    # Example 1 : Calculate the conditional probabilities for token-category pairs.
    NaiveBayesTextClassifierTrainer_out <- td_naivebayes_textclassifier_trainer_sqle(
                                            data=complaints_tokenized$result,
                                            token.column="token",
                                            doc.category.column="category")
    
    # Print the result tbl_teradata objects.
    print(NaiveBayesTextClassifierTrainer_out$result)
    print(NaiveBayesTextClassifierTrainer_out$model.data)