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

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The LARPredict function (td_lar_predict_mle) 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
  )

## 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
  )

Arguments

object

Required Argument.
Specifies the name of the object returned by the td_lar_mle function. For td_lar_predict_mle, this can also be the tibble object containing the LAR model.

newdata

Required Argument.
Specifies the tibble object with new data for prediction.

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

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.

target.col

Optional Argument.
Specifies the name of the response column in the "data" argument (for prediction comparison). The sum-of-square error (SSE) for each prediction appears in the last row of the output table.

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.

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.

Value

Function returns an object of class "td_lar_predict_mle" which is a named list containing Teradata tbl 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 example data.
    loadExampleData("larpredict_example", "diabetes_test", "diabetes")
    
    # Create remote tibble objects.
    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: 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: 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: Use the table from a previously created model
    # Extract the model table 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)