| |
- LinRegPredict(data, model, index_columns=None, response_column=None, accumulate=None, gen_sql_only=False)
- DESCRIPTION:
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.
* 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.
* 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.
PARAMETERS:
data:
Required Argument.
Specifies the input data to score.
Types: teradataml DataFrame
model:
Required Argument.
Specifies the input containing the linear model to use in scoring. This must be
the "model" teradataml DataFrame generated by LinReg() function from VALIB or a
teradataml DataFrame created on a table generated by 'linear' function from
Vantage Analytic Library.
Types: teradataml DataFrame
index_columns:
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: str OR list of Strings (str)
response_column:
Optional Argument.
Specifies the name of the predicted value column. If not used, the name of the
dependent column in the input is used.
Types: str
accumulate:
Optional Argument.
Specifies the name(s) of the column(s) from the input to retain in the output.
Types: str OR list of Strings (str)
gen_sql_only:
Optional Argument.
Specifies whether to generate only SQL for the function.
When set to True, function SQL is generated, not executed, which can be accessed
using show_query() method, otherwise SQL is just executed but not returned.
Default Value: False
Types: bool
RETURNS:
An instance of LinRegPredict.
Output teradataml DataFrames can be accessed using attribute references, such as
LinRegPredictObj.<attribute_name>.
Output teradataml DataFrame attribute name is: result
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
# Notes:
# 1. To execute Vantage Analytic Library functions,
# a. import "valib" object from teradataml.
# b. set 'configure.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.
# Import valib object from teradataml to execute this function.
from teradataml import valib
# Set the 'configure.val_install_location' variable.
from teradataml import configure
configure.val_install_location = "SYSLIB"
# Create required teradataml DataFrame.
df = DataFrame("customer")
print(df)
# Example 1: Shows how linear regression model scoring is performed.
# First generate the model using LinReg() function from 'valib'.
lin_reg_obj = valib.LinReg(data=df,
columns=["age", "years_with_bank", "nbr_children"],
response_column="income")
# Print the linear regression model.
print(lin_reg_obj.model)
# Score the data using the linear regression model generated above.
obj = valib.LinRegPredict(data=df,
model=lin_reg_obj.model,
response_column="inc")
# Print the results.
print(obj.result)
# Example 2: Generate only SQL for the function, but do not execute the same.
obj = valib.LinRegPredict(data=df,
model=lin_reg_obj.model,
response_column="inc",
gen_sql_only=True)
# Print the generated SQL.
print(obj.show_query("sql"))
# Print both generated SQL and stored procedure call.
print(obj.show_query("both"))
# Print the stored procedure call.
print(obj.show_query())
print(obj.show_query("sp"))
|