Teradata R Package Function Reference - NaiveBayesPredict - 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 NaiveBayesPredict function uses the model output by the NaiveBayesReduce (td_naivebayes_mle) function to predict the outcomes for a test set of data.
Note: This function is only available when tdplyr is connected to Vantage 1.1 or later versions.

Usage

  td_naivebayes_predict_mle (
      formula = NULL,
      modeldata = NULL,
      newdata = NULL,
      id.col = NULL,
      output.prob = FALSE,
      responses = NULL,
      terms = NULL,
      newdata.sequence.column = NULL,
      modeldata.sequence.column = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL
  )

Arguments

formula

Optional Argument.
Required when the argument "modeldata" is not an object of td_naivebayes_mle class.
Specifies a string consisting of "formula" which was used to fit in model data. Only basic formula of the (col1 ~ col2 + col3 +...) form is supported and all variables must be from the same tbl_teradata object. The response should be column of type numeric or logical.

modeldata

Required Argument.
Specifies the tbl_teradata object that contains the model data.
This argument can accept either tbl_teradata object or an object of td_naivebayes_mle class.

modeldata.order.column

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

newdata

Required Argument.
Specifies the tbl_teradata object defining the input test data.

newdata.order.column

Optional 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)

id.col

Required Argument.
Specifies the name of the column that contains the ID that uniquely identifies the test input data.
Types: character

output.prob

Optional Argument.
Specifies whether to output probabilities.
Default Value: FALSE
Types: logical

responses

Optional Argument.
Specifies a list of responses to output.
Note: This argument is required when connected to Vantage prior to Vantage 1.1.1.
Types: character OR vector of characters

terms

Optional Argument.
Specifies the names of input tbl_teradata 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)

modeldata.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "modeldata". 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_naivebayes_predict_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("naivebayes_predict_example", "nb_iris_input_test", "nb_iris_input_train")
    
    # Create remote tibble objects.
    nb_iris_input_train <- tbl(con, "nb_iris_input_train")
    nb_iris_input_test <- tbl(con, "nb_iris_input_test")
    
    # Example 1 - Using NaiveBayes model in td_naivebayes_predict_mle function.
    # Generate NaiveBayes model based on train data "nb_iris_input_train".
    naivebayes_train1 <- td_naivebayes_mle(formula=(species ~ petal_length + sepal_width + petal_width + sepal_length), 
                                          data=nb_iris_input_train)
                                          
    # Use the generated model to predict the 'species' on the test data nb_iris_input_test.
    td_naivebayes_predict_mle_out1 <- td_naivebayes_predict_mle(modeldata = naivebayes_train1,
                                                               newdata = nb_iris_input_test,
                                                               id.col = "id",
                                                               output.prob = FALSE,
                                                               responses = c("virginica", "setosa", "versicolor")
                                                               )
                                                               
    # Example 2 - Using NaiveBayes model's tbl_teradata object in td_naivebayes_predict_mle function.
    # Use tbl_teradata object of the model generated (in Example 1) to predict the 'species' on 
    # the test data nb_iris_input_test.
    # The 'formula' argument is required when 'modeldata' takes tbl_teradata object instead of
    # td_naivebayes_mle object.
    td_naivebayes_predict_mle_out2 <- td_naivebayes_predict_mle(modeldata = naivebayes_train1$result,
                                                               newdata = nb_iris_input_test,
                                                               id.col = "id",
                                                               output.prob = FALSE,
                                                               responses = c("virginica", "setosa", "versicolor"),
                                                               formula=(species ~ petal_length + sepal_width + petal_width + sepal_length)
                                                               )