| |
- OrdinalEncodingTransform(data=None, object=None, accumulate=None, **generic_arguments)
- DESCRIPTION:
The OrdinalEncodingTransform() function maps the categorical value
to a specified ordinal value using the OrdinalEncodingFit()
function output.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame containing the ordinalencoding parameters
generated by OrdinalEncodingFit() function or the instance of OrdinalEncodingFit.
Types: teradataml DataFrame or OrdinalEncodingFit
accumulate:
Optional Argument.
Specifies the input teradataml DataFrame column(s) to copy to the
output. By default, the function copies no input teradataml
DataFrame columns to the output.
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 OrdinalEncodingTransform.
Output teradataml DataFrames can be accessed using attribute
references, such as OrdinalEncodingTransformObj.<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.
titanic = DataFrame.from_table("titanic")
# Check the list of available analytic functions.
display_analytic_functions()
# Example 1: Transform the data by identyfying distinct categorical values from the input
# using OrdinalEncodingFit.
ordinal_encodingfit_res_1 = OrdinalEncodingFit(target_column='sex',
data=titanic)
ordinal_encoding_transform_out_1 = OrdinalEncodingTransform(data = titanic,
object = ordinal_encodingfit_res_1.result,
accumulate='age'
)
# Print the result DataFrame.
print(ordinal_encoding_transform_out_1.result)
# Example 2: Transform the data by identyfying distinct categorical values
# from the input and returns the distinct categorical values
# along with the ordinal value for each category.
ordinal_encodingfit_res_2 = OrdinalEncodingFit(target_column='sex',
approach='LIST',
categories=['category0', 'category1'],
ordinal_values=[1, 2],
start_value=0,
default_value=-1,
data=titanic)
ordinal_encoding_transform_out_2 = OrdinalEncodingTransform(data = titanic,
object = ordinal_encodingfit_res_2,
accumulate='age'
)
# Print the result DataFrame.
print(ordinal_encoding_transform_out_2.result)
|