| |
- TargetEncodingTransform(data=None, object=None, accumulate=None, **generic_arguments)
- DESCRIPTION:
The TargetEncodingTransform() function takes the input data
and a Fit data generated by the TargetEncodingFit() function
for encoding the categorical values.
Notes:
* This function requires the UTF8 client character set.
* This function does not support Pass-Through Characters (PTCs).
* This function does not support KanjiSJIS or Graphic data types.
Usage considerations for TargetEncodingTransform are:
* Errors are generated in these cases:
* When the Fit data does not meet the criteria.
* When category from input data is not found in the Fit data and
the "default_values" argument is also not used during
TargetEncodingFit() function.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame containing the TargetEncodingFit
parameters generated by TargetEncodingFit() function or the instance
of TargetEncodingFit.
Types: teradataml DataFrame or TargetEncodingFit
accumulate:
Optional Argument.
Specifies the name(s) of input teradataml DataFrame column(s) to
be copied to the output.
Notes:
* The maximum length supported is 128.
* The maximum list length is 2047.
* "accumulate" are not case sensitive.
Types: str OR list of Strings (str)
**generic_arguments:
Specifies the generic keyword arguments SQLE functions accept. Below
are the generic keyword arguments:
persist:
Optional Argument.
Specifies whether to persist the results of the
function in a table or not. When set to True,
results are persisted in a table; otherwise,
results are garbage collected at the end of the
session.
Default Value: False
Types: bool
volatile:
Optional Argument.
Specifies whether to put the results of the
function in a volatile table or not. When set to
True, results are stored in a volatile table,
otherwise not.
Default Value: False
Types: bool
Function allows the user to partition, hash, order or local
order the input data. These generic arguments are available
for each argument that accepts teradataml DataFrame as
input and can be accessed as:
* "<input_data_arg_name>_partition_column" accepts str or
list of str (Strings)
* "<input_data_arg_name>_hash_column" accepts str or list
of str (Strings)
* "<input_data_arg_name>_order_column" accepts str or list
of str (Strings)
* "local_order_<input_data_arg_name>" accepts boolean
Note:
These generic arguments are supported by teradataml if
the underlying SQL Engine function supports, else an
exception is raised.
RETURNS:
Instance of TargetEncodingTransform.
Output teradataml DataFrames can be accessed using attribute
references, such as TargetEncodingTransformObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
# Notes:
# 1. Get the connection to Vantage to execute the function.
# 2. One must import the required functions mentioned in
# the example from teradataml.
# 3. Function will raise error if not supported on the Vantage
# user is connected to.
# Load the example data.
load_example_data("teradataml", ["titanic"])
# Create teradataml DataFrame objects.
data_input = DataFrame.from_table("titanic")
# Check the list of available analytic functions.
display_analytic_functions()
# Find the distinct values and counts for column 'sex' and 'embarked'.
categorical_summ = CategoricalSummary(data=data_input,
target_columns = ["sex", "embarked"]
)
# Find the distinct count of 'sex' and 'embarked' in which only 2 column should be present
name 'ColumnName' and 'CategoryCount'.
category_data=categorical_summ.result.groupby('ColumnName').count()
category_data = category_data.assign(drop_columns = True,
ColumnName = category_data.ColumnName,
CategoryCount = category_data.count_DistinctValue)
# Generates the required hyperparameters when "encoder_method" is 'CBM_BETA'.
TargetEncodingFit_out = TargetEncodingFit(data = data_input,
category_data = category_data,
encoder_method = 'CBM_BETA',
target_columns = ['sex', 'embarked'],
response_column = 'survived',
default_values = [-1, -2]
)
# Example 1 : Encode the column 'sex' and 'embarked'.
TargetEncodingTransform_out = TargetEncodingTransform(data = data_input,
object = TargetEncodingFit_out,
accumulate = "passenger"
)
# Print the result DataFrame.
print(TargetEncodingTransform_out.result)
|