Teradata R Package Function Reference | 17.00 - 17.00 - GLML1L2Predict - 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 GLML1L2Predict function uses the model output by the GLML1L2 (td_glml1l2_mle) function to perform generalized linear model prediction on new input data.

Usage

  td_glml1l2_predict_mle (
      modeldata = NULL,
      newdata = NULL,
      accumulate = NULL,
      output.prob = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      modeldata.sequence.column = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL
  )
  ## S3 method for class 'td_glml1l2_mle'
predict(
      modeldata = NULL,
      newdata = NULL,
      accumulate = NULL,
      output.prob = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      modeldata.sequence.column = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL)

Arguments

modeldata

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

modeldata.order.column

Optional Argument.
Specifies Order By columns for "modeldata".
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 test data set.

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)

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.prob

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

output.responses

Optional Argument.
Specifies responses in the input tbl_teradata.
"output.prob" must be set to TRUE in order to use this argument.
Note: "output.responses" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later versions.
Permitted Values: '0', '1'
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)

modeldata.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "modeldata". 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_glml1l2_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("glml1l2_example", "admissions_train", "housing_train")
    loadExampleData("glml1l2predict_example", "admissions_test", "housing_test")

    # Create object(s) of class "tbl_teradata".
    admissions_train <- tbl(con, "admissions_train")
    admissions_test <- tbl(con, "admissions_test")
    housing_train <- tbl(con, "housing_train")
    housing_test <- tbl(con, "housing_test")

    # Example 1 -
    # Generate a model based on train data "admissions_train".
    td_glml1l2_mle_out1 <- td_glml1l2_mle(formula = (admitted ~ stats + gpa + masters
                                                     + programming),
                                          data = admissions_train,
                                          alpha = 0,
                                          lambda = 0.02,
                                          family = "Binomial",
                                          randomization = TRUE
                                         )

    # Use the generated model to predict the 'admissions' on the test data
    # admissions_test by using model generated by GLML1L2, and also output the probabilities.
    td_glml1l2_predict_mle_out1 <- td_glml1l2_predict_mle(newdata = admissions_test,
                                                          modeldata = td_glml1l2_mle_out1,
                                                          accumulate = c("id"),
                                                          output.prob = TRUE
                                                         )

    # Example 2 -
    # Generate a model based on train data "housing_train".
    td_glml1l2_mle_out2 <- td_glml1l2_mle(formula = (price ~ lotsize + bedrooms + gashw
                                                     + driveway + stories + recroom + garagepl
                                                     + bathrms + homestyle + fullbase + airco
                                                     + prefarea),
                                          data = housing_train,
                                          alpha = 1,
                                          lambda = 0.02,
                                          family = "Gaussian",
                                          randomization = TRUE
                                          )

    # Use the generated model to predict the 'price' on the test data
    # housing_test by using the 'output' tbl_teradata from the model
    # generated by GLML1L2 as modeldata.
    td_glml1l2_predict_mle_out2 <- td_glml1l2_predict_mle(newdata = housing_test,
                                                          modeldata = td_glml1l2_mle_out2$output,
                                                          accumulate = c("sn")
                                                         )

    # Alternatively use the generic S3 predict function to make prediction.
    td_glml1l2_predict_mle_out21 <- predict(td_glml1l2_mle_out2,
                                            newdata = housing_test,
                                            accumulate = c("sn")
                                           )