Teradata Package for R Function Reference | 17.00 - AdaBoostPredict - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
AdaBoostPredict

Description

The AdaBoostPredict function applies the model output by the function AdaBoost (td_adaboost_mle) to a new data set, outputting predicted labels for each data point.

Usage

  td_adaboost_predict_mle (
      object = NULL,
      newdata = NULL,
      attr.groupby.columns = NULL,
      attr.pid.columns = NULL,
      attr.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)

  ## S3 method for class 'td_adaboost_mle'
predict(
      object = NULL,
      newdata = NULL,
      attr.groupby.columns = NULL,
      attr.pid.columns = NULL,
      attr.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 td_adaboost_mle.
This argument can accept either tbl_teradata object or an object of "td_adaboost_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 name of the tbl_teradata containing the attribute names and the values of test data.

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.groupby.columns

Required Argument.
Specifies the name of the column on which the "newdata" is partitioned.
Types: character

attr.pid.columns

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

attr.val.column

Required Argument.
Specifies the name of the attribute tbl_teradata column that contains the data point values.
Types: character

output.response.probdist

Optional Argument.
Specifies whether to output probabilities.
It can be set to TRUE only when the td_adaboost_mle function call used to generate the model has set "output.response.probdist" to TRUE.
Note: With Vantage version prior to 1.1.1, when this argument is set to TRUE, the argument "output.responses" must also be specified.
Default Value: FALSE
Types: logical

accumulate

Optional Argument.
Specifies the names of "newdata" 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.
This argument can only be used when "output.response.probdist" is 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_adaboost_predict_mle" which is a named list containing tbl_teradata 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 the data to run the example
    loadExampleData("adaboost_example", "housing_train", "housing_cat", "housing_train_response", 
                    "iris_attribute_train", "iris_response_train")
    loadExampleData("adaboost_predict_example", "housing_test", "iris_attribute_test")
    
    # Create object(s) of class "tbl_teradata".
    housing_train <- tbl(con, "housing_train")
    housing_cat <- tbl(con, "housing_cat")
    housing_train_response <- tbl(con, "housing_train_response")
    iris_attribute_train <- tbl(con, "iris_attribute_train")
    iris_response_train <- tbl(con, "iris_response_train")
    
    housing_test <- tbl(con, "housing_test")
    iris_attribute_test <- tbl(con, "iris_attribute_test")
    
    # Example 1 - This example uses test data and the model output by the td_adaboost_mle() 
    # to use real estate sales data to predict home style.
    #
    # First, we will have to run td_adaboost_mle() function on the input in sparse format.
    # We run td_unpivot_mle() to create the input in sparse format.
    td_unpivot_out1 <- td_unpivot_mle(data = housing_train,
                                      unpivot = c("price", "lotsize", "bedrooms", "bathrms",
                                                  "stories","driveway", "recroom", "fullbase",
                                                  "gashw", "airco", "garagepl", "prefarea"),
                                      accumulate = "sn")
                                      
    td_adaboost_out1 <- td_adaboost_mle(attribute.data = td_unpivot_out1$result,
                                        attribute.name.columns = "attribute",
                                        attribute.value.column = "value_col",
                                        categorical.attribute.data = housing_cat,
                                        response.data = housing_train_response,
                                        id.columns = "sn",
                                        response.column = "response",
                                        iter.num = 20,
                                        num.splits = 10,
                                        max.depth = 3,
                                        min.node.size = 100)
                                    
    # Use the generated model to predict the house style, on the test data.
    # Transform the test data into sparse format.
    td_unpivot_out2 <- td_unpivot_mle(data = housing_test,
                                      unpivot = c("price", "lotsize", "bedrooms", "bathrms", 
                                                  "stories","driveway", "recroom", "fullbase",
                                                  "gashw", "airco", "garagepl", "prefarea"),
                                      accumulate = "sn")

    td_adaboost_predict_out1 <- td_adaboost_predict_mle (object = td_adaboost_out1,
                                                         newdata = td_unpivot_out2$result,
                                                         attr.groupby.columns = 'attribute',
                                                         attr.pid.columns = 'sn',
                                                         attr.val.column = 'value_col',
                                                         newdata.partition.column = "sn",
                                                         object.order.column="classifier_id")
                                                         
    # Example 2 - In this example, we predict the 'species' for the flowers 
    # represented by the data points in the test data (iris_attribute_test) based on the
    # model generated using td_adaboost_mle() function.
    #
    # Train an AdaBoost model on the input data which is in sparse format.
    td_adaboost_out2 <- td_adaboost_mle(attribute.data = iris_attribute_train,
                                        attribute.name.columns = "attribute",
                                        attribute.value.column = "attrvalue",
                                        response.data = iris_response_train,
                                        id.columns = "pid",
                                        response.column = "response",
                                        iter.num = 5,
                                        num.splits = 10,
                                        max.depth = 3,
                                        min.node.size = 5,
                                        output.response.probdist=TRUE,
                                        approx.splits=FALSE)
                                        
    # Use the generated model to predict the species on the test data which is
    # sparse format.
    td_adaboost_predict_out2 <- td_adaboost_predict_mle (object = td_adaboost_out2,
                                                         newdata = iris_attribute_test,
                                                         attr.groupby.columns = 'attribute',
                                                         attr.pid.columns = 'pid',
                                                         attr.val.column = 'attrvalue',
                                                         newdata.partition.column = "pid",
                                                         output.response.probdist = TRUE,
                                                         output.responses = c('1','2','3'),
                                                         object.order.column="classifier_id")
                                                         
    # Using S3 predict function to predict the species on the test data based 
    # on the generated model 'td_adaboost_out2'.
    td_adaboost_predict_out3 <- predict(object = td_adaboost_out2,
                                        newdata = iris_attribute_test,
                                        attr.groupby.columns = 'attribute',
                                        attr.pid.columns = 'pid',
                                        attr.val.column = 'attrvalue',
                                        newdata.partition.column = "pid",
                                        output.response.probdist = TRUE,
                                        output.responses = c('1','2','3'),
                                        object.order.column="classifier_id")