| |
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, incremental=True, show_rate_change=True, seq_prob_key=None, 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 HMMEvaluator function measures the probabilities of sequences,
with respect to each trained HMM.
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
incremental:
Optional Argument.
Specifies whether only new sequence probabilities are computed. If
"True", only new sequence probabilities are computed.
If "False", all probabilities are computed.
Note: If the seq_prob_key argument is not specified, the function cannot
determine whether the observed sequence is new; therefore, all model sequences
in the input tables are treated as new.
Default Value: True
Types: bool
show_rate_change:
Optional Argument.
Specifies the value to show the percentage change that corresponds to the
applied model with the difference from previous predicted probability.
Function shows the percentage change, when this is set to "True".
Default Value: True
Types: bool
seq_prob_key:
Optional Argument.
Specifies the column to calculate the change rate. The function uses the
previous value under this column.
Types: str
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 "observation" input teradataml DataFrame
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 HMMEvaluator.
Output teradataml DataFrames can be accessed using attribute
references, such as HMMEvaluatorObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException
EXAMPLES:
# Load example data.
load_example_data("hmmunsupervised", "loan_prediction")
load_example_data("hmmevaluator", ["Pi_loan", "A_loan", "B_loan", "test_loan_prediction"])
# Create teradataml DataFrame objects.
pi_loan = DataFrame.from_table("pi_loan")
A_loan = DataFrame.from_table("A_loan")
B_loan = DataFrame.from_table("B_loan")
test_loan_prediction = DataFrame.from_table("test_loan_prediction")
loan_prediction = DataFrame.from_table("loan_prediction")
# Example 1
# Train a HMM Unsupervised model on the loan prediction dataset
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,
init_methods = ["random"]
)
# Use the output of the trained model to make the evaluation for probabilities of sequences.
# Note: Similarly, output of a trained supervised HMM model can also be used to make evaluation.
HMMEvaluator_out1 = HMMEvaluator(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 = ["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"
)
# Print the results
print(HMMEvaluator_out1)
# Example 2 - Alternatively, load the trained model data from the database tables to make the evaluations
HMMEvaluator_out2 = HMMEvaluator(init_state_prob = pi_loan,
init_state_prob_partition_column = ["model_id"],
state_transition_prob = A_loan,
state_transition_prob_partition_column = ["model_id"],
emission_prob = B_loan,
emission_prob_partition_column = ["model_id"],
observation = test_loan_prediction,
observation_partition_column = ["model_id"],
observation_order_column = ["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"
)
# Print the results
print(HMMEvaluator_out2)
- __repr__(self)
- Returns the string representation for a HMMEvaluator class instance.
|