Teradata Package for Python Function Reference | 20.00 - NaiveBayesTextClassifierPredict - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
 
 
NaiveBayesTextClassifierPredict

 
Functions
       
NaiveBayesTextClassifierPredict(object=None, newdata=None, input_token_column=None, doc_id_columns=None, model_type='MULTINOMIAL', top_k=None, model_token_column=None, model_category_column=None, model_prob_column=None, output_prob=False, responses=None, accumulate=None, **generic_arguments)
DESCRIPTION:
    The NaiveBayesTextClassifierPredict() function uses the model generated by the
    NaiveBayesTextClassifierTrainer() function to predict the outcomes for a test set
    of data.
 
PARAMETERS:
    object:
        Required Argument.
        Specifies the teradataml DataFrame which contains the model
        data generated by the NaiveBayesTextClassifierTrainer() function or
        instance of NaiveBayesTextClassifierTrainer.
        Types: teradataml DataFrame or NaiveBayesTextClassifierTrainer
 
    newdata:
        Required Argument.
        Specifies the teradataml DataFrame containing the input test
        data.
        Types: teradataml DataFrame
 
    input_token_column:
        Required Argument.
        Specifies the name of the newdata column that contains the tokens.
        Types: str
 
    doc_id_columns:
        Required Argument.
        Specifies the names of the newdata columns that contain the
        document identifier.
        Types: str OR list of Strings (str)
 
    model_type:
        Optional Argument.
        Specifies the model type of the text classifier.
        Permitted Values: 'MULTINOMIAL', 'BERNOULLI'
        Default Value: 'MULTINOMIAL'
        Types: str
 
    top_k:
        Optional Argument.
        Specifies the number of most likely prediction categories to output
        with their log-likelihood values (for example, the top 10 most likely
        prediction categories). The default is all prediction categories.
        Types: int
 
    model_token_column:
        Optional Argument.
        Specifies the name of the object column that contains the
        tokens. The default value is the first column of object.
        Types: str
 
    model_category_column:
        Optional Argument.
        Specifies the name of the object column that contains the
        prediction categories. The default value is the second column of
        object.
        Types: str
 
    model_prob_column:
        Optional Argument.
        Specifies the name of the object column that contains the token
        counts. The default value is the third column of object.
        Types: str
 
    output_prob:
        Optional Argument.
        Specifies whether to output probabilities.
        Default Value: False
        Types: bool
 
    responses:
        Optional Argument.
        Specifies a list of Responses to output.
        Types: str OR list of strs
 
    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)
 
    **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: boolean
 
            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: 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
            SQL Engine function supports, else an exception is raised.
 
RETURNS:
    Instance of NaiveBayesTextClassifierPredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as
    NaiveBayesTextClassifierPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
    result
 
RAISES:
    TeradataMlException
 
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("NaiveBayesTextClassifierPredict",["complaints_tokens_test","token_table"])
 
    # Create teradataml DataFrame objects.
    token_table = DataFrame("token_table")
    complaints_tokens_test = DataFrame("complaints_tokens_test")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Create a model which is output of NaiveBayesTextClassifierTrainer.
    nbt_out = NaiveBayesTextClassifierTrainer(data = token_table,
                                              token_column = 'token',
                                              doc_id_column = 'doc_id',
                                              doc_category_column = 'category',
                                              model_type = "Bernoulli",
                                              data_partition_column = 'category')
 
    # Example: Run NaiveBayesTextClassifierPredict() on model generated by
    #          NaiveBayesTextClassifierTrainer() where model_type is "Bernoulli".
    nbt_predict_out = NaiveBayesTextClassifierPredict(object = nbt_out,
                                                      newdata = complaints_tokens_test,
                                                      input_token_column = 'token',
                                                      doc_id_columns = 'doc_id',
                                                      model_type = "Bernoulli",
                                                      model_token_column = 'token',
                                                      model_category_column = 'category',
                                                      model_prob_column = 'prob',
                                                      newdata_partition_column = 'doc_id')
 
    # Print the result DataFrame.
    print(nbt_predict_out.result)