Description
The NaiveBayesPredict function uses the model output by the
NaiveBayes (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. |
modeldata |
Required Argument. |
modeldata.order.column |
Optional Argument. |
newdata |
Required Argument. |
newdata.order.column |
Optional Argument. |
id.col |
Required Argument. |
output.prob |
Optional Argument. |
responses |
Optional Argument. |
terms |
Optional Argument. |
newdata.sequence.column |
Optional Argument. |
modeldata.sequence.column |
Optional Argument. |
Value
Function returns an object of class "td_naivebayes_predict_mle" which
is a named list containing object of class "tbl_teradata".
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 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 - 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)
)