| |
- KMeansPredict(data=None, object=None, accumulate=None, output_distance=False, **generic_arguments)
- DESCRIPTION:
The KMeansPredict() function uses the cluster centroids in
the KMeans() function output to assign the input data points
to the cluster centroids.
Notes:
* This function requires the UTF8 client character
set for UNICODE data.
* This function does not support Pass Through
Characters (PTCs).
* For information about PTCs, see Teradata Vantage™ -
Analytics Database International Character Set Support.
* This function does not support KanjiSJIS or Graphic data types.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame generated by
KMeans() function or the instance of KMeans.
Types: teradataml DataFrame or KMeans
accumulate:
Optional Argument.
Specifies the name(s) of 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)
output_distance:
Optional Argument.
Specifies whether to return the distance between
each data point and the nearest cluster.
Default Value: False
Types: bool
**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 KMeansPredict.
Output teradataml DataFrames can be accessed using attribute
references, such as KMeansPredictObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
1. 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("kmeans", "computers_train1")
# Create teradataml DataFrame objects.
computers_train1 = DataFrame.from_table("computers_train1")
# Check the list of available analytic functions.
display_analytic_functions()
# Grouping a set of observations into 2 clusters in which
# each observation belongs to the cluster with the nearest mean.
KMeans_out = KMeans(id_column="id",
target_columns=['price', 'speed'],
data=computers_train1,
num_clusters=2)
# Print the result DataFrames.
print(KMeans_out.result)
print(KMeans_out.model_data)
# Example 1 : Assign the input data points to the cluster centroid
# using the model generated by the KMeans() function.
# Note that teradataml DataFrame representing the model
# is passed as input to "object".
KMeansPredict_out = KMeansPredict(object=KMeans_out.result,
data=computers_train1)
# Print the result DataFrames.
print(KMeansPredict_out.result)
# Example 2 : Assign the input data points to the cluster centroid
# using the model generated by the KMeans() function.
# Note that model is passed as instance of KMeans to "object".
KMeansPredict_out_1 = KMeansPredict(data=computers_train1,
object=KMeans_out,
accumulate="ram",
output_distance=False)
# Print the result DataFrames.
print(KMeansPredict_out_1.result)
|