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

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
LinearRegressionPredict

Description

The LinearRegressionPredict function takes a model built by the Linear Regression (td_lin_reg_mle) 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,
      newdata.order.column = NULL,
      object.order.column = NULL
  )
  ## S3 method for class 'td_lin_reg_mle'
predict(
      object = NULL,
      newdata = NULL,
      accumulate = NULL,
      input.columns = NULL,
      newdata.sequence.column = NULL,
      object.sequence.column = NULL,
      newdata.order.column = NULL,
      object.order.column = NULL
  )

Arguments

object

Required Argument.
Specifies the model tbl_teradata generated by td_lin_reg_mle.
This argument can accept either a tbl_teradata or an object of "td_lin_reg_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)

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)

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 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("linearregression_example", "housing_data")

    # Create object(s) of class "tbl_teradata".
    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 in the 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
                                               )