Teradata Package for Python Function Reference - HMMDecoder - 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.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage

 
teradataml.analytics.mle.HMMDecoder = class HMMDecoder(builtins.object)
     Methods defined here:
__init__(self, init_state_prob=None, state_transition_prob=None, emission_prob=None, observation=None, state_model_key=None, state_key=None, state_prob_key=None, trans_model_key=None, trans_from_key=None, trans_to_key=None, trans_prob_key=None, emit_model_key=None, emit_state_key=None, emit_observed_key=None, emit_prob_key=None, model_key=None, sequence_key=None, observed_key=None, sequence_max_size=2147483647, skip_key=None, accumulate=None, observation_sequence_column=None, init_state_prob_sequence_column=None, state_transition_prob_sequence_column=None, emission_prob_sequence_column=None, observation_partition_column=None, init_state_prob_partition_column=None, state_transition_prob_partition_column=None, emission_prob_partition_column=None, observation_order_column=None, init_state_prob_order_column=None, state_transition_prob_order_column=None, emission_prob_order_column=None)
DESCRIPTION:
    The HMMDecoder function finds the state sequence with the highest
    probability, given the learned model and observed sequences.
 
 
PARAMETERS:
    init_state_prob:
        Required Argument.
        Specifies the teradataml DataFrame representing the initial state table.
 
    init_state_prob_partition_column:
        Required Argument.
        Specifies Partition By columns for init_state_prob.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Types: str OR list of Strings (str)
 
    init_state_prob_order_column:
        Optional Argument.
        Specifies Order By columns for init_state_prob.
        Values to this argument can be provided as a list, if multiple
        columns are used for ordering.
        Types: str OR list of Strings (str)
 
    state_transition_prob:
        Required Argument.
        Specifies the teradataml DataFrame representing the state transition table.
 
    state_transition_prob_partition_column:
        Required Argument.
        Specifies Partition By columns for state_transition_prob.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Types: str OR list of Strings (str)
 
    state_transition_prob_order_column:
        Optional Argument.
        Specifies Order By columns for state_transition_prob.
        Values to this argument can be provided as a list, if multiple
        columns are used for ordering.
        Types: str OR list of Strings (str)
 
    emission_prob:
        Required Argument.
        Specifies the teradataml DataFrame representing the emission probability table.
 
    emission_prob_partition_column:
        Required Argument.
        Specifies Partition By columns for emission_prob.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Types: str OR list of Strings (str)
 
    emission_prob_order_column:
        Optional Argument.
        Specifies Order By columns for emission_prob.
        Values to this argument can be provided as a list, if multiple
        columns are used for ordering.
        Types: str OR list of Strings (str)
 
    observation:
        Required Argument.
        Specifies the teradataml DataFrame representing the observation table for which
        the probabilities of sequences are to be found.
 
    observation_partition_column:
        Required Argument.
        Specifies Partition By columns for observation.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Types: str OR list of Strings (str)
 
    observation_order_column:
        Required Argument.
        Specifies Order By columns for observation.
        Values to this argument can be provided as list, if multiple columns
        are used for ordering.
        Types: str OR list of Strings (str)
 
    state_model_key:
        Required Argument.
        Specifies the name of the model attribute column in the init_state_prob table.
        Types: str OR list of Strings (str)
 
    state_key:
        Required Argument.
        Specifies the name of the state attribute column in the init_state_prob table.
        Types: str OR list of Strings (str)
 
    state_prob_key:
        Required Argument.
        Specifies the name of the initial probability column in the init_state_prob
        table.
        Types: str OR list of Strings (str)
 
    trans_model_key:
        Required Argument.
        Specifies the name of the model attribute column in the state_transition_prob
        table.
        Types: str OR list of Strings (str)
 
    trans_from_key:
        Required Argument.
        Specifies the name of the source of the state transition column in the
        state_transition_prob table.
        Types: str OR list of Strings (str)
 
    trans_to_key:
        Required Argument.
        Specifies the name of the target of the state transition column in the
        state_transition_prob table.
        Types: str OR list of Strings (str)
 
    trans_prob_key:
        Required Argument.
        Specifies the name of the state transition probability column in the
        state_transition_prob table.
        Types: str OR list of Strings (str)
 
    emit_model_key:
        Required Argument.
        Specifies the name of the model attribute column in the emission_prob table.
        Types: str OR list of Strings (str)
 
    emit_state_key:
        Required Argument.
        Specifies the name of the state attribute in the emission_prob table.
        Types: str OR list of Strings (str)
 
    emit_observed_key:
        Required Argument.
        Specifies the name of the observation attribute column in the emission_prob
        table.
        Types: str OR list of Strings (str)
 
    emit_prob_key:
        Required Argument.
        Specifies the name of the emission probability in the emission_prob table.
        Types: str OR list of Strings (str)
 
    model_key:
        Required Argument.
        Specifies the name of the column that contains the model attribute. If you
        specify this argument, then model_attribute must match a model_key in
        the observation_partition_column.
        Types: str
 
    sequence_key:
        Required Argument.
        Specifies the name of the column that contains the sequence attribute. The
        sequence_attribute must be a sequence attribute in the
        observation_partition_column.
        Types: str
 
    observed_key:
        Required Argument.
        Specifies the name of the column that contains the observed symbols.
        Note: Observed symbols are case-sensitive.
        Types: str
 
    sequence_max_size:
        Optional Argument.
        Specifies the maximum length, in rows, of a sequence in the observation table.
        Default Value: 2147483647
        Types: int
 
    skip_key:
        Optional Argument.
        Specifies the name of the column whose values determine whether the function
        skips the row. The function skips the row if the value is "true",
        "yes", "y", or "1". The function does not skip the row if the value
        is "false", "f", "no", "n", "0", or None.
        Types: str
 
    accumulate:
        Optional Argument.
        Specifies the names of the columns in input_table that the function
        copies to the output table.
        Types: str OR list of Strings (str)
 
    observation_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "observation". 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)
 
    init_state_prob_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "init_state_prob". 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)
 
    state_transition_prob_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "state_transition_prob". 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)
 
    emission_prob_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "emission_prob". 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 HMMDecoder.
    Output teradataml DataFrames can be accessed using attribute
    references, such as HMMDecoderObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException
 
 
