Teradata R Package Function Reference | 17.00 - 17.00 - DecisionTreePredict - 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 DecisionTreePredict function applies a tree model to input data, to output predicted labels for each data point.
Note: This function is only available when tdplyr is connected to Vantage 1.1 or later versions.

Usage

  td_decision_tree_predict_mle (
      object = NULL,
      newdata = NULL,
      attr.table.groupby.columns = NULL,
      attr.table.pid.columns = NULL,
      attr.table.val.column = NULL,
      output.response.probdist = FALSE,
      accumulate = NULL,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL,
      newdata.partition.column = NULL,
      newdata.order.column = NULL,
      object.order.column = NULL
  )

Arguments

object

Required Argument.
Specifies the model tbl_teradata generated by DecisionTree (td_decision_tree_mle).
This argument can accept either a tbl_teradata or an object of "td_decision_tree_mle" class

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 name of the tbl_teradata object containing the attribute names and the values. It contains test data and has same schema as that of input tbl_teradata of td_decision_tree_mle function.

newdata.partition.column

Required Argument.
Specifies Partition By columns for "newdata".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

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)

attr.table.groupby.columns

Required Argument.
Specifies the names of the columns on which attribute tbl_teradata used in td_decision_tree_mle function is partitioned. Each partition contains one attribute of the input data.
Types: character OR vector of Strings (character)

attr.table.pid.columns

Required Argument.
Specifies the names of the columns that define the data point identifiers.
Types: character OR vector of Strings (character)

attr.table.val.column

Required Argument.
Specifies the name of the column that contains the input values.
Types: character

output.response.probdist

Optional Argument.
Specifies whether to output probabilities.
Note:

  1. With Vantage version prior to 1.1.1, when this argument is set to TRUE, the argument "output.responses" must also be specified.

  2. It can be set to TRUE only when the td_decision_tree_mle function call used to generate the model had "output.response.probdist" to TRUE.

Default Value: FALSE
Types: logical

accumulate

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

output.responses

Optional Argument.
Specifies all responses in input tbl_teradata
. Note: This argument requires the "output.response.probdist" argument to be set to TRUE.
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_tree_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("decisiontreepredict_example", "iris_attribute_test")
    loadExampleData("decision_tree_example", "iris_attribute_train", "iris_response_train", "iris_altinput")
    
    # Create object(s) of class "tbl_teradata".
    iris_attribute_train <- tbl(con, "iris_attribute_train")
    iris_response_train <- tbl(con, "iris_response_train")
    iris_attribute_test <- tbl(con, "iris_attribute_test")
    
    # Example - 1
    # First train the data, i.e. create a Model
    decision_tree_out <- td_decision_tree_mle(attribute.table = iris_attribute_train,
                               response.table = iris_response_train,
                               attribute.name.columns = c("attribute"),
                               attribute.value.column = "attrvalue",
                               id.columns = c("pid"),
                               response.column = "response",
                               num.splits = 3,
                               approx.splits = FALSE,
                               nodesize = 10,
                               max.depth = 10,
                               split.measure = "gini"
                               )
    # Run predict on the output of td_decision_tree_mle() function.
    td_decision_tree_predict_out <- td_decision_tree_predict_mle(object = decision_tree_out,
                                       newdata = iris_attribute_test,
                                       newdata.partition.column = c("pid"),
                                       newdata.order.column = c("attribute"),
                                       attr.table.groupby.columns = c("attribute"),
                                       attr.table.pid.columns = c("pid"),
                                       attr.table.val.column = "attrvalue",
                                       accumulate = c("attrvalue")
                                       )
    # Example - 2                                  
    # set output.response.probdist to TRUE to output the probability distributions.                 
    decision_tree_out2 <- td_decision_tree_mle(attribute.table=iris_attribute_train,
                                response.table=iris_response_train,
                                attribute.name.columns='attribute',
                                id.columns='pid',
                                attribute.value.column='attrvalue',
                                response.column='response',
                                num.splits=3,
                                nodesize=5,
                                max.depth=10,
                                split.measure='gini',
                                approx.splits=FALSE,
                                output.response.probdist=TRUE,
                                response.probdist.type = "Laplace"
                              )
                          
    # Use "output.response.probdist", "output.responses".    
    td_decision_tree_predict_out <- td_decision_tree_predict_mle(newdata=iris_attribute_test,
                                       newdata.partition.column='pid',
                                       newdata.order.column='attribute',
                                       object=decision_tree_out2,
                                       attr.table.groupby.columns='attribute',
                                       attr.table.pid.columns='pid',
                                       attr.table.val.column='attrvalue',
                                       accumulate='attrvalue',
                                       output.response.probdist=TRUE,
                                       output.responses=c('1','2','3')
                                       )