| |
- PCAPredict(data, model, index_columns=None, accumulate=None, gen_sql_only=False)
- DESCRIPTION:
The function generates PCA scores using the model created by PCA() VALIB function.
The scoring process expresses each component as a linear combination of the input
columns. The result output DataFrame contains one or more index (key) columns and PCA
score columns, one for each component.
When PCA analysis was based on a correlation matrix, scoring input data is normalized
by subtracting the mean and dividing by the standard deviation.
If multiple factor models were built by means of one or more group by columns, the
resulting score DataFrame includes these columns and score the grouped input columns
accordingly.
PARAMETERS:
data:
Required Argument.
Specifies the input data containing the columns to get PCA scores.
Types: teradataml DataFrame
model:
Required Argument.
Specifies the teradataml DataFrame generated by VALIB PCA() function, containing
the PCA model to use in scoring.
Types: teradataml DataFrame
index_columns:
Optional Argument.
Specifies one or more different columns for the primary index of the result
output DataFrame. By default, the primary index columns of the result output
DataFrame are the primary index columns of the input DataFrame "data". In
addition, the columns specified in this argument need to form a unique key for
the result output DataFrame. Otherwise, there are more than one score for a
given observation.
Types: str OR list of Strings (str)
accumulate:
Optional Argument.
Specifies one or more columns from the "data" DataFrame that can be passed to
the result output DataFrame.
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 PCAPredict.
Output teradataml DataFrames can be accessed using attribute references, such as
PCAPredObj.<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 the required teradataml DataFrame.
df = DataFrame("customer")
print(df)
# Example 1: Run PCA() on columns "age", "income", "years_with_bank" and "nbr_children".
pca_obj = valib.PCA(data=df,
columns=["age", "years_with_bank", "nbr_children", "income"])
# Get PCA scores using the model generated above.
obj = valib.PCAPredict(data=df,
model=pca_obj.result,
index_columns="cust_id",
accumulate=["age", "years_with_bank", "nbr_children"])
# Print the results.
print(obj.result)
# Example 2: Generate only SQL for the function, but do not execute the same.
obj = valib.PCAPredict(data=df,
model=pca_obj.result,
index_columns="cust_id",
accumulate=["age", "years_with_bank", "nbr_children"],
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"))
|