Teradata R Package Function Reference | 17.00 - 17.00 - NaiveBayesPredict - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

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_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 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_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_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"))