| |
- OneHotEncodingTransform(data=None, object=None, is_input_dense=None, **generic_arguments)
- DESCRIPTION:
Function encodes specified attributes and categorical values as one-hot numeric vectors,
using OneHotEncodingFit() function output.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame containing the encoding parameters generated by
OneHotEncodingFit() function or the instance of OneHotEncodingFit.
Types: teradataml DataFrame or OneHotEncodingFit
is_input_dense:
Required Argument.
Specifies whether input is in dense format or sparse format.
Types: boolean
**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 table or not.
When set to True, results are persisted in table; otherwise, results
are garbage collected at the end of the session.
Default Value: False
Types: boolean
volatile:
Optional Argument.
Specifies whether to put the results of the function in volatile table or not.
When set to True, results are stored in volatile table, otherwise not.
Default Value: False
Types: boolean
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
SQLE Engine function supports, else an exception is raised.
RETURNS:
Instance of OneHotEncodingTransform.
Output teradataml DataFrames can be accessed using attribute
references, such as OneHotEncodingTransformObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
# Notes:
# 1. Get the connection to Vantage, before importing the function in user space.
# 2. User can import the function, if it is available on the Vantage user is connected to.
# 3. To check the list of analytic functions available on the Vantage user connected to,
# use "display_analytic_functions()".
# Load the example data.
load_example_data("teradataml", ["titanic"])
# Create teradataml DataFrame object.
titanic_data = DataFrame.from_table("titanic")
# Check the list of available analytic functions.
display_analytic_functions()
# Import functions OneHotEncodingFit and OneHotEncodingTransform.
from teradataml import OneHotEncodingFit, OneHotEncodingTransform
# Example 1: Transform categorical column "sex" to numerical columns "sex_male", "sex_female",
# and "sex_other" using OneHotEncodingFit() and OneHotEncodingTransform().
# Generate fit object for column "sex".
fit_obj = OneHotEncodingFit(data=titanic_data,
is_input_dense=True,
target_column="sex",
categorical_values=["male", "female"],
other_column="other")
# Print the result DataFrame.
print(fit_obj.result)
# Encode "male" and "female" values of column "sex".
obj = OneHotEncodingTransform(data=titanic_data,
object=fit_obj.result,
is_input_dense=True)
# Print the result DataFrame.
print(obj.result)
|