Teradata R Package Function Reference | 17.00 - 17.00 - LARPredict - 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 LARPredict function takes new data and the model generated by the function LAR (td_lar_mle) and uses the predictors in the model to output predictions for the new data.

Usage

  td_lar_predict_mle (
      object = NULL,
      newdata = NULL,
      mode = "STEP",
      s = NULL,
      target.col = NULL,
      object.sequence.column = NULL,
      newdata.sequence.column = NULL,
      newdata.order.column = NULL,
      object.order.column = NULL
  )
  ## S3 method for class 'td_lar_mle'
predict(
      object = NULL,
      newdata = NULL,
      mode = "STEP",
      s = NULL,
      target.col = NULL,
      object.sequence.column = NULL,
      newdata.sequence.column = NULL,
      newdata.order.column = NULL,
      object.order.column = NULL
 )

Arguments

object

Required Argument.
Specifies the model tbl_teradata generated by td_lar_mle.
This argument can accept either a tbl_teradata or an object of "td_lar_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 test tbl_teradata to be used for prediction.

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)

mode

Optional Argument.
Specifies the mode for the "s" argument. This can take the following values:

  1. "STEP": The "s" argument indicates the positions corresponding to the steps in the model generated by the td_lar_mle function. The "s" argument can include any real values in [1, k], where k is the maximum step in the model.

  2. "FRACTION": The "s" argument indicates the fractions of the L1 norm of the coefficients against the maximum L1 norm. The maximum L1 norm is that of the full OLS solution, which is the coefficients at the last step. The "s" argument can include any real values in [0, 1].

  3. "NORM": The "s" argument indicates the L1 norm of the coefficients. The "s" argument can include any real values in [0, max L1 norm]. For maximum L1 norm, see above.

  4. "LAMBDA": The "s" argument indicates the maximum absolute correlations. For definition, the "s" argument can include any real values.


Default Value: "STEP"
Permitted Values: STEP, FRACTION, NORM, LAMBDA
Types: character

s

Optional Argument.
Specifies the positions of the coefficients at which to generate predictions. Each coefficient is a different numeric value in the range specified by the "mode" argument.
Types: numeric OR vector of numerics

target.col

Optional Argument.
Specifies the name of the response column in the "newdata" argument (for prediction comparison). The sum-of-square error (SSE) for each prediction appears in the last row of the output tbl_teradata.
Types: character OR vector of Strings (character)

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_lar_predict_mle" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using the name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("larpredict_example", "diabetes_test", "diabetes")

    # Create object(s) of class "tbl_teradata".
    diabetes_test <- tbl(con, "diabetes_test")
    diabetes <- tbl(con, "diabetes") %>% rename_all(tolower)

    # Build a LAR model with response variable 'y' and ten baseline predictors.
    td_lar_out <- td_lar_mle(formula = (y ~ hdl + glu + ldl + map1 + sex + tch + age + ltg
                                        + bmi + tc),
                             data = diabetes,
                             type = "LAR",
                             max.steps  = 20,
                             intercept = TRUE
                             )

    # Example 1: Use the model object directly as input to the td_lar_predict_mle() function.
    td_lar_predict_out1 <- td_lar_predict_mle(object = td_lar_out,
                                              newdata = diabetes_test,
                                              mode = "step",
                                              s = 1.6,
                                              target.col = c("y")
                                             )

    # Example 2: Alternatively use the predict S3 method to find predictions.
    predict_out <- predict(td_lar_out,
                           newdata = diabetes_test,
                           mode = "step",
                           s = 1.6,
                           target.col = c("y")
                           )

    # Example 3: Use the tbl_teradata from a previously created model
    # Extract the model tbl_teradata using the extract2() function
    td_lar_out_tbl <- td_lar_out %>% extract2(1)

    td_lar_predict_out2 <- td_lar_predict_mle(object = td_lar_out_tbl,
                                              newdata = diabetes_test,
                                              mode = "step",
                                              s = 1.6,
                                              target.col = c("y")
                                              )
    # The prediction result can be persisted in a table - "result_td_lar_predict_out2".
    copy_to(con, 
            df = td_lar_predict_out2$result, 
            name = "result_td_lar_predict_out2", 
            overwrite = TRUE)