Teradata R Package Function Reference | 17.00 - 17.00 - GLML1L2 - 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 GLML1L2 function differs from the GLM function in these ways:

  1. GLML1L2 supports the regularization models Ridge, LASSO, and Elastic Net.

  2. GLML1L2 outputs a model tbl_teradata and, optionally, a factor tbl_teradata (GLM outputs only a model).

Usage

  td_glml1l2_mle (
      formula = NULL,
      data = NULL,
      alpha = 0.0,
      lambda = 0,
      max.iter.num = 10000,
      stop.threshold = 1.0E-7,
      family = "Gaussian",
      randomization = FALSE,
      data.sequence.column = NULL
  )

Arguments

formula

Required Argument.
An object of class "formula". Specifies the model to be fitted. Only basic formula of the (col1 ~ col2 + col3 +...) form are supported and all variables must be from the same tbl_teradata object. The response should be a column of type numeric or logical.

data

Required Argument.
Specifies the name of the tbl_teradata that contains the input data.

alpha

Optional Argument.
Specifies whether to use Lasso, Ridge or Elastic Net. If the value is 0, Ridge is used. If the value is 1, Lasso is used. For any value between 0 and 1, Elastic Net is applied.
Default Value: 0.0
Types: numeric

lambda

Optional Argument.
Specifies the parameter that controls the magnitude of the regularization term. The value of "lambda" must be in the range [0.0, 100.0]. A value of zero disables regularization.
Default Value: 0
Types: numeric

max.iter.num

Optional Argument.
Specifies the maximum number of iterations over the data. The parameter "max.iter.num" must be a positive numeric value in the range [1, 100000].
Default Value: 10000
Types: integer

stop.threshold

Optional Argument.
Specifies the convergence threshold.
Default Value: 1.0E-7
Types: numeric

family

Optional Argument.
Specifies the distribution exponential family.
Default Value: "Gaussian"
Permitted Values: Binomial, Gaussian
Types: character

randomization

Optional Argument.
Specifies whether to randomize the input tbl_teradata data.
Default Value: FALSE
Types: logical

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". 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_mle" which is a named list containing objects of class "tbl_teradata".
Named list members can be referenced directly with the "$" operator using following names:

  1. factor.data

  2. output

Note:

  1. When argument randomization is TRUE or if any categorical columns are provided in formula argument, then and only then the output tbl_teradata object factor.data is created.

  2. factor.data can be used as the input (data) for future GLML1L2 function calls, thereby saving the function from repeating the categorical-to-numerical conversion or randomization.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("glml1l2_example", "admissions_train", "housing_train")

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

    # Example 1 -
    # Ridge Regression, family = 'Binomial'.
    # Because the response variable is binary (the admitted column has
    # two possible values), the call specifies family = 'Binomial'.
    # alpha = 0 indicates L2 (ridge regression) regularization.
    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
                                         )

    # Example 2 -
    # factor.data (from Example 1) as input data.
    # Because Randomization was TRUE in the function call that created
    # the factor.data input, this call does not need it.
    td_glml1l2_mle_out2 <- td_glml1l2_mle(formula = (admitted ~ masters_yes + stats_novice
                                                     + programming_novice + stats_beginner
                                                     + programming_beginner + gpa),
                                          data = td_glml1l2_mle_out1$factor.data,
                                          alpha = 0,
                                          lambda = 0.02,
                                          family = "Binomial"
                                         )

    # Example 3 -
    # LASSO, family = 'Gaussian'.
    # Because the response variable has a Gaussian distribution, the call specifies
    # family = 'Gaussian'.
    # alpha = 1 indicates L1 (LASSO) regularization.
    td_glml1l2_mle_out3 <- 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
                                         )