EXAMPLES:
    # Load example data.
    load_example_data("hmmunsupervised", "loan_prediction")
    load_example_data("hmmsupervised", "customer_loyalty")
 
    # Example 1 - This example uses loan status updates to build a Unupservised HMM
    # model and then predict loan defaults.
    load_example_data("hmmdecoder", "test_loan_prediction")
    loan_prediction = DataFrame.from_table("loan_prediction")
    HMMUnsupervised_out = HMMUnsupervised(vertices = loan_prediction,
                                          vertices_partition_column = ["model_id", "seq_id"],
                                          vertices_order_column = ["seq_vertex_id"],
                                          model_key = "model_id",
                                          sequence_key = "seq_id",
                                          observed_key = "observed_id",
                                          hidden_states_num = 3
                                          )
 
    test_loan_prediction = DataFrame.from_table("test_loan_prediction")
    HMMDecoder_out1 = HMMDecoder(init_state_prob = HMMUnsupervised_out.output_initialstate_table,
                                init_state_prob_partition_column = ["model_id"],
                                state_transition_prob = HMMUnsupervised_out.output_statetransition_table,
                                state_transition_prob_partition_column = ["model_id"],
                                emission_prob = HMMUnsupervised_out.output_emission_table,
                                emission_prob_partition_column = ["model_id"],
                                observation = test_loan_prediction,
                                observation_partition_column = ["model_id"],
                                observation_order_column = ["model_id", "seq_id", "seq_vertex_id"],
                                state_model_key = ["model_id"],
                                state_key = ["state"],
                                state_prob_key = ["probability"],
                                trans_model_key = ["model_id"],
                                trans_from_key = ["from_state"],
                                trans_to_key = ["to_state"],
                                trans_prob_key = ["probability"],
                                emit_model_key = ["model_id"],
                                emit_state_key = ["state"],
                                emit_observed_key = ["observed"],
                                emit_prob_key = ["probability"],
                                model_key = "model_id",
                                sequence_key = "seq_id",
                                observed_key = "observed_id",
                                accumulate = ["seq_vertex_id"]
                                )
    # Print the results.
    print(HMMDecoder_out1)
 
    # Example 2 - This example uses the output of a HMM Supervised model with the input
    # to determine the loyalty levels of customers from the new sequence of purchases.
    load_example_data("hmmdecoder", "customer_loyalty_newseq")
    customer_loyalty = DataFrame.from_table("customer_loyalty")
 
    HMMSupervised_out = HMMSupervised(vertices = customer_loyalty,
                                      vertices_partition_column = ["user_id", "seq_id"],
                                      vertices_order_column = ["user_id", "seq_id", "purchase_date"],
                                      model_key = "user_id",
                                      sequence_key = "seq_id",
                                      observed_key = "observation",
                                      state_key = "loyalty_level"
                                      )
 
    customer_loyalty_newseq = DataFrame.from_table("customer_loyalty_newseq")
 
    HMMDecoder_out2 = HMMDecoder(init_state_prob = HMMSupervised_out.output_initialstate_table,
                                init_state_prob_partition_column = ["user_id"],
                                state_transition_prob = HMMSupervised_out.output_statetransition_table,
                                state_transition_prob_partition_column = ["user_id"],
                                emission_prob = HMMSupervised_out.output_emission_table,
                                emission_prob_partition_column = ["user_id"],
                                observation = customer_loyalty_newseq,
                                observation_partition_column = ["user_id"],
                                observation_order_column = ["user_id", "seq_id", "purchase_date"],
                                state_model_key = ["user_id"],
                                state_key = ["state"],
                                state_prob_key = ["probability"],
                                trans_model_key = ["user_id"],
                                trans_from_key = ["from_state"],
                                trans_to_key = ["to_state"],
                                trans_prob_key = ["probability"],
                                emit_model_key = ["user_id"],
                                emit_state_key = ["state"],
                                emit_observed_key = ["observed"],
                                emit_prob_key = ["probability"],
                                model_key = "user_id",
                                sequence_key = "seq_id",
                                observed_key = "observation",
                                accumulate = ["purchase_date"]
                                )
    # Print the results.
    print(HMMDecoder_out2)
 
    # Example 3 - Part of Speech Tagging example
    load_example_data("hmmdecoder", ["initial", "state_transition", "emission", "phrases"])
    initial = DataFrame.from_table("initial")
    state_transition = DataFrame.from_table("state_transition")
    emission = DataFrame.from_table("emission")
    phrases = DataFrame.from_table("phrases")
 
    HMMDecoder_out3 = HMMDecoder(init_state_prob = initial,
                                init_state_prob_partition_column = ["model"],
                                state_transition_prob = state_transition,
                                state_transition_prob_partition_column = ["model"],
                                emission_prob = emission,
                                emission_prob_partition_column = ["model"],
                                observation = phrases,
                                observation_partition_column = ["model"],
                                observation_order_column = ["model", "phrase_id"],
                                state_model_key = ["model"],
                                state_key = ["tag"],
                                state_prob_key = ["probability"],
                                trans_model_key = ["model"],
                                trans_from_key = ["from_tag"],
                                trans_to_key = ["to_tag"],
                                trans_prob_key = ["probability"],
                                emit_model_key = ["model"],
                                emit_state_key = ["tag"],
                                emit_observed_key = ["word"],
                                emit_prob_key = ["probability"],
                                model_key = "model",
                                sequence_key = "phrase_id",
                                observed_key = "word"
                                )
 
    # Print the results.
    print(HMMDecoder_out3)
 
    # Example 4 - This example uses HMMDecoder to find the propensity of customer churn,
    # given the actions or transactions of a bank customer.
    load_example_data("hmmdecoder", ["churn_initial", "churn_state_transition", "churn_emission", "churn_data"])
    churn_initial = DataFrame.from_table("churn_initial")
    churn_state_transition = DataFrame.from_table("churn_state_transition")
    churn_emission = DataFrame.from_table("churn_emission")
    churn_data = DataFrame.from_table("churn_data")
 
    HMMDecoder_out4 = HMMDecoder(init_state_prob = churn_initial,
                                init_state_prob_partition_column = ["model"],
                                state_transition_prob = churn_state_transition,
                                state_transition_prob_partition_column = ["model"],
                                emission_prob = churn_emission,
                                emission_prob_partition_column = ["model"],
                                observation = churn_data,
                                observation_partition_column = ["model"],
                                observation_order_column = ["model","id", "path_id"],
                                state_model_key = ["model"],
                                state_key = ["tag"],
                                state_prob_key = ["probability"],
                                trans_model_key = ["model"],
                                trans_from_key = ["from_tag"],
                                trans_to_key = ["to_tag"],
                                trans_prob_key = ["probability"],
                                emit_model_key = ["model"],
                                emit_state_key = ["state"],
                                emit_observed_key = ["observed"],
                                emit_prob_key = ["probability"],
                                model_key = "model",
                                sequence_key = "id",
                                observed_key = "action",
                                accumulate = ["path_id"]
                                )
 
    # Print the results.
    print(HMMDecoder_out4)
__repr__(self)
Returns the string representation for a HMMDecoder 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.