Teradata Package for R Function Reference | 17.00 - 17.00 - td_lin_reg_predict_valib - Teradata Package for R

Teradata® Package for R Function Reference

Teradata Package for R
Release Number
July 2021
Last Update
August 2022
Content Type
Programming Reference
Publication ID
English (United States)
Last Update
Linear Regression Predict


Linear Regression Scoring is the application of a Linear Regression model to an input data that contains the same independent variable columns contained in the model. The result is an output score data that minimally contains one or more key columns and an estimate of the dependent variable in the model.

Some of the key features of linear scoring are outlined below:

  1. If one or more group by columns are present in the input data to be scored and the model input data, each row in the input data to be scored is scored using the appropriate model in the model input data.

  2. If an error such as "Constant columns detected" occurs for a particular combination of group by column values, the predicted value of the dependent column is null for any row containing that combination of group by column values. The error message is also placed in the column name in the model report.


td_lin_reg_predict_valib(model, data, ...)



Required Argument.
Specifies the input containing the linear model to use in scoring This must be the "model" tbl_teradata generated by td_lin_reg_valib() or a tbl_teradata created on a table generated by 'linear' function from Vantage Analytic Library.
Types: tbl_teradata


Required Argument.
Specifies the input data to score.
Types: tbl_teradata


Specifies other arguments supported by the function as described in the 'Other Arguments' section.


Function returns an object of class "td_lin_reg_predict_valib" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using name: result.

Other Arguments


Optional Argument.
Specifies the name(s) of the column(s) representing the primary index of the score output. By default, the primary index columns of the score output are the primary index columns of the input. In addition, the index columns need to form a unique key for the score output. Otherwise, there are more than one score for a given observation.
Types: character OR vector of Strings (character)


Optional Argument.
Specifies the name of the predicted value column. If not used, the name of the dependent column in the input is used.

  • If the response column is not unique in the score output, '_tm_' is automatically placed in front of the name.

Types: character


Optional Argument.
Specifies the name(s) of the column(s) from the input to retain in the output.
Types: character OR vector of Strings (character)


Optional Argument.
Specifies the name of a column that contains the residual value (the difference between the predicted and actual value of the dependent variable).
Default Value: 'Residual'
Types: character


# Notes:
#   1. To execute Vantage Analytic Library functions, set option
#      'val.install.location' to the database name where Vantage analytic
#      library functions are installed.
#   2. Datasets used in these examples can be loaded using Vantage Analytic
#      Library installer.

# Set the option 'val.install.location'.
options(val.install.location = "SYSLIB")

# Get remote data source connection.
con <- td_get_context()$connection

# Create an object of class "tbl_teradata".
df <- tbl(con, "customer")

# Example 1: Shows how linear regression model scoring is performed.
# First generate the model using td_lin_reg_valib() function.
lin_reg_obj <- td_lin_reg_valib(data=df,
                                columns=c("age", "years_with_bank",
# Print the model.

# Score the data using the linear regression model generated above.
obj <- td_lin_reg_predict_valib(data=df,
# Print the results.

# Score using S3 predict function and the model generated above.
obj <- predict(object=lin_reg_obj,
# Print the results.