Teradata Package for Python Function Reference | 17.10 - 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

Product
Teradata Package for Python
Release Number
17.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
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, **generic_arguments)
DESCRIPTION:
    The NaiveBayesTextClassifierPredict() function uses the model generated by the
    NaiveBayesTextClassifier() 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 NaiveBayesTextClassifier() function or
        instance of NaiveBayesTextClassifier.
        Types: teradataml DataFrame or NaiveBayesTextClassifier
 
    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
 
    **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 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, 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("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()
 
    # Import function NaiveBayesTextClassifierPredict.
    from teradataml import NaiveBayesTextClassifierPredict
 
    # Create a model which is output of NaiveBayesTextClassifier.
    nbt_out = NaiveBayesTextClassifier(data = token_table,
                                       token_column = 'token',
                                       doc_id_columns = 'doc_id',
                                       doc_category_column = 'category',
                                       model_type = "Bernoulli",
                                       data_partition_column = 'category')
 
    # Example: Run NaiveBayesTextClassifierPredict() on model generated by
    #          NaiveBayesTextClassifier() 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)