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 function to predict the outcomes for a test set of data.

Usage

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

Arguments

modeldata

Required Argument.
Specifies the name of the object that contains the naivebayes model which is the output of function td_naivebayes_mle. For td_naivebayes_predict_sqle, this can also be the tibble containing the model table of naivebayes model.

newdata

Required Argument.
Specifies the table defining the input test data.

id.col

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

responses

Required Argument.
Specifies the list of Responses to output.

formula

Required Argument.
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 Teradata tbl object. The response should be column of type real, numeric, integer or boolean. If modeldata argument is of class td_naivebayes_mle then formula argument can be omitted

Value

Function returns an object of class "td_naivebayes_predict_sqle" 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_train","nb_iris_input_test")
    
    # 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 -
    #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"))