Teradata R Package Function Reference | 17.00 - 17.00 - XGBoostPredict - 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 XGBoostPredict function applies the model output by the XGBoost (td_xgboost_mle) function to a new data set, outputting predicted labels for each data point.

Usage

  td_xgboost_predict_mle (
      object = NULL,
      object.order.column = NULL,
      newdata = NULL,
      newdata.partition.column = "ANY",
      newdata.order.column = NULL,
      id.column = NULL,
      terms = NULL,
      iter.num = NULL,
      num.boosted.trees = NULL,
      attribute.name.column = NULL,
      attribute.value.column = NULL,
      output.response.probdist = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL
  )

  ## S3 method for class 'td_xgboost_mle'
predict(
      object = NULL,
      object.order.column = NULL,
      newdata = NULL,
      newdata.partition.column = "ANY",
      newdata.order.column = NULL,
      id.column = NULL,
      terms = NULL,
      iter.num = NULL,
      num.boosted.trees = NULL,
      attribute.name.column = NULL,
      attribute.value.column = NULL,
      output.response.probdist = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL
  )

Arguments

object

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

object.order.column

Required 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 containing the input test data.

newdata.partition.column

Optional Argument.
Specifies Partition By columns for "newdata".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Default Value: ANY
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)

id.column

Optional Argument.
Specifies a column containing a unique identifier for each test point in the test set given in the "newdata" argument.
Types: character

terms

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

iter.num

Optional Argument.
Specifies the number of iterations for each boosted tree to use for prediction. The lower bound is 1. If this argument is not specified, the value is the same as used for training the model. The number of iterations used is upperbounded by the number of iterations used during training.
Types: integer

num.boosted.trees

Optional Argument.
Specifies the number of boosted trees to be used for prediction. If this argument is not specified, the value is the same as used for training the model. The number of boosted trees used for prediciton is upper bounded by the number of boosted trees used during training.
Types: integer

attribute.name.column

Optional Argument.
Required for sparse data format.
If the data set is in sparse format, this argument indicates the column containing the attributes in the input tbl_teradata.
Types: character

attribute.value.column

Optional Argument.
If the data is in the sparse format, this argument indicates the column containing the attribute values in the input tbl_teradata.
Types: 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_xgboost_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("xgboost_example", "housing_train_binary","iris_train","sparse_iris_train","sparse_iris_attribute")
    loadExampleData("xgboostpredict_example", "housing_test_binary","iris_test","sparse_iris_test")

    # Example 1: Binary Classification
    # Create object(s) of class "tbl_teradata".
    housing_train_binary <- tbl(con, "housing_train_binary")
    housing_test_binary <- tbl(con,"housing_test_binary")
    
    # Create model
    td_xgboost_out1 <- td_xgboost_mle(data=housing_train_binary,
              id.column='sn',
              formula = ( homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + 
                          price + lotsize + bedrooms + bathrms + stories + garagepl ),
              num.boosted.trees=2,
              loss.function='binomial',
              prediction.type='classification',
              reg.lambda=1,
              shrinkage.factor=0.1,
              iter.num=10,
              min.node.size=1,
              max.depth=10
              )
              
    # Use the generated model to find prediction.
    td_xgboost_predict_out1 <- td_xgboost_predict_mle(newdata=housing_test_binary,
                                  object=td_xgboost_out1,
                                  object.order.column= c('tree_id','iter','class_num'),
                                  id.column='sn',
                                  terms='homestyle',
                                  num.boosted.trees=1)
                                  
    # Alternatively use S3 predict method to find the prediction.
    predict_out <- predict(td_xgboost_out1,
                        newdata=housing_test_binary,
                        object.order.column= c('tree_id','iter','class_num'),
                        id.column='sn',
                        terms='homestyle',
                        num.boosted.trees=1)
                        
    # Example 2: Multiple-Class Classification
    iris_train <- tbl(con,"iris_train")
    iris_test <- tbl(con,"iris_test")
    
    td_xgboost_out2 <- td_xgboost_mle(data=iris_train,
                                  id.column='id',
                                  formula = ( species ~ sepal_length + sepal_length + petal_length + petal_width + species),
                                  num.boosted.trees=2,
                                  loss.function='softmax',
                                  reg.lambda=1,
                                  shrinkage.factor=0.1,
                                  iter.num=10,
                                  min.node.size=1,
                                  max.depth=10)
                                  
    # Use the generated model to find prediction.
    td_xgboost_predict_out2 <- td_xgboost_predict_mle(newdata=iris_test,
                                  object=td_xgboost_out2,
                                  object.order.column=c('tree_id', 'iter', 'class_num'),
                                  id.column='id',
                                  terms='species',
                                  num.boosted.trees=2)     
                        
     # Example 3: Sparse Input Format. "response.column" argument is specified instead of "formula".
     # Create object(s) of class "tbl_teradata".
     sparse_iris_train <- tbl(con,"sparse_iris_train")
     sparse_iris_attribute <- tbl(con,"sparse_iris_attribute")
     sparse_iris_test <- tbl(con,"sparse_iris_test")
     
     td_xgboost_out3 <- td_xgboost_mle(data=sparse_iris_train,
                attribute.table=sparse_iris_attribute,
                id.column='id',
                attribute.name.column='attribute',
                attribute.value.column='value_col',
                response.column="species",
                loss.function='SOFTMAX',
                reg.lambda=1,
                num.boosted.trees=2,
                shrinkage.factor=0.1,
                column.subsampling=1.0,
                iter.num=10,
                min.node.size=1,
                max.depth=10,
                variance=0,
                seed=1
                )
      
      # Use the generated model to find prediction.
      td_xgboost_predict_out3 <- td_xgboost_predict_mle(newdata=sparse_iris_test,
                                  object=td_xgboost_out3,
                                  object.order.column=c('tree_id', 'iter', 'class_num'),
                                  id.column='id',
                                  attribute.name.column='attribute',
                                  attribute.value.column='value_col',
                                  terms='species',
                                  num.boosted.trees=2)