| |
- LogRegPredict(data, model, estimate_column=None, index_columns=None, prob_column=None, accumulate=None, prob_threshold=0.5, gen_sql_only=False)
- DESCRIPTION:
Logistic Regression function model can be passed to a Logistic Regression Scoring
function to create a score output containing predicted values of the dependent variable.
PARAMETERS:
data:
Required Argument.
Specifies the input data to score.
Types: teradataml DataFrame
model:
Required Argument.
Specifies the input containing the logistic model to use in scoring. This must
be the "model" teradataml DataFrame generated by LogReg() function from VALIB or
a teradataml DataFrame created on a table generated by 'logistic' function from
Vantage Analytic Library.
Types: teradataml DataFrame
estimate_column:
Required Argument.
Specifies the name of a column in the score output containing the estimated value
of the dependent variable (column).
Notes:
1. Either "estimate_column" or "prob_column" must be requested.
2. If the estimate column is not unique in the score output, '_tm_' is
automatically placed in front of the name.
Types: str
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)
prob_column:
Optional Argument.
Specifies the name of a column in the score output containing the probability
that the dependent value is equal to the response value.
Notes:
1. Either "estimate_column" or "prob_column" must be requested.
2. If the probability column is not unique in the score output, '_tm_' is
automatically placed in front of the name.
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)
prob_threshold:
Optional Argument.
Specifies the probability threshold value. When the probability of the dependent
variable being 1 is greater than or equal to this value, the estimated value of
the dependent variable is 1. If less than this value, the estimated value is 0.
Default Value: 0.5
Types: float, int
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 LogRegPredict.
Output teradataml DataFrames can be accessed using attribute references, such as
LogRegPredictObj.<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 logistic model scoring can be performed.
# Generate a logistic model.
log_reg_obj = valib.LogReg(data=df,
columns=["age", "years_with_bank", "income"],
response_column="nbr_children",
response_value=0)
# Print the model.
print(log_reg_obj.model)
# Score using the model generated above.
obj = valib.LogRegPredict(data=df,
model=log_reg_obj.model,
prob_column="Probability")
# Print the results.
print(obj.result)
# Example 2: Generate only SQL for the function, but do not execute the same.
obj = valib.LogRegPredict(data=df,
model=log_reg_obj.model,
prob_column="Probability",
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"))
|