Teradata Package for R Function Reference | 17.20 - NaiveBayesPredict - 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
ft:locale
en-US
ft:lastEdition
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
lifecycle
latest
Product Category
Teradata Vantage

NaiveBayesPredict

Description

The NaiveBayesPredict function uses the model output by the NaiveBayesReduce td_naivebayes_mle function to predict the outcomes for a test dataset.

Usage

  td_naivebayes_predict_mle_sqle (
      modeldata = NULL,
      newdata = NULL,
      id.col = NULL,
      responses = NULL,
      formula = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL
  )
## S3 method for class 'td_naivebayes_mle'
predict(
      modeldata = NULL,
      newdata = NULL,
      id.col = NULL,
      responses = NULL,
      formula = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL)

Arguments

modeldata

Optional Argument.
Specifies the model tbl_teradata generated by td_naivebayes_mle.
This argument can accept either a tbl_teradata 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 containing 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

responses

Required Argument.
Specifies the list of responses to output.
Types:character OR vector of Strings (characters)

formula

Required Argument. Required when the "modeldata" is a tbl_teradata.
An object of class "formula". Specifies the model to be fitted. 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.

Value

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

Examples

  
    # Get the current context/connection.
    con <- td_get_context()$connection

    # Load example data.
    loadExampleData("naivebayes_predict_example", "nb_iris_input_train","nb_iris_input_test")

    # Create object(s) of class "tbl_teradata".
    nb_iris_input_train <- tbl(con, "nb_iris_input_train")
    nb_iris_input_test <- tbl(con, "nb_iris_input_test")

    # Example 1 -
    # Run the train function
    naivebayes_train <- td_naivebayes_mle(formula = (species ~ petal_length + sepal_width +
                                                     petal_width + sepal_length),
                                          data = nb_iris_input_train)

    # Generate prediction using output of train function
    naivebayes_predict_result1 <- td_naivebayes_predict_mle_sqle(
                                    newdata=nb_iris_input_test,
                                    formula = (species ~ petal_length + sepal_width + petal_width +
                                               sepal_length),
                                    modeldata = naivebayes_train,
                                    id.col = "id",
                                    responses = c("virginica","setosa","versicolor")
                                  )

    # Alternatively use S3 predict method to find the predictions.
    naivebayes_predict_result2 <- predict(naivebayes_train,
                                          newdata = nb_iris_input_test,
                                          id.col = "id",
                                          responses = c("virginica","setosa","versicolor"))