Teradata R Package Function Reference - 16.20 - LinRegPredict - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The LinearRegressionPredict (td_linreg_predict_mle) function takes a model built by the Linear Regression function and a test data set whose input attributes are the same as those in the model, and predicts the response variable for each observation in the test data set.

Usage

  td_linreg_predict_mle (
      object = NULL,
      newdata = NULL,
      accumulate = NULL,
      input.columns = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL
  )

Arguments

object

Required Argument.
Specifies the model tbl_teradata from linear regression for the prediction.

newdata

Required Argument.
Specifies the test tbl_teradata to be used for prediction.

accumulate

Optional Argument.
Specifies the names of input tbl_teradata columns to copy to the output table.
Types: character OR vector of Strings (character)

input.columns

Optional Argument.
Specifies the names of the input tbl_teradata columns that contain the input variables.
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_linreg_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("linearregression_example", "housing_data")
    
    # Create remote tibble objects.
    housing_data <- tbl(con, "housing_data")
    
    # Build a linear regression model on the input data
    td_lin_reg_out <- td_lin_reg_mle(data = housing_data,
                                 formula = (sellingprice ~ housesize + lotsize + bedrooms + granite + upgradedbathroom)
                                )
    
    # Example 1 - This example uses the above linear regression model to 
    # make the predictions using td_linreg_predict_mle function.
    td_lin_reg_predict_out <- td_linreg_predict_mle(object = td_lin_reg_out$result,
                                                 newdata = housing_data)
    
    # Alternatively use the generic S3 predict function to make prediction.
    td_linreg_predict_out1 <- predict(object = td_lin_reg_out,
                                      newdata = housing_data,
                                      accumulate =
                                               c("housesize","lotsize","bedrooms","granite","upgradedbathroom"))
                                     
    # Example 2 - This example uses a persisted model to make predictions.
    # Persist the model to the Teradata Vantage Advanced SQL Engine using the copy_to function.
    linregmodel  <- td_lin_reg_out[[1]] %>% copy_to(con, df = .)
    td_linreg_predict_out2 <- td_linreg_predict_mle(object = linregmodel,
                                               newdata = housing_data
                                               )