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

 
teradataml.analytics.mle.SentimentEvaluator = class SentimentEvaluator(builtins.object)
     Methods defined here:
__init__(self, object=None, obs_column=None, sentiment_column=None, object_sequence_column=None, object_order_column=None)
DESCRIPTION:
    The SentimentEvaluator function uses test data to evaluate the
    precision and recall of the predictions output by the function
    SentimentExtractor. The precision and recall are affected by the
    model that SentimentExtractor uses; therefore, if you change the
    model, you must rerun SentimentEvaluator on the new predictions.
 
 
PARAMETERS:
    object:
        Required Argument.
        Specifies the input teradataml DataFrame containing a text
        column with the input text.
 
    object_order_column:
        Optional Argument.
        Specifies Order By columns for object.
        Values to this argument can be provided as list, if multiple columns
        are used for ordering.
        Types: str OR list of Strings (str)
 
    obs_column:
        Required Argument.
        Specifies the name of the input column with the observed sentiment
        (POS, NEG or NEU).
        Types: str
 
    sentiment_column:
        Required Argument.
        Specifies the name of the input column with the predicted sentiment
        (POS, NEG or NEU).
        Types: str
 
    object_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "object". The argument is used to ensure
        deterministic results for functions which produce results that vary
        from run to run.
        Types: str OR list of Strings (str)
 
RETURNS:
    Instance of SentimentEvaluator.
    Output teradataml DataFrames can be accessed using attribute
    references, such as SentimentEvaluatorObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException
 
 
EXAMPLES:
    # Load example data.
    load_example_data("sentimenttrainer", "sentiment_train")
    load_example_data("sentimentextractor", ["sentiment_extract_input", "sentiment_word"])
 
    # Create teradataml DataFrame objects.
    sentiment_train = DataFrame.from_table("sentiment_train")
    sentiment_extract_input = DataFrame.from_table("sentiment_extract_input")
    sentiment_word = DataFrame.from_table("sentiment_word")
 
    # Example 1 -This example uses the dictionary model file 'default_sentiment_lexicon.txt'.
    SentimentExtractorOut1 = SentimentExtractor(object = "dictionary",
                                                newdata = sentiment_extract_input,
                                                text_column = "review",
                                                accumulate = ["category"]
                                                )
 
    SentimentEvaluatorOut1 = SentimentEvaluator(object=SentimentExtractorOut1.result,
                                                obs_column='category',
                                                sentiment_column='out_polarity'
                                               )
 
    # Print the results.
    print(SentimentEvaluatorOut1)
 
    # Example 2 - This example uses the classification model file
    #             'default_sentiment_classification_model.bin'.
    SentimentExtractorOut2 = SentimentExtractor(object = "classification:default_sentiment_classification_model.bin",
                                                newdata = sentiment_extract_input,
                                                text_column = "review",
                                                accumulate = ["category"]
                                                )
 
    SentimentEvaluatorOut2 = SentimentEvaluator(object=SentimentExtractorOut2.result,
                                                obs_column='category',
                                                sentiment_column='out_polarity'
                                               )
 
    # Print the results.
    print(SentimentEvaluatorOut2)
 
    # Example 3 - This example uses classification model file output by
    #             the SentimentTrainer function.
    SentimentTrainerOut = SentimentTrainer(data = sentiment_train,
                                           text_column = "review",
                                           sentiment_column = "category",
                                           model_file = "sentimentmodel1.bin"
                                           )
 
    # Use the sentiment extractor function to extract sentiment of each input document.
    SentimentExtractorOut3 = SentimentExtractor(object = "classification:sentimentmodel1.bin",
                                                newdata = sentiment_extract_input,
                                                text_column = "review",
                                                accumulate = ["category"]
                                                )
 
    SentimentEvaluatorOut3 = SentimentEvaluator(object=SentimentExtractorOut3.result,
                                                obs_column="category",
                                                sentiment_column="out_polarity"
                                               )
 
    # Print the results.
    print(SentimentEvaluatorOut3)
 
    # Example 4 - This example uses a dictionary table ('sentiment_word')
    #             instead of model file.
    SentimentExtractorOut4 = SentimentExtractor(newdata = sentiment_extract_input,
                                                dict_data = sentiment_word,
                                                text_column = "review",
                                                accumulate = ["category"]
                                                )
 
    SentimentEvaluatorOut4 = SentimentEvaluator(object=SentimentExtractorOut4.result,
                                                obs_column="category",
                                                sentiment_column="out_polarity"
                                               )
 
    # Print the results.
    print(SentimentEvaluatorOut4)
__repr__(self)
Returns the string representation for a SentimentEvaluator class instance.
get_build_time(self)
Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
get_prediction_type(self)
Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
get_target_column(self)
Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
show_query(self)
Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.