| |
- LinRegEvaluator(data, model, gen_sql_only=False)
- DESCRIPTION:
Linear regression model evaluation begins with scoring a DataFrame that includes the
actual values of the dependent variable. The standard error of estimate for the model is
calculated and reported and is compared to the standard error of estimate reported when
the model was built. The standard error of estimate is calculated as the square root of
the average squared residual value over all the observations (as shown below):
standard error of estimate = sqrt( sum((y-y1)**2)/(n-p-1) ),
where
* y1 - the actual value of the dependent variable
* y - the predicted value
* n - the number of observations
* p - the number of independent variables (substituting n-p in the denominator if
there is no constant term)
PARAMETERS:
data:
Required Argument.
Specifies the input data to evaluate.
Types: teradataml DataFrame
model:
Required Argument.
Specifies the input containing the linear model to use in evaluation. 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
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 LinRegEvaluator.
Output teradataml DataFrames can be accessed using attribute references, such as
LinRegEvaluatorObj.<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 evaluation 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)
# Evaluate the data using the linear regression model generated above.
obj = valib.LinRegEvaluator(data=df,
model=lin_reg_obj.model)
# Print the results.
print(obj.result)
# Example 2: Generate only SQL for the function, but do not execute the same.
obj = valib.LinRegEvaluator(data=df,
model=lin_reg_obj.model,
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"))
|