Teradata R Package Function Reference - 16.20 - DecisionForestPredict - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The Decision Forest Predict (td_decision_forest_predict_mle) function uses the model generated by the Decision Forest (td_decision_forest_mle) function to generate predictions on a response variable 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_decision_forest_predict_mle (
      object = NULL,
      newdata = NULL,
      id.column = NULL,
      detailed = FALSE,
      terms = NULL,
      output.response.probdist = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL,
      newdata.order.column = NULL,
      object.order.column = NULL
  )

Arguments

object

Required Argument.
Specifies the tbl_teradata object or the Decision Forest (td_decision_forest_mle) model object with contains the model information.

object.order.column

Optional Argument.
Specifies Order By columns for object.
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 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.column

Required Argument.
Specifies a column containing a unique identifier for each test point in the test set.
Types: character

detailed

Optional Argument.
Specifies whether to output detailed information about the forest trees; that is, the decision tree and the specific tree information, including task index and tree index for each tree.
Default Value: FALSE
Types: logical

terms

Optional Argument.
Specifies the names of the input columns to copy to the output table.
Types: character OR vector of Strings (character)

output.response.probdist

Optional Argument.
Specifies whether to output probabilities.
Note: "output.response.probdist" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later versions.
Default Value: FALSE
Types: logical

output.responses

Optional Argument.
Specifies responses in input tbl_teradata.
Note:

  1. The argument "output.response.probdist" must be set to TRUE to use this argument.

  2. "output.responses" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later versions.

Default Value: NULL
Types: character OR vector of characters

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)

object.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "object". 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_decision_forest_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("decisionforestpredict_example", "housing_test", "housing_train")
    
    # Create remote tibble objects.
    housing_train <- tbl(con, "housing_train")
    housing_test <- tbl(con, "housing_test")
    
    # Example 1 - Using model object generated by td_decision_forest_mle.
    # Generate DecisionForest model based on train data "housing_train".
    formula <- (homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl)
    decision_forest_model <- td_decision_forest_mle(data=housing_train,
                                                    formula = formula,
                                                    tree.type="classification",
                                                    ntree=50,
                                                    tree.size=100,
                                                    nodesize=1,
                                                    variance=0,
                                                    max.depth=12,
                                                    maxnum.categorical=20,
                                                    mtry=3,
                                                    mtry.seed=100,
                                                    seed=100
                                                    )
                              
    # Use the generated model to predict the 'homestyle' on the test data housing_test.
    df_predict_mle_out1 <- td_decision_forest_predict_mle(object = decision_forest_model,
                                                          newdata = housing_test,
                                                          id.column = "sn",
                                                          detailed = FALSE,
                                                          terms = c("homestyle")
                                                          )

    # Example 2 - Using tbl_teradata object of the model generated by td_decision_forest_mle.
    # Use predictive.model tbl_teradata object of the generated model (in Example 1) to predict 
    # the 'homestyle' on the test data housing_test.
    df_predict_mle_out2 <- td_decision_forest_predict_mle(object = decision_forest_model$predictive.model,
                                                          newdata = housing_test,
                                                          id.column = "sn",
                                                          detailed = FALSE,
                                                          terms = c("homestyle")
                                                          )
                                                          
  # Example 3 - Use the generated model to predict the probabilities for 'homestyle' on the test data
  # 'housing_test' of each sample.
  df_predict_mle_out1 <- td_decision_forest_predict_mle(object = decision_forest_model,
                                                        newdata = housing_test,
                                                        id.column = "sn",
                                                        detailed = FALSE,
                                                        output.response.probdist=TRUE,
                                                        terms = c("homestyle")
                                                        )
  
  # Example 4 - Use the generated model to predict 'homestyle' in the test data 'housing_test' and 
  # probabilities of each label specified in the output.response argument. When output.responses is 
  # used, output.response.probdist argument must be set to TRUE to get probability values.
  df_predict_mle_out1 <-td_decision_forest_predict_mle(object = decision_forest_model,
                                                       newdata = housing_test,
                                                       id.column = "sn",
                                                       detailed = FALSE,
                                                       output.response.probdist = TRUE,
                                                       output.responses = c('Eclectic','Classic','bungalow'),
                                                       terms = c("homestyle")
                                                       )